From 810becccaf2215b78a3ff43042fd08d5276a90ec Mon Sep 17 00:00:00 2001 From: OliE Date: Wed, 25 Apr 2018 16:45:10 +0200 Subject: [PATCH] replaced debug preference with a check box preference --- .../gui/preferences/AboutPreferences.java | 49 ++++++++++++------- .../src/main/res/xml/about_preferences.xml | 2 +- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/gui/preferences/AboutPreferences.java b/android_app/app/src/main/java/com/health/openscale/gui/preferences/AboutPreferences.java index d96efe5a..581743c8 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/preferences/AboutPreferences.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/preferences/AboutPreferences.java @@ -18,6 +18,7 @@ package com.health.openscale.gui.preferences; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.preference.CheckBoxPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.util.Log; @@ -43,6 +44,8 @@ public class AboutPreferences extends PreferenceFragment { private static final int DEBUG_LOG_REQUEST = 100; + private CheckBoxPreference debugLog; + class FileDebugTree extends Timber.DebugTree { PrintWriter writer; DateFormat format; @@ -99,32 +102,33 @@ public class AboutPreferences extends PreferenceFragment { findPreference(KEY_APP_VERSION).setSummary( String.format("v%s (%d)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)); - Preference debugLog = findPreference(KEY_DEBUG_LOG); + debugLog = (CheckBoxPreference)findPreference(KEY_DEBUG_LOG); debugLog.setSummary(getEnabledFileDebugTree() != null ? R.string.info_is_enable : R.string.info_is_not_enable); debugLog.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - FileDebugTree tree = getEnabledFileDebugTree(); - if (tree != null) { - Timber.d("Debug log disabled"); - tree.close(); - Timber.uproot(tree); - preference.setSummary(R.string.info_is_not_enable); - OpenScale.DEBUG_MODE = false; - return true; + if (debugLog.isChecked()) { + DateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm"); + String fileName = String.format("openScale_%s.txt", format.format(new Date())); + + Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_TITLE, fileName); + + startActivityForResult(intent, DEBUG_LOG_REQUEST); + } else { + FileDebugTree tree = getEnabledFileDebugTree(); + if (tree != null) { + Timber.d("Debug log disabled"); + tree.close(); + Timber.uproot(tree); + preference.setSummary(R.string.info_is_not_enable); + OpenScale.DEBUG_MODE = false; + } } - DateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm"); - String fileName = String.format("openScale_%s.txt", format.format(new Date())); - - Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_TITLE, fileName); - - startActivityForResult(intent, DEBUG_LOG_REQUEST); - return true; } }); @@ -151,6 +155,13 @@ public class AboutPreferences extends PreferenceFragment { if (requestCode == DEBUG_LOG_REQUEST && resultCode == RESULT_OK && data != null) { startLogTo(data.getData()); + + debugLog.setSummary(getEnabledFileDebugTree() != null + ? R.string.info_is_enable : R.string.info_is_not_enable); + + debugLog.setChecked(true); + } else { + debugLog.setChecked(false); } } } diff --git a/android_app/app/src/main/res/xml/about_preferences.xml b/android_app/app/src/main/res/xml/about_preferences.xml index fbfd33e6..508ea6d9 100644 --- a/android_app/app/src/main/res/xml/about_preferences.xml +++ b/android_app/app/src/main/res/xml/about_preferences.xml @@ -23,7 +23,7 @@ android:title="@string/label_license" android:summary="GPLv3"/> -