~anjan/lift

3c4b3369ca0e24e2fcb4360b23a31c1a88b86906 — Anjandev Momi 4 years ago 973a421
close file when done workout and fix onPause always
1 files changed, 18 insertions(+), 5 deletions(-)

M app/src/main/java/ca/momi/lift/Workout.java
M app/src/main/java/ca/momi/lift/Workout.java => app/src/main/java/ca/momi/lift/Workout.java +18 -5
@@ 50,6 50,11 @@ public class Workout extends AppCompatActivity {

    private boolean pausing = false;

    protected void onResume() {
        super.onResume();
        pausing = false;
    }

    protected void onPause() {
        super.onPause();
        pausing = true;


@@ 92,17 97,17 @@ public class Workout extends AppCompatActivity {
        }
    }

    public void checkStoragePermissionAndWrite(Activity thisActivity, String fileName, String text) {
    public boolean checkStoragePermissionAndWrite(Activity thisActivity, String fileName, String text) {

        String state = Environment.getExternalStorageState();

        if (!Environment.MEDIA_MOUNTED.equals(state)){
            Log.d(TAG, "Error: external storage is unavailable");
            return;
            return false;
        }
        if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
            Log.d(TAG, "Error: external storage is read only.");
            return;
            return false;
        }
        Log.d(TAG, "External storage is not read only or unavailable");



@@ 131,16 136,20 @@ public class Workout extends AppCompatActivity {

            try {
                ExternalStore.writeTextToExtStorage(fileName, text);
                return true;
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        } else {
            // Permission has already been granted

            try {
                ExternalStore.writeTextToExtStorage(fileName, text);
                return true;
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }



@@ 406,11 415,15 @@ public class Workout extends AppCompatActivity {
                    LastWorkout.onPausetxt;
        }


        checkStoragePermissionAndWrite((Activity) v.getContext(),  dateString, workoutSessionText);
        if (currentWorkTimer != null) {
            currentWorkTimer.timer.cancel();
        }

        if (checkStoragePermissionAndWrite((Activity) v.getContext(),  dateString, workoutSessionText)){
            finish();
        } else {
            Log.d(TAG, "writeData: failed. Try again");
        }
    }