mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-22 08:13:43 +02:00
replaced debug preference with a check box preference
This commit is contained in:
@@ -18,6 +18,7 @@ package com.health.openscale.gui.preferences;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -43,6 +44,8 @@ public class AboutPreferences extends PreferenceFragment {
|
|||||||
|
|
||||||
private static final int DEBUG_LOG_REQUEST = 100;
|
private static final int DEBUG_LOG_REQUEST = 100;
|
||||||
|
|
||||||
|
private CheckBoxPreference debugLog;
|
||||||
|
|
||||||
class FileDebugTree extends Timber.DebugTree {
|
class FileDebugTree extends Timber.DebugTree {
|
||||||
PrintWriter writer;
|
PrintWriter writer;
|
||||||
DateFormat format;
|
DateFormat format;
|
||||||
@@ -99,32 +102,33 @@ public class AboutPreferences extends PreferenceFragment {
|
|||||||
findPreference(KEY_APP_VERSION).setSummary(
|
findPreference(KEY_APP_VERSION).setSummary(
|
||||||
String.format("v%s (%d)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE));
|
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
|
debugLog.setSummary(getEnabledFileDebugTree() != null
|
||||||
? R.string.info_is_enable : R.string.info_is_not_enable);
|
? R.string.info_is_enable : R.string.info_is_not_enable);
|
||||||
debugLog.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
debugLog.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
FileDebugTree tree = getEnabledFileDebugTree();
|
if (debugLog.isChecked()) {
|
||||||
if (tree != null) {
|
DateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
||||||
Timber.d("Debug log disabled");
|
String fileName = String.format("openScale_%s.txt", format.format(new Date()));
|
||||||
tree.close();
|
|
||||||
Timber.uproot(tree);
|
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
||||||
preference.setSummary(R.string.info_is_not_enable);
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
OpenScale.DEBUG_MODE = false;
|
intent.setType("text/plain");
|
||||||
return true;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -151,6 +155,13 @@ public class AboutPreferences extends PreferenceFragment {
|
|||||||
|
|
||||||
if (requestCode == DEBUG_LOG_REQUEST && resultCode == RESULT_OK && data != null) {
|
if (requestCode == DEBUG_LOG_REQUEST && resultCode == RESULT_OK && data != null) {
|
||||||
startLogTo(data.getData());
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
android:title="@string/label_license"
|
android:title="@string/label_license"
|
||||||
android:summary="GPLv3"/>
|
android:summary="GPLv3"/>
|
||||||
<PreferenceCategory android:title="@string/label_development">
|
<PreferenceCategory android:title="@string/label_development">
|
||||||
<Preference
|
<CheckBoxPreference
|
||||||
android:key="debug_log"
|
android:key="debug_log"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/label_debug_log" />
|
android:title="@string/label_debug_log" />
|
||||||
|
Reference in New Issue
Block a user