Skip to content

Commit 77781c7

Browse files
committed
- Enhancement : Permissions have been made optional
- Enhancement : Cardio fragment removed (#55)
1 parent f183b21 commit 77781c7

File tree

10 files changed

+99
-60
lines changed

10 files changed

+99
-60
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ For Development [Android Studio](https://developer.android.com/studio/) with [gr
4444

4545
## Change Log
4646

47+
### 0.17.2 : April 5, 2019
48+
49+
- Enhancement : Permissions have been made optional
50+
- Enhancement : Cardio fragment removed
51+
4752
### 0.17.1 : March 27, 2019
4853

4954
- Bug : Fixed frozen edit in creation profil

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
package="com.easyfitness"
5-
android:versionCode="28"
6-
android:versionName="0.17">
5+
android:versionCode="30"
6+
android:versionName="0.17.2">
77

88
<uses-permission android:name="android.permission.VIBRATE" />
99
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

app/src/main/java/com/easyfitness/MainActivity.java

Lines changed: 77 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package com.easyfitness;
22

3+
import android.Manifest;
34
import android.app.AlertDialog;
45
import android.content.DialogInterface;
56
import android.content.Intent;
67
import android.content.SharedPreferences;
8+
import android.content.pm.PackageManager;
79
import android.content.res.Configuration;
810
import android.os.Bundle;
911
import android.os.Environment;
1012
import android.preference.PreferenceManager;
13+
import android.support.v4.app.ActivityCompat;
1114
import android.support.v4.app.Fragment;
1215
import android.support.v4.app.FragmentManager;
1316
import android.support.v4.app.FragmentTransaction;
17+
import android.support.v4.content.ContextCompat;
1418
import android.support.v4.widget.DrawerLayout;
1519
import android.support.v7.app.ActionBarDrawerToggle;
1620
import android.support.v7.app.AppCompatActivity;
@@ -210,7 +214,7 @@ public void onCreate(Bundle savedInstanceState) {
210214

211215
dataList.add(drawerTitleItem);
212216
dataList.add(new DrawerItem(this.getResources().getString(R.string.menu_Workout), R.drawable.ic_barbell, true));
213-
dataList.add(new DrawerItem(this.getResources().getString(R.string.CardioMenuLabel), R.drawable.ic_running, true));
217+
//dataList.add(new DrawerItem(this.getResources().getString(R.string.CardioMenuLabel), R.drawable.ic_running, true));
214218
dataList.add(new DrawerItem(this.getResources().getString(R.string.MachinesLabel), R.drawable.ic_machine, true));
215219
dataList.add(new DrawerItem(this.getResources().getString(R.string.weightMenuLabel), R.drawable.ic_scale, true));
216220
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) {
412416

413417
};
414418

419+
private final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1001;
420+
421+
private void exportDatabase() {
422+
// Here, thisActivity is the current activity
423+
if (ContextCompat.checkSelfPermission(this,
424+
Manifest.permission.WRITE_EXTERNAL_STORAGE)
425+
!= PackageManager.PERMISSION_GRANTED) {
426+
// No explanation needed; request the permission
427+
ActivityCompat.requestPermissions(this,
428+
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
429+
MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
430+
} else {
431+
// Afficher une boite de dialogue pour confirmer
432+
AlertDialog.Builder exportDbBuilder = new AlertDialog.Builder(this);
433+
434+
exportDbBuilder.setTitle(getActivity().getResources().getText(R.string.export_database));
435+
exportDbBuilder.setMessage(getActivity().getResources().getText(R.string.export_question) + " " + getCurrentProfil().getName() + "?");
436+
437+
// Si oui, supprimer la base de donnee et refaire un Start.
438+
exportDbBuilder.setPositiveButton(getActivity().getResources().getText(R.string.global_yes), new DialogInterface.OnClickListener() {
439+
public void onClick(DialogInterface dialog, int which) {
440+
CVSManager cvsMan = new CVSManager(getActivity().getBaseContext());
441+
if (cvsMan.exportDatabase(getCurrentProfil())) {
442+
KToast.successToast(getActivity(), getCurrentProfil().getName() + ": " + getActivity().getResources().getText(R.string.export_success), Gravity.BOTTOM, KToast.LENGTH_LONG);
443+
} else {
444+
KToast.errorToast(getActivity(), getCurrentProfil().getName() + ": " + getActivity().getResources().getText(R.string.export_failed), Gravity.BOTTOM, KToast.LENGTH_LONG);
445+
}
446+
447+
// Do nothing but close the dialog
448+
dialog.dismiss();
449+
}
450+
});
451+
452+
exportDbBuilder.setNegativeButton(getActivity().getResources().getText(R.string.global_no), new DialogInterface.OnClickListener() {
453+
454+
@Override
455+
public void onClick(DialogInterface dialog, int which) {
456+
// Do nothing
457+
dialog.dismiss();
458+
}
459+
});
460+
461+
AlertDialog exportDbDialog = exportDbBuilder.create();
462+
exportDbDialog.show();
463+
}
464+
}
415465

416466
@Override
417467
public boolean onOptionsItemSelected(MenuItem item) {
@@ -424,39 +474,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
424474
// Handle presses on the action bar items
425475
switch (item.getItemId()) {
426476
case R.id.export_database:
427-
// Afficher une boite de dialogue pour confirmer
428-
AlertDialog.Builder exportDbBuilder = new AlertDialog.Builder(this);
429-
430-
exportDbBuilder.setTitle(getActivity().getResources().getText(R.string.export_database));
431-
exportDbBuilder.setMessage(getActivity().getResources().getText(R.string.export_question) + " " + getCurrentProfil().getName() + "?");
432-
433-
// Si oui, supprimer la base de donnee et refaire un Start.
434-
exportDbBuilder.setPositiveButton(getActivity().getResources().getText(R.string.global_yes), new DialogInterface.OnClickListener() {
435-
public void onClick(DialogInterface dialog, int which) {
436-
CVSManager cvsMan = new CVSManager(getActivity().getBaseContext());
437-
if (cvsMan.exportDatabase(getCurrentProfil())) {
438-
KToast.successToast(getActivity(), getCurrentProfil().getName() + ": " + getActivity().getResources().getText(R.string.export_success), Gravity.BOTTOM, KToast.LENGTH_LONG);
439-
} else {
440-
KToast.errorToast(getActivity(), getCurrentProfil().getName() + ": " + getActivity().getResources().getText(R.string.export_failed), Gravity.BOTTOM, KToast.LENGTH_LONG);
441-
}
442-
443-
// Do nothing but close the dialog
444-
dialog.dismiss();
445-
}
446-
});
447-
448-
exportDbBuilder.setNegativeButton(getActivity().getResources().getText(R.string.global_no), new DialogInterface.OnClickListener() {
449-
450-
@Override
451-
public void onClick(DialogInterface dialog, int which) {
452-
// Do nothing
453-
dialog.dismiss();
454-
}
455-
});
456-
457-
AlertDialog exportDbDialog = exportDbBuilder.create();
458-
exportDbDialog.show();
459-
477+
exportDatabase();
460478
return true;
461479
case R.id.import_database:
462480
// Create DirectoryChooserDialog and register a callback
@@ -536,6 +554,27 @@ public void onClick(DialogInterface dialog, int which) {
536554
}
537555
}
538556

557+
@Override
558+
public void onRequestPermissionsResult(int requestCode,
559+
String[] permissions, int[] grantResults) {
560+
switch (requestCode) {
561+
case MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: {
562+
// If request is cancelled, the result arrays are empty.
563+
if (grantResults.length > 0
564+
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
565+
KToast.infoToast(this, getString(R.string.access_granted), Gravity.BOTTOM, KToast.LENGTH_SHORT);
566+
exportDatabase();
567+
} else {
568+
KToast.infoToast(this, getString(R.string.another_time_maybe), Gravity.BOTTOM, KToast.LENGTH_SHORT);
569+
570+
}
571+
572+
573+
}
574+
}
575+
}
576+
577+
539578
public boolean CreateNewProfil() {
540579
AlertDialog.Builder newProfilBuilder = new AlertDialog.Builder(this);
541580

@@ -885,26 +924,22 @@ public void onItemClick(AdapterView parent, View view, int position, long id) {
885924
setTitle(getResources().getText(R.string.menu_Workout));
886925
break;
887926
case 2:
888-
showFragment(CARDIO);
889-
setTitle(getResources().getText(R.string.CardioLabel));
890-
break;
891-
case 3:
892927
showFragment(MACHINES);
893928
setTitle(getResources().getText(R.string.MachinesLabel));
894929
break;
895-
case 4:
930+
case 3:
896931
showFragment(WEIGHT);
897932
setTitle(getResources().getText(R.string.weightMenuLabel));
898933
break;
899-
case 5:
934+
case 4:
900935
showFragment(BODYTRACKING);
901936
setTitle(getResources().getText(R.string.bodytracking));
902937
break;
903-
case 6:
938+
case 5:
904939
showFragment(SETTINGS);
905940
setTitle(getResources().getText(R.string.SettingLabel));
906941
break;
907-
case 7:
942+
case 6:
908943
showFragment(ABOUT);
909944
setTitle(getResources().getText(R.string.AboutLabel));
910945
break;

app/src/main/java/com/easyfitness/intro/MainIntroActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected void onCreate(Bundle savedInstanceState) {
8484
.scrollable(scrollable)
8585
.build());
8686

87-
final Slide permissionsSlide;
87+
/*final Slide permissionsSlide;
8888
if (permissions) {
8989
permissionsSlide = new SimpleSlide.Builder()
9090
.title(R.string.introSlide3Title)
@@ -99,7 +99,7 @@ protected void onCreate(Bundle savedInstanceState) {
9999
addSlide(permissionsSlide);
100100
} else {
101101
permissionsSlide = null;
102-
}
102+
}*/
103103

104104
// Initialisation des objets DB
105105
DAOProfil mDbProfils = new DAOProfil(this.getApplicationContext());

app/src/main/java/com/easyfitness/intro/NewProfileFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void onFocusChange(View v, boolean hasFocus) {
124124
public void onNavigationBlocked(int position, int direction) {
125125
//Slide slide = getIntroActivity().getSlide(position);
126126

127-
if (position == 5) {
127+
if (position == 4) {
128128
mBtCreate.callOnClick();
129129
}
130130
}

app/src/main/java/com/easyfitness/utils/ImageUtil.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -333,19 +333,9 @@ private File createImageFile(Fragment pF) throws IOException {
333333
private void requestPermissionForWriting(Fragment pF) {
334334
// Here, thisActivity is the current activity
335335
if (ContextCompat.checkSelfPermission(pF.getActivity(),
336-
Manifest.permission.READ_CONTACTS)
336+
Manifest.permission.WRITE_EXTERNAL_STORAGE)
337337
!= PackageManager.PERMISSION_GRANTED) {
338338

339-
// Should we show an explanation?
340-
if (ActivityCompat.shouldShowRequestPermissionRationale(pF.getActivity(),
341-
Manifest.permission.READ_CONTACTS)) {
342-
343-
// Show an explanation to the user *asynchronously* -- don't block
344-
// this thread waiting for the user's response! After the user
345-
// sees the explanation, try again to request the permission.
346-
347-
} else {
348-
349339
// No explanation needed, we can request the permission.
350340

351341
ActivityCompat.requestPermissions(pF.getActivity(),
@@ -355,7 +345,7 @@ private void requestPermissionForWriting(Fragment pF) {
355345
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
356346
// app-defined int constant. The callback method gets the
357347
// result of the request.
358-
}
348+
359349
}
360350
}
361351

app/src/main/res/values-de/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,5 +288,7 @@
288288
<string name="BMI_dialog_title">Body-Mass-Index (BMI)</string>
289289
<string name="BMI_formula">BMI = Gewicht(kg) / Größe(m)*Größe(m)</string>
290290
<string name="RFM_dialog_title">Relativer Fettmassenindex (RFM)</string>
291+
<string name="access_granted">Zugriff gewährt</string>
292+
<string name="another_time_maybe">Später vielleicht :)</string>
291293
</resources>
292294

app/src/main/res/values-fr/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,6 @@
278278
<string name="RFM_dialog_title">Indice de Masse Graisseuse Relatif (MGR)</string>
279279
<string name="RFM_female_formula">Femmes: RFM = 76 – (20 x (hauteur/circonférence de la taille))</string>
280280
<string name="RFM_male_formula">Hommes: RFM = 64 – (20 x (hauteur/circonférence de la taille))</string>
281+
<string name="access_granted">Accès autorisé</string>
282+
<string name="another_time_maybe">Une autre fois peut-être :)</string>
281283
</resources>

app/src/main/res/values/about.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
3-
<string name="app_version" translatable="false">0.17.1</string>
3+
<string name="app_version" translatable="false">0.17.2</string>
44
<string name="database_version_label" translatable="false">Database version: </string>
55
<string name="author_label" translatable="false">Author: </string>
66
<string name="author" translatable="false">Charles Combes</string>
@@ -10,6 +10,9 @@
1010
<string name="email_url" translatable="false">fastnfitnessapp@gmail.com</string>
1111
<string name="revision_history_label" translatable="false">Revision History: </string>
1212
<string name="revision_history" translatable="false">\n
13+
v0.17.2: 05/04/2019\n
14+
\t - Enhancement : Permissions have been made optional\n
15+
\t - Enhancement : Cardio fragment removed\n
1316
v0.17.1: 27/03/2019\n
1417
\t - Bug : Fixed intro profil creation\n
1518
v0.17: 18/03/2019\n

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
<string name="RFM_dialog_title">Relative Fat Mass Index (RFM)</string>
293293
<string name="RFM_female_formula">Women: RFM = 76 – (20 x (size/waist circumference))</string>
294294
<string name="RFM_male_formula">Men: RFM = 64 – (20 x (size/waist circumference))</string>
295+
<string name="access_granted">Access granted</string>
296+
<string name="another_time_maybe">Another time maybe :)</string>
295297

296298
</resources>
297299

0 commit comments

Comments
 (0)