+ } else {
+ clearCachePreference.setIcon(R.drawable.cache_warning);
+ }
+ break;
+
+ case "clear_cookies":
+ // Update the icon.
+ if (sharedPreferences.getBoolean("clear_cookies", true)) {
+ if (darkTheme) {
+ clearCookiesPreference.setIcon(R.drawable.cookies_cleared_dark);
+ } else {
+ clearCookiesPreference.setIcon(R.drawable.cookies_cleared_light);
+ }
+ } else {
+ clearCookiesPreference.setIcon(R.drawable.cookies_warning);
+ }
+ break;
+
+ case "clear_dom_storage":
+ // Update the icon.
+ if (sharedPreferences.getBoolean("clear_dom_storage", true)) {
+ if (darkTheme) {
+ clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_dark);
+ } else {
+ clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_light);
+ }
+ } else {
+ clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
+ }
+ break;
+
+ // This section can be removed once the minimum API >= 26.
+ case "clear_form_data":
+ // Update the icon.
+ if (sharedPreferences.getBoolean("clear_form_data", true)) {
+ if (darkTheme) {
+ clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark);
+ } else {
+ clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light);
+ }
+ } else {
+ clearFormDataPreference.setIcon(R.drawable.form_data_warning);
+ }
+ break;
+
+ case "clear_cache":
+ // Update the icon.
+ if (sharedPreferences.getBoolean("clear_cache", true)) {
+ if (darkTheme) {
+ clearCachePreference.setIcon(R.drawable.cache_cleared_dark);
+ } else {
+ clearCachePreference.setIcon(R.drawable.cache_cleared_light);
+ }
+ } else {
+ clearCachePreference.setIcon(R.drawable.cache_warning);
+ }
+ break;
+
+ case "homepage":
+ // Set the new homepage URL as the summary text for the Homepage preference.
+ homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
+ break;
+
+ case "font_size":
+ // Update the font size summary text.
+ fontSizePreference.setSummary(sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%%");
+ break;
+
+ case "open_intents_in_new_tab":
+ // Update the icon.
+ if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
+ if (darkTheme) {
+ openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_dark);
+ } else {
+ openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_light);
+ }
+ } else {
+ if (darkTheme) {
+ openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_dark);
+ } else {
+ openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_light);
+ }
+ }
+ break;
+
+ case "swipe_to_refresh":
+ // Update the icon.
+ if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
+ if (darkTheme) {
+ swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_dark);
+ } else {
+ swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_light);
+ }
+ } else {
+ if (darkTheme) {
+ swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_dark);
+ } else {
+ swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_light);
+ }
+ }
+ break;
+
+ case "scroll_app_bar":
+ // Update the icon.
+ if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
+ if (darkTheme) {
+ scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
+ } else {
+ scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
+ }
+ } else {
+ if (darkTheme) {
+ scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
+ } else {
+ scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
+ }
+ }
+ break;
+
+ case "display_additional_app_bar_icons":
+ // Update the icon.
+ if (sharedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
+ if (darkTheme) {
+ displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_dark);
+ } else {
+ displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_light);
+ }
+ } else {
+ if (darkTheme) {
+ displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_dark);
+ } else {
+ displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_light);
+ }
+ }
+ break;
+
+ case "download_with_external_app":
+ // Update the icon.
+ if (sharedPreferences.getBoolean("download_with_external_app", false)) {
+ if (darkTheme) {
+ downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_dark);
+ } else {
+ downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_light);
+ }
+ } else {
+ if (darkTheme) {
+ downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_dark);
+ } else {
+ downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_light);
+ }
+ }
+ break;
+
+ case "dark_theme":
+ // Update the icon.
+ if (sharedPreferences.getBoolean("dark_theme", false)) {
+ darkThemePreference.setIcon(R.drawable.theme_dark);
+ } else {
+ darkThemePreference.setIcon(R.drawable.theme_light);
+ }
+
+ // Create an intent to restart Privacy Browser.
+ Intent changeThemeRestartIntent = getActivity().getParentActivityIntent();
+
+ // Assert that the intent is not null to remove the lint error below.
+ assert changeThemeRestartIntent != null;
+
+ // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack. It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
+ changeThemeRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+
+ // Create a handler to restart the activity.
+ Handler changeThemeRestartHandler = new Handler();
+
+ // Create a runnable to restart the activity.
+ Runnable changeThemeRestartRunnable = () -> {
+ // Restart the activity.
+ startActivity(changeThemeRestartIntent);
+
+ // Kill this instance of Privacy Browser. Otherwise, the app exhibits sporadic behavior after the restart.
+ System.exit(0);
+ };
+
+ // Restart the activity after 100 milliseconds, so that the app has enough time to save the change to the preference.
+ changeThemeRestartHandler.postDelayed(changeThemeRestartRunnable, 100);
+ break;
+
+ case "night_mode":
+ // Store the current night mode status.
+ boolean currentNightModeBoolean = sharedPreferences.getBoolean("night_mode", false);
+ boolean currentJavaScriptBoolean = sharedPreferences.getBoolean("javascript", false);
+
+ // Update the icon.
+ if (currentNightModeBoolean) {
+ if (darkTheme) {
+ nightModePreference.setIcon(R.drawable.night_mode_enabled_dark);
+ } else {
+ nightModePreference.setIcon(R.drawable.night_mode_enabled_light);
+ }
+ } else {
+ if (darkTheme) {
+ nightModePreference.setIcon(R.drawable.night_mode_disabled_dark);
+ } else {
+ nightModePreference.setIcon(R.drawable.night_mode_disabled_light);
+ }
+ }
+
+ // Update the status of `javaScriptPreference` and `domStoragePreference`.
+ javaScriptPreference.setEnabled(!currentNightModeBoolean);
+ domStoragePreference.setEnabled(currentNightModeBoolean || currentJavaScriptBoolean);
+
+ // Update the `javaScriptPreference` icon.
+ if (currentNightModeBoolean || currentJavaScriptBoolean) {
+ javaScriptPreference.setIcon(R.drawable.javascript_enabled);
+ } else {
+ javaScriptPreference.setIcon(R.drawable.privacy_mode);
+ }
+
+ // Update the DOM storage preference icon.
+ if (currentNightModeBoolean || currentJavaScriptBoolean) { // The preference is enabled.
+ if (sharedPreferences.getBoolean("dom_storage", false)) { // DOM storage is enabled.
+ domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
+ } else { // DOM storage is disabled.
+ if (darkTheme) {
+ domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
+ } else {
+ domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
+ }
+ }
+ } else { // The preference is disabled. The icon should be ghosted.
+ if (darkTheme) {
+ domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_dark);