Added menu item to disable main log

pull/197/head
M66B 4 years ago
parent 6e3708d8ce
commit ccb026b7b2

@ -20,8 +20,10 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import androidx.room.Entity;
import androidx.room.Index;
import androidx.room.PrimaryKey;
@ -61,6 +63,11 @@ public class EntityLog {
static void log(final Context context, String data) {
Log.i(data);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean main_log = prefs.getBoolean("main_log", true);
if (!main_log)
return;
final EntityLog entry = new EntityLog();
entry.time = new Date().getTime();
entry.data = data;

@ -19,7 +19,9 @@ package eu.faircode.email;
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -106,6 +108,10 @@ public class FragmentLogs extends FragmentBase {
@Override
public void onPrepareOptionsMenu(Menu menu) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean main_log = prefs.getBoolean("main_log", true);
menu.findItem(R.id.menu_enabled).setChecked(main_log);
menu.findItem(R.id.menu_auto_scroll).setChecked(autoScroll);
super.onPrepareOptionsMenu(menu);
}
@ -113,9 +119,15 @@ public class FragmentLogs extends FragmentBase {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId == R.id.menu_auto_scroll) {
autoScroll = !item.isChecked();
item.setChecked(autoScroll);
if (itemId == R.id.menu_enabled) {
boolean enabled = !item.isChecked();
onMenuEnable(enabled);
item.setChecked(enabled);
return true;
} else if (itemId == R.id.menu_auto_scroll) {
boolean enabled = !item.isChecked();
onMenuAutoScoll(enabled);
item.setChecked(enabled);
return true;
} else if (itemId == R.id.menu_clear) {
onMenuClear();
@ -124,6 +136,15 @@ public class FragmentLogs extends FragmentBase {
return super.onOptionsItemSelected(item);
}
private void onMenuEnable(boolean enabled) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("main_log", enabled).apply();
}
private void onMenuAutoScoll(boolean enabled) {
autoScroll = enabled;
}
private void onMenuClear() {
EntityLog.clear(getContext());
}

@ -1,9 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_enabled"
android:checkable="true"
android:checked="true"
android:title="@string/title_enabled"
app:showAsAction="never" />
<item
android:id="@+id/menu_auto_scroll"
android:checkable="true"
android:checked="true"
android:title="@string/title_auto_scroll"
app:showAsAction="never" />
<item

Loading…
Cancel
Save