From 77781c7c113b76851459439eda3f7cca82f77d26 Mon Sep 17 00:00:00 2001 From: brodeurlv Date: Fri, 5 Apr 2019 22:35:06 +0200 Subject: [PATCH] - Enhancement : Permissions have been made optional - Enhancement : Cardio fragment removed (#55) --- README.md | 5 + app/src/main/AndroidManifest.xml | 4 +- .../java/com/easyfitness/MainActivity.java | 119 +++++++++++------- .../easyfitness/intro/MainIntroActivity.java | 4 +- .../easyfitness/intro/NewProfileFragment.java | 2 +- .../java/com/easyfitness/utils/ImageUtil.java | 14 +-- app/src/main/res/values-de/strings.xml | 2 + app/src/main/res/values-fr/strings.xml | 2 + app/src/main/res/values/about.xml | 5 +- app/src/main/res/values/strings.xml | 2 + 10 files changed, 99 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 016d7e81..ee0bc932 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,11 @@ For Development [Android Studio](https://developer.android.com/studio/) with [gr ## Change Log +### 0.17.2 : April 5, 2019 + +- Enhancement : Permissions have been made optional +- Enhancement : Cardio fragment removed + ### 0.17.1 : March 27, 2019 - Bug : Fixed frozen edit in creation profil diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0ddbf5ae..28419abb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@ + android:versionCode="30" + android:versionName="0.17.2"> diff --git a/app/src/main/java/com/easyfitness/MainActivity.java b/app/src/main/java/com/easyfitness/MainActivity.java index 4dc33678..94ec5fe7 100644 --- a/app/src/main/java/com/easyfitness/MainActivity.java +++ b/app/src/main/java/com/easyfitness/MainActivity.java @@ -1,16 +1,20 @@ package com.easyfitness; +import android.Manifest; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.content.res.Configuration; import android.os.Bundle; import android.os.Environment; import android.preference.PreferenceManager; +import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; +import android.support.v4.content.ContextCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; @@ -210,7 +214,7 @@ public void onCreate(Bundle savedInstanceState) { dataList.add(drawerTitleItem); dataList.add(new DrawerItem(this.getResources().getString(R.string.menu_Workout), R.drawable.ic_barbell, true)); - dataList.add(new DrawerItem(this.getResources().getString(R.string.CardioMenuLabel), R.drawable.ic_running, true)); + //dataList.add(new DrawerItem(this.getResources().getString(R.string.CardioMenuLabel), R.drawable.ic_running, true)); dataList.add(new DrawerItem(this.getResources().getString(R.string.MachinesLabel), R.drawable.ic_machine, true)); dataList.add(new DrawerItem(this.getResources().getString(R.string.weightMenuLabel), R.drawable.ic_scale, true)); dataList.add(new DrawerItem(this.getResources().getString(R.string.bodytracking), R.drawable.ic_measuring_tape, true)); @@ -412,6 +416,52 @@ public void onClick(DialogInterface dialog, int which) { }; + private final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1001; + + private void exportDatabase() { + // Here, thisActivity is the current activity + if (ContextCompat.checkSelfPermission(this, + Manifest.permission.WRITE_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED) { + // No explanation needed; request the permission + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, + MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); + } else { + // Afficher une boite de dialogue pour confirmer + AlertDialog.Builder exportDbBuilder = new AlertDialog.Builder(this); + + exportDbBuilder.setTitle(getActivity().getResources().getText(R.string.export_database)); + exportDbBuilder.setMessage(getActivity().getResources().getText(R.string.export_question) + " " + getCurrentProfil().getName() + "?"); + + // Si oui, supprimer la base de donnee et refaire un Start. + exportDbBuilder.setPositiveButton(getActivity().getResources().getText(R.string.global_yes), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + CVSManager cvsMan = new CVSManager(getActivity().getBaseContext()); + if (cvsMan.exportDatabase(getCurrentProfil())) { + KToast.successToast(getActivity(), getCurrentProfil().getName() + ": " + getActivity().getResources().getText(R.string.export_success), Gravity.BOTTOM, KToast.LENGTH_LONG); + } else { + KToast.errorToast(getActivity(), getCurrentProfil().getName() + ": " + getActivity().getResources().getText(R.string.export_failed), Gravity.BOTTOM, KToast.LENGTH_LONG); + } + + // Do nothing but close the dialog + dialog.dismiss(); + } + }); + + exportDbBuilder.setNegativeButton(getActivity().getResources().getText(R.string.global_no), new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + // Do nothing + dialog.dismiss(); + } + }); + + AlertDialog exportDbDialog = exportDbBuilder.create(); + exportDbDialog.show(); + } + } @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -424,39 +474,7 @@ public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.export_database: - // Afficher une boite de dialogue pour confirmer - AlertDialog.Builder exportDbBuilder = new AlertDialog.Builder(this); - - exportDbBuilder.setTitle(getActivity().getResources().getText(R.string.export_database)); - exportDbBuilder.setMessage(getActivity().getResources().getText(R.string.export_question) + " " + getCurrentProfil().getName() + "?"); - - // Si oui, supprimer la base de donnee et refaire un Start. - exportDbBuilder.setPositiveButton(getActivity().getResources().getText(R.string.global_yes), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - CVSManager cvsMan = new CVSManager(getActivity().getBaseContext()); - if (cvsMan.exportDatabase(getCurrentProfil())) { - KToast.successToast(getActivity(), getCurrentProfil().getName() + ": " + getActivity().getResources().getText(R.string.export_success), Gravity.BOTTOM, KToast.LENGTH_LONG); - } else { - KToast.errorToast(getActivity(), getCurrentProfil().getName() + ": " + getActivity().getResources().getText(R.string.export_failed), Gravity.BOTTOM, KToast.LENGTH_LONG); - } - - // Do nothing but close the dialog - dialog.dismiss(); - } - }); - - exportDbBuilder.setNegativeButton(getActivity().getResources().getText(R.string.global_no), new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - // Do nothing - dialog.dismiss(); - } - }); - - AlertDialog exportDbDialog = exportDbBuilder.create(); - exportDbDialog.show(); - + exportDatabase(); return true; case R.id.import_database: // Create DirectoryChooserDialog and register a callback @@ -536,6 +554,27 @@ public void onClick(DialogInterface dialog, int which) { } } + @Override + public void onRequestPermissionsResult(int requestCode, + String[] permissions, int[] grantResults) { + switch (requestCode) { + case MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: { + // If request is cancelled, the result arrays are empty. + if (grantResults.length > 0 + && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + KToast.infoToast(this, getString(R.string.access_granted), Gravity.BOTTOM, KToast.LENGTH_SHORT); + exportDatabase(); + } else { + KToast.infoToast(this, getString(R.string.another_time_maybe), Gravity.BOTTOM, KToast.LENGTH_SHORT); + + } + + + } + } + } + + public boolean CreateNewProfil() { AlertDialog.Builder newProfilBuilder = new AlertDialog.Builder(this); @@ -885,26 +924,22 @@ public void onItemClick(AdapterView parent, View view, int position, long id) { setTitle(getResources().getText(R.string.menu_Workout)); break; case 2: - showFragment(CARDIO); - setTitle(getResources().getText(R.string.CardioLabel)); - break; - case 3: showFragment(MACHINES); setTitle(getResources().getText(R.string.MachinesLabel)); break; - case 4: + case 3: showFragment(WEIGHT); setTitle(getResources().getText(R.string.weightMenuLabel)); break; - case 5: + case 4: showFragment(BODYTRACKING); setTitle(getResources().getText(R.string.bodytracking)); break; - case 6: + case 5: showFragment(SETTINGS); setTitle(getResources().getText(R.string.SettingLabel)); break; - case 7: + case 6: showFragment(ABOUT); setTitle(getResources().getText(R.string.AboutLabel)); break; diff --git a/app/src/main/java/com/easyfitness/intro/MainIntroActivity.java b/app/src/main/java/com/easyfitness/intro/MainIntroActivity.java index 17f4f760..0d8a6a43 100644 --- a/app/src/main/java/com/easyfitness/intro/MainIntroActivity.java +++ b/app/src/main/java/com/easyfitness/intro/MainIntroActivity.java @@ -84,7 +84,7 @@ protected void onCreate(Bundle savedInstanceState) { .scrollable(scrollable) .build()); - final Slide permissionsSlide; + /*final Slide permissionsSlide; if (permissions) { permissionsSlide = new SimpleSlide.Builder() .title(R.string.introSlide3Title) @@ -99,7 +99,7 @@ protected void onCreate(Bundle savedInstanceState) { addSlide(permissionsSlide); } else { permissionsSlide = null; - } + }*/ // Initialisation des objets DB DAOProfil mDbProfils = new DAOProfil(this.getApplicationContext()); diff --git a/app/src/main/java/com/easyfitness/intro/NewProfileFragment.java b/app/src/main/java/com/easyfitness/intro/NewProfileFragment.java index 0edbe1c1..8d86be5b 100644 --- a/app/src/main/java/com/easyfitness/intro/NewProfileFragment.java +++ b/app/src/main/java/com/easyfitness/intro/NewProfileFragment.java @@ -124,7 +124,7 @@ public void onFocusChange(View v, boolean hasFocus) { public void onNavigationBlocked(int position, int direction) { //Slide slide = getIntroActivity().getSlide(position); - if (position == 5) { + if (position == 4) { mBtCreate.callOnClick(); } } diff --git a/app/src/main/java/com/easyfitness/utils/ImageUtil.java b/app/src/main/java/com/easyfitness/utils/ImageUtil.java index 654b3b68..b9d46f71 100644 --- a/app/src/main/java/com/easyfitness/utils/ImageUtil.java +++ b/app/src/main/java/com/easyfitness/utils/ImageUtil.java @@ -333,19 +333,9 @@ private File createImageFile(Fragment pF) throws IOException { private void requestPermissionForWriting(Fragment pF) { // Here, thisActivity is the current activity if (ContextCompat.checkSelfPermission(pF.getActivity(), - Manifest.permission.READ_CONTACTS) + Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - // Should we show an explanation? - if (ActivityCompat.shouldShowRequestPermissionRationale(pF.getActivity(), - Manifest.permission.READ_CONTACTS)) { - - // Show an explanation to the user *asynchronously* -- don't block - // this thread waiting for the user's response! After the user - // sees the explanation, try again to request the permission. - - } else { - // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(pF.getActivity(), @@ -355,7 +345,7 @@ private void requestPermissionForWriting(Fragment pF) { // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. - } + } } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 04cfd177..945be907 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -288,5 +288,7 @@ Body-Mass-Index (BMI) BMI = Gewicht(kg) / Größe(m)*Größe(m) Relativer Fettmassenindex (RFM) + Zugriff gewährt + Später vielleicht :) diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 287762e8..7652f197 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -278,4 +278,6 @@ Indice de Masse Graisseuse Relatif (MGR) Femmes: RFM = 76 – (20 x (hauteur/circonférence de la taille)) Hommes: RFM = 64 – (20 x (hauteur/circonférence de la taille)) + Accès autorisé + Une autre fois peut-être :) diff --git a/app/src/main/res/values/about.xml b/app/src/main/res/values/about.xml index 08b47da2..3f1446bd 100644 --- a/app/src/main/res/values/about.xml +++ b/app/src/main/res/values/about.xml @@ -1,6 +1,6 @@ - 0.17.1 + 0.17.2 Database version: Author: Charles Combes @@ -10,6 +10,9 @@ fastnfitnessapp@gmail.com Revision History: \n + v0.17.2: 05/04/2019\n + \t - Enhancement : Permissions have been made optional\n + \t - Enhancement : Cardio fragment removed\n v0.17.1: 27/03/2019\n \t - Bug : Fixed intro profil creation\n v0.17: 18/03/2019\n diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0fca9c39..bdc9fcfe 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -292,6 +292,8 @@ Relative Fat Mass Index (RFM) Women: RFM = 76 – (20 x (size/waist circumference)) Men: RFM = 64 – (20 x (size/waist circumference)) + Access granted + Another time maybe :)