1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-22 16:23:09 +02:00

replaced debug preference with a check box preference

This commit is contained in:
OliE
2018-04-25 16:45:10 +02:00
parent 8beeca596d
commit 810becccaf
2 changed files with 31 additions and 20 deletions

View File

@@ -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);
}
}
}

View File

@@ -23,7 +23,7 @@
android:title="@string/label_license"
android:summary="GPLv3"/>
<PreferenceCategory android:title="@string/label_development">
<Preference
<CheckBoxPreference
android:key="debug_log"
android:persistent="false"
android:title="@string/label_debug_log" />