Skip to content

Commit

Permalink
- Enhancement : Permissions have been made optional
Browse files Browse the repository at this point in the history
- Enhancement : Cardio fragment removed (#55)
  • Loading branch information
brodeurlv committed Apr 5, 2019
1 parent f183b21 commit 77781c7
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 60 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.easyfitness"
android:versionCode="28"
android:versionName="0.17">
android:versionCode="30"
android:versionName="0.17.2">

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Expand Down
119 changes: 77 additions & 42 deletions app/src/main/java/com/easyfitness/MainActivity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -99,7 +99,7 @@ protected void onCreate(Bundle savedInstanceState) {
addSlide(permissionsSlide);
} else {
permissionsSlide = null;
}
}*/

// Initialisation des objets DB
DAOProfil mDbProfils = new DAOProfil(this.getApplicationContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
14 changes: 2 additions & 12 deletions app/src/main/java/com/easyfitness/utils/ImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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.
}

}
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,7 @@
<string name="BMI_dialog_title">Body-Mass-Index (BMI)</string>
<string name="BMI_formula">BMI = Gewicht(kg) / Größe(m)*Größe(m)</string>
<string name="RFM_dialog_title">Relativer Fettmassenindex (RFM)</string>
<string name="access_granted">Zugriff gewährt</string>
<string name="another_time_maybe">Später vielleicht :)</string>
</resources>

2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,6 @@
<string name="RFM_dialog_title">Indice de Masse Graisseuse Relatif (MGR)</string>
<string name="RFM_female_formula">Femmes: RFM = 76 – (20 x (hauteur/circonférence de la taille))</string>
<string name="RFM_male_formula">Hommes: RFM = 64 – (20 x (hauteur/circonférence de la taille))</string>
<string name="access_granted">Accès autorisé</string>
<string name="another_time_maybe">Une autre fois peut-être :)</string>
</resources>
5 changes: 4 additions & 1 deletion app/src/main/res/values/about.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
<string name="app_version" translatable="false">0.17.1</string>
<string name="app_version" translatable="false">0.17.2</string>
<string name="database_version_label" translatable="false">Database version: </string>
<string name="author_label" translatable="false">Author: </string>
<string name="author" translatable="false">Charles Combes</string>
Expand All @@ -10,6 +10,9 @@
<string name="email_url" translatable="false">[email protected]</string>
<string name="revision_history_label" translatable="false">Revision History: </string>
<string name="revision_history" translatable="false">\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
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@
<string name="RFM_dialog_title">Relative Fat Mass Index (RFM)</string>
<string name="RFM_female_formula">Women: RFM = 76 – (20 x (size/waist circumference))</string>
<string name="RFM_male_formula">Men: RFM = 64 – (20 x (size/waist circumference))</string>
<string name="access_granted">Access granted</string>
<string name="another_time_maybe">Another time maybe :)</string>

</resources>

0 comments on commit 77781c7

Please sign in to comment.