mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-02 19:10:11 +01:00
Reset default per options section
This commit is contained in:
@@ -25,6 +25,9 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
@@ -53,10 +56,15 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
|
||||
private Group grpSearchLocal;
|
||||
|
||||
private final static String[] RESET_OPTIONS = new String[]{
|
||||
"badge", "subscriptions", "search_local", "english", "authentication", "paranoid", "updates", "debug"
|
||||
};
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
setSubtitle(R.string.title_advanced);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_options_misc, container, false);
|
||||
|
||||
@@ -80,8 +88,6 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
|
||||
setOptions();
|
||||
|
||||
swBadge.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
@@ -160,6 +166,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
|
||||
setLastCleanup(prefs.getLong("last_cleanup", -1));
|
||||
|
||||
setOptions();
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
return view;
|
||||
@@ -171,6 +178,38 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
setOptions();
|
||||
if ("last_cleanup".equals(key))
|
||||
setLastCleanup(prefs.getLong(key, -1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.menu_options, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_default:
|
||||
onMenuDefault();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void onMenuDefault() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
for (String option : RESET_OPTIONS)
|
||||
editor.remove(option);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private void setOptions() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
|
||||
@@ -187,12 +226,6 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
grpSearchLocal.setVisibility(Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
if ("last_cleanup".equals(key))
|
||||
setLastCleanup(prefs.getLong(key, -1));
|
||||
}
|
||||
|
||||
private void setLastCleanup(long time) {
|
||||
java.text.DateFormat df = SimpleDateFormat.getDateTimeInstance();
|
||||
tvLastCleanup.setText(
|
||||
|
||||
Reference in New Issue
Block a user