+ // Set the clear cookies preference icon.
+ if (clearEverything || sharedPreferences.getBoolean("clear_cookies", true)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
+ } else {
+ clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
+ }
+ } else {
+ clearCookiesPreference.setIcon(R.drawable.cookies_warning);
+ }
+
+ // Set the clear DOM storage preference icon.
+ if (clearEverything || sharedPreferences.getBoolean("clear_dom_storage", true)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
+ } else {
+ clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
+ }
+ } else {
+ clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
+ }
+
+ // Set the clear form data preference icon if the API < 26. It has no effect on newer versions of Android.
+ if (Build.VERSION.SDK_INT < 26) {
+ if (clearEverything || sharedPreferences.getBoolean("clear_form_data", true)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
+ } else {
+ clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
+ }
+ } else {
+ clearFormDataPreference.setIcon(R.drawable.form_data_warning);
+ }
+ }
+
+ // Set the clear logcat preference icon.
+ if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
+ } else {
+ clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
+ }
+ } else {
+ clearLogcatPreference.setIcon(R.drawable.bug_warning);
+ }
+
+ // Set the clear cache preference icon.
+ if (clearEverything || sharedPreferences.getBoolean("clear_cache", true)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ clearCachePreference.setIcon(R.drawable.cache_cleared_night);
+ } else {
+ clearCachePreference.setIcon(R.drawable.cache_cleared_day);
+ }
+ } else {
+ clearCachePreference.setIcon(R.drawable.cache_warning);
+ }
+
+ // Set the open intents in new tab preference icon.
+ if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
+ } else {
+ openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
+ }
+ } else {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
+ } else {
+ openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
+ }
+ }
+
+ // Set the swipe to refresh preference icon.
+ if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
+ } else {
+ swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
+ }
+ } else {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
+ } else {
+ swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
+ }
+ }
+
+ // Set the download with external app preference icon.
+ if (sharedPreferences.getBoolean(getString(R.string.download_with_external_app_key), false)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_day);
+ } else {
+ downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_night);
+ }
+ } else {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_day);
+ } else {
+ downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_night);
+ }
+ }
+
+ // Set the scroll app bar preference icon.
+ if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
+ } else {
+ scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
+ }
+ } else {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
+ } else {
+ scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
+ }
+ }
+
+ // Set the bottom app bar preference icon.
+ if (sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_enabled_day);
+ } else {
+ bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_enabled_night);
+ }
+ } else {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_disabled_day);
+ } else {
+ bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_disabled_night);
+ }
+ }
+
+ // Set the display additional app bar icons preference icon.
+ if (sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
+ } else {
+ displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
+ }
+ } else {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
+ } else {
+ displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
+ }
+ }
+
+ // Set the WebView theme preference icon.
+ switch (webViewThemeEntryNumber) {
+ case 0: // The system default WebView theme is selected.
+ // Set the icon according to the app theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
+ } else {
+ webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
+ }
+ break;
+
+ case 1: // The light WebView theme is selected.
+ // Set the icon according to the app theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
+ } else {
+ webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
+ }
+ break;
+
+ case 2: // The dark WebView theme is selected.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
+ } else {
+ webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
+ }
+ break;
+ }
+
+ // Set the wide viewport preference icon.
+ if (sharedPreferences.getBoolean("wide_viewport", true)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
+ } else {
+ wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
+ }
+ } else {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
+ } else {
+ wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
+ }
+ }
+
+ // Set the display webpage images preference icon.
+ if (sharedPreferences.getBoolean("display_webpage_images", true)) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
+ } else {
+ displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
+ }
+ } else {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
+ } else {
+ displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
+ }
+ }
+
+ // Get the shared preferences change listener.
+ sharedPreferenceChangeListener = getSharedPreferencesChangeListener(requireContext());
+
+ // Register the listener.
+ sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
+ }
+
+ // The listener should be unregistered when the app is paused.
+ @Override
+ public void onPause() {
+ // Run the default commands.
+ super.onPause();
+
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
+
+ // Unregister the shared preferences listener.
+ sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
+ }
+
+ // The listener should be re-registered when the app is resumed.
+ @Override
+ public void onResume() {
+ // Run the default commands.
+ super.onResume();
+
+ // Get a new shared preferences change listener.
+ sharedPreferenceChangeListener = getSharedPreferencesChangeListener(requireContext());
+
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
+
+ // Re-register the shared preferences listener.
+ sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
+ }
+
+ // The context must be passed to the shared preference change listener or else any calls to the system `getString()` will crash if the app has been restarted.
+ private SharedPreferences.OnSharedPreferenceChangeListener getSharedPreferencesChangeListener(Context context) {
+ // Return the shared preference change listener.
+ return (SharedPreferences sharedPreferences, String key) -> {
+ switch (key) {
+ case "javascript":
+ // Update the icons and the DOM storage preference status.
+ if (sharedPreferences.getBoolean("javascript", false)) { // The JavaScript preference is enabled.
+ // Update the icon for the JavaScript preference.
+ javaScriptPreference.setIcon(R.drawable.javascript_enabled);
+
+ // Update the status of the DOM storage preference.
+ domStoragePreference.setEnabled(true);
+
+ // Update the icon for the DOM storage preference.
+ if (sharedPreferences.getBoolean("dom_storage", false)) {
+ domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
+ } else {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);