diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java index b781923501..123916cbeb 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java @@ -30,6 +30,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.CompoundButton; +import android.widget.NumberPicker; import android.widget.Spinner; import android.widget.Toast; @@ -40,6 +41,7 @@ import androidx.lifecycle.Lifecycle; import androidx.preference.PreferenceManager; public class FragmentOptionsBehavior extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { + private SwitchCompat swDoubleBack; private SwitchCompat swPull; private SwitchCompat swAutoScroll; private SwitchCompat swDoubleTap; @@ -55,11 +57,13 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe private SwitchCompat swAutoUnflag; private SwitchCompat swAutoMove; private SwitchCompat swDiscardDelete; + private NumberPicker npDefaultSnooze; private final static String[] RESET_OPTIONS = new String[]{ - "pull", "autoscroll", "doubletap", "swipenav", "reversed", + "double_back", "pull", "autoscroll", "doubletap", "swipenav", "reversed", "autoexpand", "expand_all", "expand_one", "collapse_multiple", - "autoclose", "onclose", "autoread", "autounflag", "automove", "discard_delete" + "autoclose", "onclose", "autoread", "autounflag", "automove", "discard_delete", + "default_snooze" }; @Override @@ -72,6 +76,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe // Get controls + swDoubleBack = view.findViewById(R.id.swDoubleBack); swPull = view.findViewById(R.id.swPull); swAutoScroll = view.findViewById(R.id.swAutoScroll); swDoubleTap = view.findViewById(R.id.swDoubleTap); @@ -87,6 +92,10 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe swAutoUnflag = view.findViewById(R.id.swAutoUnflag); swAutoMove = view.findViewById(R.id.swAutoMove); swDiscardDelete = view.findViewById(R.id.swDiscardDelete); + npDefaultSnooze = view.findViewById(R.id.npDefaultSnooze); + + npDefaultSnooze.setMinValue(1); + npDefaultSnooze.setMaxValue(999); setOptions(); @@ -94,6 +103,13 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + swDoubleBack.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("double_back", checked).apply(); + } + }); + swPull.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -213,6 +229,13 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe } }); + npDefaultSnooze.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { + @Override + public void onValueChange(NumberPicker picker, int oldVal, int newVal) { + prefs.edit().putInt("default_snooze", newVal).apply(); + } + }); + PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); return view; @@ -259,6 +282,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe private void setOptions() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + swDoubleBack.setChecked(prefs.getBoolean("double_back", true)); swPull.setChecked(prefs.getBoolean("pull", true)); swAutoScroll.setChecked(prefs.getBoolean("autoscroll", true)); swDoubleTap.setChecked(prefs.getBoolean("doubletap", false)); @@ -288,5 +312,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe swAutoUnflag.setChecked(prefs.getBoolean("autounflag", false)); swAutoMove.setChecked(!prefs.getBoolean("automove", false)); swDiscardDelete.setChecked(prefs.getBoolean("discard_delete", false)); + + npDefaultSnooze.setValue(prefs.getInt("default_snooze", 1)); } } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index c26d6ea6af..d9ba6eed60 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -31,11 +31,8 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; import android.widget.Button; import android.widget.CompoundButton; -import android.widget.NumberPicker; -import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; @@ -47,9 +44,6 @@ import androidx.lifecycle.Lifecycle; import androidx.preference.PreferenceManager; public class FragmentOptionsMisc extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { - private SwitchCompat swDoubleBack; - private NumberPicker npDefaultSnooze; - private Spinner spBiometricsTimeout; private SwitchCompat swEnglish; private SwitchCompat swWatchdog; private SwitchCompat swUpdates; @@ -69,7 +63,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private Group grpDebug; private final static String[] RESET_OPTIONS = new String[]{ - "double_back", "default_snooze", "biometrics_timeout", "english", "watchdog", "updates", "experiments", "crash_reports", "debug" + "english", "watchdog", "updates", "experiments", "crash_reports", "debug" }; private final static String[] RESET_QUESTIONS = new String[]{ @@ -88,9 +82,6 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc // Get controls - swDoubleBack = view.findViewById(R.id.swDoubleBack); - npDefaultSnooze = view.findViewById(R.id.npDefaultSnooze); - spBiometricsTimeout = view.findViewById(R.id.spBiometricsTimeout); swEnglish = view.findViewById(R.id.swEnglish); swWatchdog = view.findViewById(R.id.swWatchdog); swUpdates = view.findViewById(R.id.swUpdates); @@ -109,42 +100,12 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc grpDebug = view.findViewById(R.id.grpDebug); - npDefaultSnooze.setMinValue(1); - npDefaultSnooze.setMaxValue(999); - setOptions(); // Wire controls final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - swDoubleBack.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("double_back", checked).apply(); - } - }); - - npDefaultSnooze.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { - @Override - public void onValueChange(NumberPicker picker, int oldVal, int newVal) { - prefs.edit().putInt("default_snooze", newVal).apply(); - } - }); - - spBiometricsTimeout.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView adapterView, View view, int position, long id) { - int[] values = getResources().getIntArray(R.array.biometricsTimeoutValues); - prefs.edit().putInt("biometrics_timeout", values[position]).apply(); - } - - @Override - public void onNothingSelected(AdapterView parent) { - prefs.edit().remove("biometrics_timeout").apply(); - } - }); - swEnglish.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -316,17 +277,6 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private void setOptions() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - swDoubleBack.setChecked(prefs.getBoolean("double_back", true)); - npDefaultSnooze.setValue(prefs.getInt("default_snooze", 1)); - - int biometrics_timeout = prefs.getInt("biometrics_timeout", 2); - int[] biometricTimeoutValues = getResources().getIntArray(R.array.biometricsTimeoutValues); - for (int pos = 0; pos < biometricTimeoutValues.length; pos++) - if (biometricTimeoutValues[pos] == biometrics_timeout) { - spBiometricsTimeout.setSelection(pos); - break; - } - swEnglish.setChecked(prefs.getBoolean("english", false)); swWatchdog.setChecked(prefs.getBoolean("watchdog", true)); swUpdates.setChecked(prefs.getBoolean("updates", true)); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java index d845a90991..fbc194336c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java @@ -27,7 +27,9 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.CompoundButton; +import android.widget.Spinner; import android.widget.Toast; import androidx.annotation.NonNull; @@ -40,9 +42,10 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer private SwitchCompat swDisableTracking; private SwitchCompat swDisplayHidden; private SwitchCompat swNoHistory; + private Spinner spBiometricsTimeout; private final static String[] RESET_OPTIONS = new String[]{ - "disable_tracking", "display_hidden", "no_history" + "disable_tracking", "display_hidden", "no_history", "biometrics_timeout" }; @Override @@ -58,6 +61,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer swDisableTracking = view.findViewById(R.id.swDisableTracking); swDisplayHidden = view.findViewById(R.id.swDisplayHidden); swNoHistory = view.findViewById(R.id.swNoHistory); + spBiometricsTimeout = view.findViewById(R.id.spBiometricsTimeout); setOptions(); @@ -87,6 +91,19 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer } }); + spBiometricsTimeout.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, long id) { + int[] values = getResources().getIntArray(R.array.biometricsTimeoutValues); + prefs.edit().putInt("biometrics_timeout", values[position]).apply(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + prefs.edit().remove("biometrics_timeout").apply(); + } + }); + PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); return view; @@ -136,5 +153,13 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer swDisableTracking.setChecked(prefs.getBoolean("disable_tracking", true)); swDisplayHidden.setChecked(prefs.getBoolean("display_hidden", false)); swNoHistory.setChecked(prefs.getBoolean("no_history", false)); + + int biometrics_timeout = prefs.getInt("biometrics_timeout", 2); + int[] biometricTimeoutValues = getResources().getIntArray(R.array.biometricsTimeoutValues); + for (int pos = 0; pos < biometricTimeoutValues.length; pos++) + if (biometricTimeoutValues[pos] == biometrics_timeout) { + spBiometricsTimeout.setSelection(pos); + break; + } } } diff --git a/app/src/main/res/layout/fragment_options_behavior.xml b/app/src/main/res/layout/fragment_options_behavior.xml index 0027f88ae8..b4c2c40fb1 100644 --- a/app/src/main/res/layout/fragment_options_behavior.xml +++ b/app/src/main/res/layout/fragment_options_behavior.xml @@ -12,15 +12,27 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 73a718a65c..767a3d2417 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -12,78 +12,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - - - - - - - - - - - + + + +