diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index f98ac673dd..68223d9313 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -477,7 +477,7 @@ public class FragmentOptions extends FragmentBase { super.onCreateOptionsMenu(menu, inflater); } - static void reset(Context context, String[] options, Runnable confirmed) { + static void reset(Context context, List options, Runnable confirmed) { new AlertDialog.Builder(context) .setIcon(R.drawable.twotone_help_24) .setTitle(R.string.title_setup_defaults) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java index 55004f59d9..c6fb5621ec 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java @@ -51,6 +51,10 @@ import androidx.appcompat.widget.SwitchCompat; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.preference.PreferenceManager; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + public class FragmentOptionsBehavior extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { private View view; private ImageButton ibHelp; @@ -113,7 +117,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe final static int REQUEST_DEFAULT_FOLDER = 1; - private final static String[] RESET_OPTIONS = new String[]{ + private final static List RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( "restore_on_launch", "sync_on_launch", "double_back", "conversation_actions", "conversation_actions_replies", "language_detection", "photo_picker", "default_snooze", "pull", "pull_all", "autoscroll", "quick_filter", "quick_scroll", "quick_actions", "swipe_sensitivity", "foldernav", @@ -125,7 +129,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe "reset_snooze", "auto_block_sender", "auto_hide_answer", "swipe_reply", "move_thread_all", "move_thread_sent", "default_folder" - }; + )); @Override @Nullable @@ -639,6 +643,9 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (!RESET_OPTIONS.contains(key)) + return; + if ("default_snooze".equals(key)) return; diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java index a02249272f..707dc8262f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java @@ -66,6 +66,8 @@ import java.security.KeyStore; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import javax.net.SocketFactory; @@ -124,7 +126,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre private Group grpValidated; private Group grpCustomSsl; - private final static String[] RESET_OPTIONS = new String[]{ + private final static List RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( "metered", "download", "download_limited", "roaming", "rlah", "download_headers", "download_eml", "download_plain", "require_validated", "require_validated_captive", "vpn_only", @@ -134,7 +136,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre "ssl_update", "ssl_harden", "ssl_harden_strict", "cert_strict", "cert_transparency", "check_names", "open_safe", "http_redirect", "bouncy_castle", "bc_fips" - }; + )); @Override @Nullable @@ -665,6 +667,9 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (!RESET_OPTIONS.contains(key)) + return; + if ("timeout".equals(key)) return; if ("dns_extra".equals(key)) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java index a8f46e1ef6..8773531a08 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java @@ -60,6 +60,8 @@ import com.flask.colorpicker.builder.ColorPickerDialogBuilder; import java.text.NumberFormat; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; public class FragmentOptionsDisplay extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -202,7 +204,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer private NumberFormat NF = NumberFormat.getNumberInstance(); - private final static String[] RESET_OPTIONS = new String[]{ + private final static List RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( "theme", "startup", "date", "date_week", "date_fixed", "date_bold", "date_time", "group_category", "cards", "beige", "tabular_card_bg", "shadow_unread", "shadow_border", "shadow_highlight", "dividers", @@ -226,7 +228,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer "list_count", "bundled_fonts", "narrow_fonts", "parse_classes", "background_color", "text_color", "text_size", "text_font", "text_align", "text_titles", "authentication", "authentication_indicator" - }; + )); @Override @Nullable @@ -1435,6 +1437,9 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (!RESET_OPTIONS.contains(key)) + return; + if ("message_zoom".equals(key)) return; diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java b/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java index 2dc62e5dcb..f6c4c3b0f5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java @@ -75,6 +75,7 @@ import java.security.Security; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.List; @@ -117,12 +118,12 @@ public class FragmentOptionsEncryption extends FragmentBase static final int REQUEST_IMPORT_CERTIFICATE = 1; - private final static String[] RESET_OPTIONS = new String[]{ + private final static List RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( "sign_default", "encrypt_default", "encrypt_auto", "auto_verify", "auto_decrypt", "auto_undecrypt", "openpgp_provider", "autocrypt", "autocrypt_mutual", "encrypt_subject", "sign_algo_smime", "encrypt_algo_smime", "check_certificate" - }; + )); @Override @Nullable @@ -625,6 +626,9 @@ public class FragmentOptionsEncryption extends FragmentBase @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (!RESET_OPTIONS.contains(key)) + return; + getMainHandler().removeCallbacks(update); getMainHandler().postDelayed(update, FragmentOptions.DELAY_SETOPTIONS); } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsIntegrations.java b/app/src/main/java/eu/faircode/email/FragmentOptionsIntegrations.java index adc355c678..9c3322afdf 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsIntegrations.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsIntegrations.java @@ -46,6 +46,9 @@ import androidx.preference.PreferenceManager; import com.google.android.material.textfield.TextInputLayout; import java.text.NumberFormat; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; public class FragmentOptionsIntegrations extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { private View view; @@ -88,13 +91,13 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP private NumberFormat NF = NumberFormat.getNumberInstance(); - private final static String[] RESET_OPTIONS = new String[]{ + private final static List RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( "lt_enabled", "lt_sentence", "lt_auto", "lt_picky", "lt_highlight", "lt_description", "lt_uri", "lt_user", "lt_key", "deepl_enabled", "vt_enabled", "vt_apikey", "send_enabled", "send_host", "send_dlimit", "send_tlimit", "openai_enabled", "openai_uri", "openai_apikey", "openai_model", "openai_temperature", "openai_moderation" - }; + )); @Override @Nullable @@ -519,6 +522,9 @@ public class FragmentOptionsIntegrations extends FragmentBase implements SharedP @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (!RESET_OPTIONS.contains(key)) + return; + if ("lt_uri".equals(key) || "lt_user".equals(key) || "lt_key".equals(key) || diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 4849d53f9e..c094c16b28 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -90,6 +90,7 @@ import java.lang.reflect.Field; import java.nio.charset.Charset; import java.text.NumberFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -262,7 +263,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private static final int REQUEST_CLASSIFIER = 1; private static final long MIN_FILE_SIZE = 1024 * 1024L; - private final static String[] RESET_OPTIONS = new String[]{ + private final static List RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( "sort_answers", "shortcuts", "ical_tentative", "fts", "classification", "class_min_probability", "class_min_difference", "show_filtered", "haptic_feedback", @@ -287,7 +288,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc "easy_correct", "infra", "tld_flags", "json_ld", "dup_msgids", "thread_byref", "mdn", "app_chooser", "app_chooser_share", "adjacent_links", "adjacent_documents", "adjacent_portrait", "adjacent_landscape", "delete_confirmation", "global_keywords", "test_iab" - }; + )); private final static String[] RESET_QUESTIONS = new String[]{ "first", "app_support", "notify_archive", @@ -2059,6 +2060,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (!RESET_OPTIONS.contains(key)) + return; + if ("last_cleanup".equals(key)) setLastCleanup(prefs.getLong(key, -1)); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java index 2174be821c..b04ee30448 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java @@ -62,6 +62,9 @@ import androidx.appcompat.widget.SwitchCompat; import androidx.constraintlayout.widget.Group; import androidx.preference.PreferenceManager; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.function.Consumer; public class FragmentOptionsNotifications extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -132,7 +135,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared private Group grpBackground; private Group grpTiles; - private final static String[] RESET_OPTIONS = new String[]{ + private final static List RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( "notify_newest_first", "notify_summary", "notify_trash", "notify_junk", "notify_block_sender", "notify_archive", "notify_move", "notify_reply", "notify_reply_direct", @@ -145,7 +148,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared "wearable_preview", "notify_messaging", "biometrics_notify", "notify_open_folder", "background_service", "alert_once" - }; + )); @Override @Nullable @@ -801,6 +804,9 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (!RESET_OPTIONS.contains(key)) + return; + getMainHandler().removeCallbacks(update); getMainHandler().postDelayed(update, FragmentOptions.DELAY_SETOPTIONS); } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java index 4a1f3b5da3..baac385446 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java @@ -55,6 +55,8 @@ import androidx.webkit.WebViewFeature; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Locale; @@ -113,7 +115,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer private final static int BIP39_WORDS = 6; - private final static String[] RESET_OPTIONS = new String[]{ + private final static List RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( "confirm_links", "sanitize_links", "adguard", "adguard_auto_update", "check_links_dbl", "confirm_files", "confirm_images", "ask_images", "html_always_images", "confirm_html", "ask_html", @@ -124,7 +126,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer "generic_ua", "safe_browsing", "load_emoji", "disconnect_auto_update", "disconnect_links", "disconnect_images", "wipe_mnemonic" - }; + )); @Override @Nullable @@ -636,6 +638,9 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (!RESET_OPTIONS.contains(key)) + return; + getMainHandler().removeCallbacks(update); getMainHandler().postDelayed(update, FragmentOptions.DELAY_SETOPTIONS); } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index d6d028d080..3f9d75d679 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -57,6 +57,8 @@ import com.flask.colorpicker.builder.ColorPickerClickListener; import com.flask.colorpicker.builder.ColorPickerDialogBuilder; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -121,7 +123,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private SwitchCompat swReplyMove; private SwitchCompat swReplyMoveInbox; - private final static String[] RESET_OPTIONS = new String[]{ + private final static List RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( "keyboard", "keyboard_no_fullscreen", "suggest_names", "suggest_sent", "suggested_received", "suggest_frequently", "suggest_account", "auto_identity", "send_reminders", "send_chips", "send_nav_color", "send_pending", @@ -139,7 +141,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc "receipt_default", "receipt_type", "receipt_legacy", "forward_new", "lookup_mx", "reply_move", "reply_move_inbox" - }; + )); @Override @Nullable @@ -742,6 +744,9 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (!RESET_OPTIONS.contains(key)) + return; + getMainHandler().removeCallbacks(update); getMainHandler().postDelayed(update, FragmentOptions.DELAY_SETOPTIONS); } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java index cdec24c005..498a8bd075 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java @@ -64,7 +64,9 @@ import org.json.JSONObject; import java.text.DateFormatSymbols; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -128,7 +130,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr private int textColorTertiary; private int colorAccent; - private final static String[] RESET_OPTIONS = new String[]{ + private final static List RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( "enabled", "poll_interval", "auto_optimize", "schedule", "schedule_start", "schedule_end", "schedule_start_weekend", "schedule_end_weekend", "weekend", "sync_quick_imap", "sync_quick_pop", @@ -138,7 +140,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr "check_authentication", "check_tls", "check_reply_domain", "check_mx", "check_blocklist", "use_blocklist", "use_blocklist_pop", "tune_keep_alive" - }; + )); @Override public void onCreate(Bundle savedInstanceState) { @@ -646,6 +648,9 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (!RESET_OPTIONS.contains(key)) + return; + getMainHandler().removeCallbacks(update); getMainHandler().postDelayed(update, FragmentOptions.DELAY_SETOPTIONS); }