c6a1493e645e96fd094217fae3df80b891d1c139
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / SettingsFragment.java
1 /*
2  * Copyright © 2016-2021 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
5  *
6  * Privacy Browser is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package com.stoutner.privacybrowser.fragments;
21
22 import android.annotation.SuppressLint;
23 import android.app.Activity;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.content.SharedPreferences;
27 import android.content.res.Configuration;
28 import android.content.res.Resources;
29 import android.os.Build;
30 import android.os.Bundle;
31 import android.os.Handler;
32 import android.os.Looper;
33 import android.view.LayoutInflater;
34 import android.view.View;
35 import android.webkit.WebView;
36 import android.widget.ArrayAdapter;
37
38 import androidx.appcompat.app.AppCompatDelegate;
39 import androidx.preference.Preference;
40 import androidx.preference.PreferenceCategory;
41 import androidx.preference.PreferenceFragmentCompat;
42
43 import com.stoutner.privacybrowser.R;
44 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
45 import com.stoutner.privacybrowser.helpers.ProxyHelper;
46
47 public class SettingsFragment extends PreferenceFragmentCompat {
48     // Declare the class variables.
49     private int currentThemeStatus;
50     private String defaultUserAgent;
51     private ArrayAdapter<CharSequence> userAgentNamesArray;
52     private String[] translatedUserAgentNamesArray;
53     private String[] userAgentDataArray;
54     private String[] appThemeEntriesStringArray;
55     private String[] appThemeEntryValuesStringArray;
56     private String[] webViewThemeEntriesStringArray;
57     private String[] webViewThemeEntryValuesStringArray;
58     private SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener;
59
60     // Declare the class views.
61     private Preference javaScriptPreference;
62     private Preference cookiesPreference;
63     private Preference domStoragePreference;
64     private Preference formDataPreference;  // The form data preference can be removed once the minimum API >= 26.
65     private Preference userAgentPreference;
66     private Preference customUserAgentPreference;
67     private Preference incognitoModePreference;
68     private Preference allowScreenshotsPreference;
69     private Preference easyListPreference;
70     private Preference easyPrivacyPreference;
71     private Preference fanboyAnnoyanceListPreference;
72     private Preference fanboySocialBlockingListPreference;
73     private Preference ultraListPreference;
74     private Preference ultraPrivacyPreference;
75     private Preference blockAllThirdPartyRequestsPreference;
76     private Preference googleAnalyticsPreference;
77     private Preference facebookClickIdsPreference;
78     private Preference twitterAmpRedirectsPreference;
79     private Preference searchPreference;
80     private Preference searchCustomURLPreference;
81     private Preference proxyPreference;
82     private Preference proxyCustomUrlPreference;
83     private Preference fullScreenBrowsingModePreference;
84     private Preference hideAppBarPreference;
85     private Preference clearEverythingPreference;
86     private Preference clearCookiesPreference;
87     private Preference clearDomStoragePreference;
88     private Preference clearFormDataPreference;  // The clear form data preference can be removed once the minimum API >= 26.
89     private Preference clearLogcatPreference;
90     private Preference clearCachePreference;
91     private Preference homepagePreference;
92     private Preference fontSizePreference;
93     private Preference openIntentsInNewTabPreference;
94     private Preference swipeToRefreshPreference;
95     private Preference downloadWithExternalAppPreference;
96     private Preference scrollAppBarPreference;
97     private Preference displayAdditionalAppBarIconsPreference;
98     private Preference appThemePreference;
99     private Preference webViewThemePreference;
100     private Preference wideViewportPreference;
101     private Preference displayWebpageImagesPreference;
102
103     @Override
104     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
105         // Load the preferences from the XML file.
106         setPreferencesFromResource(R.xml.preferences, rootKey);
107
108         // Get a handle for the activity.
109         Activity activity = getActivity();
110
111         // Remove the lint warning below that `getApplicationContext()` might produce a null pointer exception.
112         assert activity != null;
113
114         // Get a handle for the resources.
115         Resources resources = getResources();
116
117         // Get the current theme status.
118         currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
119
120         // // Get a handle for the shared preferences.
121         SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
122
123         // Get handles for the preferences.
124         javaScriptPreference = findPreference("javascript");
125         cookiesPreference = findPreference(getString(R.string.cookies_key));
126         domStoragePreference = findPreference("dom_storage");
127         formDataPreference = findPreference("save_form_data");  // The form data preference can be removed once the minimum API >= 26.
128         userAgentPreference = findPreference("user_agent");
129         customUserAgentPreference = findPreference("custom_user_agent");
130         incognitoModePreference = findPreference("incognito_mode");
131         allowScreenshotsPreference = findPreference(getString(R.string.allow_screenshots_key));
132         easyListPreference = findPreference("easylist");
133         easyPrivacyPreference = findPreference("easyprivacy");
134         fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
135         fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
136         ultraListPreference = findPreference("ultralist");
137         ultraPrivacyPreference = findPreference("ultraprivacy");
138         blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
139         googleAnalyticsPreference = findPreference("google_analytics");
140         facebookClickIdsPreference = findPreference("facebook_click_ids");
141         twitterAmpRedirectsPreference = findPreference("twitter_amp_redirects");
142         searchPreference = findPreference("search");
143         searchCustomURLPreference = findPreference("search_custom_url");
144         proxyPreference = findPreference("proxy");
145         proxyCustomUrlPreference = findPreference("proxy_custom_url");
146         fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
147         hideAppBarPreference = findPreference("hide_app_bar");
148         clearEverythingPreference = findPreference("clear_everything");
149         clearCookiesPreference = findPreference("clear_cookies");
150         clearDomStoragePreference = findPreference("clear_dom_storage");
151         clearFormDataPreference = findPreference("clear_form_data");  // The clear form data preference can be removed once the minimum API >= 26.
152         clearLogcatPreference = findPreference(getString(R.string.clear_logcat_key));
153         clearCachePreference = findPreference("clear_cache");
154         homepagePreference = findPreference("homepage");
155         fontSizePreference = findPreference("font_size");
156         openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab");
157         swipeToRefreshPreference = findPreference("swipe_to_refresh");
158         downloadWithExternalAppPreference = findPreference(getString(R.string.download_with_external_app_key));
159         scrollAppBarPreference = findPreference("scroll_app_bar");
160         displayAdditionalAppBarIconsPreference = findPreference(getString(R.string.display_additional_app_bar_icons_key));
161         appThemePreference = findPreference("app_theme");
162         webViewThemePreference = findPreference("webview_theme");
163         wideViewportPreference = findPreference("wide_viewport");
164         displayWebpageImagesPreference = findPreference("display_webpage_images");
165
166         // Remove the lint warnings below that the preferences might be null.
167         assert javaScriptPreference != null;
168         assert cookiesPreference != null;
169         assert domStoragePreference != null;
170         assert formDataPreference != null;
171         assert userAgentPreference != null;
172         assert customUserAgentPreference != null;
173         assert incognitoModePreference != null;
174         assert allowScreenshotsPreference != null;
175         assert easyListPreference != null;
176         assert easyPrivacyPreference != null;
177         assert fanboyAnnoyanceListPreference != null;
178         assert fanboySocialBlockingListPreference != null;
179         assert ultraListPreference != null;
180         assert ultraPrivacyPreference != null;
181         assert blockAllThirdPartyRequestsPreference != null;
182         assert googleAnalyticsPreference != null;
183         assert facebookClickIdsPreference != null;
184         assert twitterAmpRedirectsPreference != null;
185         assert searchPreference != null;
186         assert searchCustomURLPreference != null;
187         assert proxyPreference != null;
188         assert proxyCustomUrlPreference != null;
189         assert fullScreenBrowsingModePreference != null;
190         assert hideAppBarPreference != null;
191         assert clearEverythingPreference != null;
192         assert clearCookiesPreference != null;
193         assert clearDomStoragePreference != null;
194         assert clearFormDataPreference != null;
195         assert clearLogcatPreference != null;
196         assert clearCachePreference != null;
197         assert homepagePreference != null;
198         assert fontSizePreference != null;
199         assert openIntentsInNewTabPreference != null;
200         assert swipeToRefreshPreference != null;
201         assert downloadWithExternalAppPreference != null;
202         assert scrollAppBarPreference != null;
203         assert displayAdditionalAppBarIconsPreference != null;
204         assert appThemePreference != null;
205         assert webViewThemePreference != null;
206         assert wideViewportPreference != null;
207         assert displayWebpageImagesPreference != null;
208
209         // Set the preference dependencies.
210         hideAppBarPreference.setDependency("full_screen_browsing_mode");
211         domStoragePreference.setDependency("javascript");
212
213         // Get strings from the preferences.
214         String userAgentName = sharedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
215         String searchString = sharedPreferences.getString("search", getString(R.string.search_default_value));
216         String proxyString = sharedPreferences.getString("proxy", getString(R.string.proxy_default_value));
217
218         // Get booleans that are used in multiple places from the preferences.
219         boolean javaScriptEnabled = sharedPreferences.getBoolean("javascript", false);
220         boolean fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
221         boolean fanboySocialBlockingEnabled = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
222         boolean fullScreenBrowsingMode = sharedPreferences.getBoolean("full_screen_browsing_mode", false);
223         boolean clearEverything = sharedPreferences.getBoolean("clear_everything", true);
224
225         // Remove the form data preferences if the API is >= 26 as they no longer do anything.
226         if (Build.VERSION.SDK_INT >= 26) {
227             // Get handles for the categories.
228             PreferenceCategory privacyCategory = findPreference("privacy");
229             PreferenceCategory clearAndExitCategory = findPreference("clear_and_exit");
230
231             // Remove the incorrect lint warnings below that the preference categories might be null.
232             assert privacyCategory != null;
233             assert clearAndExitCategory != null;
234
235             // Remove the form data preferences.
236             privacyCategory.removePreference(formDataPreference);
237             clearAndExitCategory.removePreference(clearFormDataPreference);
238         }
239
240         // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled.
241         fanboySocialBlockingListPreference.setEnabled(!fanboyAnnoyanceListEnabled);
242
243
244         // Inflate a WebView to get the default user agent.
245         LayoutInflater inflater = getActivity().getLayoutInflater();
246
247         // `@SuppressLint("InflateParams")` removes the warning about using `null` as the `ViewGroup`, which in this case makes sense because the `bare_webview` will not be displayed.
248         @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
249
250         // Get a handle for a bare WebView.
251         WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
252
253         // Get the default user agent.
254         defaultUserAgent = bareWebView.getSettings().getUserAgentString();
255
256         // Get the user agent arrays.
257         userAgentNamesArray = ArrayAdapter.createFromResource(requireContext(), R.array.user_agent_names, R.layout.spinner_item);
258         translatedUserAgentNamesArray = resources.getStringArray(R.array.translated_user_agent_names);
259         userAgentDataArray = resources.getStringArray(R.array.user_agent_data);
260
261         // Get the array position of the user agent name.
262         int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName);
263
264         // Populate the user agent summary.
265         switch (userAgentArrayPosition) {
266             case MainWebViewActivity.UNRECOGNIZED_USER_AGENT:  // The user agent name is not on the canonical list.
267                 // This is probably because it was set in an older version of Privacy Browser before the switch to persistent user agent names.  Use the current user agent entry name as the summary.
268                 userAgentPreference.setSummary(userAgentName);
269                 break;
270
271             case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
272                 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
273                 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + defaultUserAgent);
274                 break;
275
276             case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
277                 // Set the summary text.
278                 userAgentPreference.setSummary(R.string.custom_user_agent);
279                 break;
280
281             default:
282                 // Get the user agent summary from the user agent data array.
283                 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + userAgentDataArray[userAgentArrayPosition]);
284         }
285
286         // Set the summary text for the custom user agent preference.
287         customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
288
289         // Only enable the custom user agent preference if the user agent is set to `Custom`.
290         customUserAgentPreference.setEnabled(userAgentPreference.getSummary().equals(getString(R.string.custom_user_agent)));
291
292
293         // Set the search URL as the summary text for the search preference when the preference screen is loaded.
294         if (searchString.equals("Custom URL")) {
295             // Use R.string.custom_url, which will be translated, instead of the array value, which will not.
296             searchPreference.setSummary(R.string.custom_url);
297         } else {
298             // Set the array value as the summary text.
299             searchPreference.setSummary(searchString);
300         }
301
302         // Set the summary text for the search custom URL (the default is `""`).
303         searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
304
305         // Only enable the search custom URL preference if the search is set to `Custom URL`.
306         searchCustomURLPreference.setEnabled(searchString.equals("Custom URL"));
307
308
309         // Set the summary text for the proxy preference when the preference screen is loaded.
310         switch (proxyString) {
311             case ProxyHelper.NONE:
312                 proxyPreference.setSummary(getString(R.string.no_proxy_enabled));
313                 break;
314
315             case ProxyHelper.TOR:
316                 if (Build.VERSION.SDK_INT == 19) {  // Proxying through SOCKS doesn't work on Android KitKat.
317                     proxyPreference.setSummary(getString(R.string.tor_enabled_kitkat));
318                 } else {
319                     proxyPreference.setSummary(getString(R.string.tor_enabled));
320                 }
321                 break;
322
323             case ProxyHelper.I2P:
324                 proxyPreference.setSummary(getString(R.string.i2p_enabled));
325                 break;
326
327             case ProxyHelper.CUSTOM:
328                 proxyPreference.setSummary(getString(R.string.custom_proxy));
329                 break;
330         }
331
332         // Set the summary text for the custom proxy URL.
333         proxyCustomUrlPreference.setSummary(sharedPreferences.getString("proxy_custom_url", getString(R.string.proxy_custom_url_default_value)));
334
335         // Only enable the custom proxy URL if a custom proxy is selected.
336         proxyCustomUrlPreference.setEnabled(proxyString.equals("Custom"));
337
338
339         // Set the status of the clear and exit preferences.
340         clearCookiesPreference.setEnabled(!clearEverything);
341         clearDomStoragePreference.setEnabled(!clearEverything);
342         clearFormDataPreference.setEnabled(!clearEverything);  // The form data line can be removed once the minimum API is >= 26.
343         clearLogcatPreference.setEnabled(!clearEverything);
344         clearCachePreference.setEnabled(!clearEverything);
345
346
347         // Set the homepage URL as the summary text for the homepage preference.
348         homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
349
350
351         // Set the font size as the summary text for the preference.
352         fontSizePreference.setSummary(sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%");
353
354
355         // Get the app theme string arrays.
356         appThemeEntriesStringArray = resources.getStringArray(R.array.app_theme_entries);
357         appThemeEntryValuesStringArray = resources.getStringArray(R.array.app_theme_entry_values);
358
359         // Get the current app theme.
360         String currentAppTheme = sharedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
361
362         // Define an app theme entry number.
363         int appThemeEntryNumber;
364
365         // Get the app theme entry number that matches the current app theme.  A switch statement cannot be used because the theme entry values string array is not a compile time constant.
366         if (currentAppTheme.equals(appThemeEntryValuesStringArray[1])) {  // The light theme is selected.
367             // Store the app theme entry number.
368             appThemeEntryNumber = 1;
369         } else if (currentAppTheme.equals(appThemeEntryValuesStringArray[2])) {  // The dark theme is selected.
370             // Store the app theme entry number.
371             appThemeEntryNumber = 2;
372         } else {  // The system default theme is selected.
373             // Store the app theme entry number.
374             appThemeEntryNumber = 0;
375         }
376
377         // Set the current theme as the summary text for the preference.
378         appThemePreference.setSummary(appThemeEntriesStringArray[appThemeEntryNumber]);
379
380
381         // Get the WebView theme string arrays.
382         webViewThemeEntriesStringArray = resources.getStringArray(R.array.webview_theme_entries);
383         webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values);
384
385         // Get the current WebView theme.
386         String currentWebViewTheme = sharedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value));
387
388         // Define a WebView theme entry number.
389         int webViewThemeEntryNumber;
390
391         // Get the WebView theme entry number that matches the current WebView theme.  A switch statement cannot be used because the WebView theme entry values string array is not a compile time constant.
392         if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[1])) {  // The light theme is selected.
393             // Store the WebView theme entry number.
394             webViewThemeEntryNumber = 1;
395         } else if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) {  // The dark theme is selected.
396             // Store the WebView theme entry number.
397             webViewThemeEntryNumber = 2;
398         } else {  // The system default theme is selected.
399             // Store the WebView theme entry number.
400             webViewThemeEntryNumber = 0;
401         }
402
403         // Set the visibility of the WebView theme preference.
404         if (Build.VERSION.SDK_INT < 21) {  // The device is running API 19.
405             // Get a handle for the general category.
406             PreferenceCategory generalCategory = findPreference("general");
407
408             // Remove the incorrect lint warning below that the general preference category might be null.
409             assert generalCategory != null;
410
411             // Remove the WebView theme preference.
412             generalCategory.removePreference(webViewThemePreference);
413         } else {  // The device is running API >= 21
414             // Set the current theme as the summary text for the preference.
415             webViewThemePreference.setSummary(webViewThemeEntriesStringArray[webViewThemeEntryNumber]);
416         }
417
418
419         // Set the JavaScript icon.
420         if (javaScriptEnabled) {
421             javaScriptPreference.setIcon(R.drawable.javascript_enabled);
422         } else {
423             javaScriptPreference.setIcon(R.drawable.privacy_mode);
424         }
425
426         // Set the cookies icon.
427         if (sharedPreferences.getBoolean(getString(R.string.cookies_key), false)) {
428             cookiesPreference.setIcon(R.drawable.cookies_enabled);
429         } else {
430             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
431                 cookiesPreference.setIcon(R.drawable.cookies_disabled_day);
432             } else {
433                 cookiesPreference.setIcon(R.drawable.cookies_disabled_night);
434             }
435         }
436
437         // Set the DOM storage icon.
438         if (javaScriptEnabled) {  // The preference is enabled.
439             if (sharedPreferences.getBoolean("dom_storage", false)) {  // DOM storage is enabled.
440                 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
441             } else {  // DOM storage is disabled.
442                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
443                     domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
444                 } else {
445                     domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
446                 }
447             }
448         } else {  // The preference is disabled.  The icon should be ghosted.
449             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
450                 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
451             } else {
452                 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
453             }
454         }
455
456         // Set the save form data icon if API < 26.  Save form data has no effect on API >= 26.
457         if (Build.VERSION.SDK_INT < 26) {
458             if (sharedPreferences.getBoolean("save_form_data", false)) {
459                 formDataPreference.setIcon(R.drawable.form_data_enabled);
460             } else {
461                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
462                     formDataPreference.setIcon(R.drawable.form_data_disabled_day);
463                 } else {
464                     formDataPreference.setIcon(R.drawable.form_data_disabled_night);
465                 }
466             }
467         }
468
469         // Set the custom user agent icon.
470         if (customUserAgentPreference.isEnabled()) {
471             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
472                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
473             } else {
474                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
475             }
476         } else {
477             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
478                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
479             } else {
480                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
481             }
482         }
483
484         // Set the incognito mode icon.
485         if (sharedPreferences.getBoolean("incognito_mode", false)) {
486             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
487                 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
488             } else {
489                 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
490             }
491         } else {
492             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
493                 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
494             } else {
495                 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
496             }
497         }
498
499         // Set the allow screenshots icon.
500         if (sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) {
501             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
502                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
503             } else {
504                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
505             }
506         } else {
507             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
508                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
509             } else {
510                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
511             }
512         }
513
514         // Set the EasyList icon.
515         if (sharedPreferences.getBoolean("easylist", true)) {
516             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
517                 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
518             } else {
519                 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
520             }
521         } else {
522             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
523                 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
524             } else {
525                 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
526             }
527         }
528
529         // Set the EasyPrivacy icon.
530         if (sharedPreferences.getBoolean("easyprivacy", true)) {
531             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
532                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
533             } else {
534                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
535             }
536         } else {
537             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
538                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
539             } else {
540                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
541             }
542         }
543
544         // Set the Fanboy lists icons.
545         if (fanboyAnnoyanceListEnabled) {
546             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
547                 // Set the Fanboy annoyance list icon.
548                 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
549
550                 // Set the Fanboy social blocking list icon.
551                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
552             } else {
553                 // Set the Fanboy annoyance list icon.
554                 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
555
556                 // Set the Fanboy social blocking list icon.
557                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
558             }
559         } else {
560             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
561                 // Set the Fanboy annoyance list icon.
562                 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
563
564                 // Set the Fanboy social blocking list icon.
565                 if (fanboySocialBlockingEnabled) {
566                     fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
567                 } else {
568                     fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
569                 }
570             } else {
571                 // Set the Fanboy annoyance list icon.
572                 fanboyAnnoyanceListPreference.setIcon(R.drawable.block_ads_disabled_day);
573
574                 // Set the Fanboy social blocking list icon.
575                 if (fanboySocialBlockingEnabled) {
576                     fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
577                 } else {
578                     fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
579                 }
580             }
581         }
582
583         // Set the UltraList icon.
584         if (sharedPreferences.getBoolean("ultralist", true)){
585             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
586                 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
587             } else {
588                 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
589             }
590         } else {
591             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
592                 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
593             } else {
594                 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
595             }
596         }
597
598         // Set the UltraPrivacy icon.
599         if (sharedPreferences.getBoolean("ultraprivacy", true)) {
600             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
601                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
602             } else {
603                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
604             }
605         } else {
606             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
607                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
608             } else {
609                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
610             }
611         }
612
613         // Set the block all third-party requests icon.
614         if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
615             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
616                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
617             } else {
618                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
619             }
620         } else {
621             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
622                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
623             } else {
624                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
625             }
626         }
627
628         // Set the Google Analytics icon according to the theme.
629         if (sharedPreferences.getBoolean("google_analytics", true)) {
630             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
631                 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
632             } else {
633                 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
634             }
635         } else {
636             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
637                 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
638             } else {
639                 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
640             }
641         }
642
643         // Set the Facebook Click IDs icon according to the theme.
644         if (sharedPreferences.getBoolean("facebook_click_ids", true)) {
645             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
646                 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
647             } else {
648                 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
649             }
650         } else {
651             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
652                 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
653             } else {
654                 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
655             }
656         }
657
658         // Set the Twitter AMP redirects icon according to the theme.
659         if (sharedPreferences.getBoolean("twitter_amp_redirects", true)) {
660             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
661                 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
662             } else {
663                 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
664             }
665         } else {
666             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
667                 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
668             } else {
669                 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
670             }
671         }
672
673         // Set the search custom URL icon.
674         if (searchCustomURLPreference.isEnabled()) {
675             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
676                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
677             } else {
678                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
679             }
680         } else {
681             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
682                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
683             } else {
684                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
685             }
686         }
687
688         // Set the Proxy icons according to the theme and status.
689         if (proxyString.equals("None")) {  // Proxying is disabled.
690             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {  // Dark theme.
691                 // Set the main proxy icon to be disabled.
692                 proxyPreference.setIcon(R.drawable.proxy_disabled_night);
693
694                 // Set the custom proxy URL icon to be ghosted.
695                 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
696             } else {  // Light theme.
697                 // Set the main proxy icon to be disabled.
698                 proxyPreference.setIcon(R.drawable.proxy_disabled_day);
699
700                 // Set the custom proxy URL icon to be ghosted.
701                 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
702             }
703         } else {  // Proxying is enabled.
704             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {  // Dark theme.
705                 // Set the main proxy icon to be enabled.
706                 proxyPreference.setIcon(R.drawable.proxy_enabled_night);
707
708                 // Set the custom proxy URL icon according to its status.
709                 if (proxyCustomUrlPreference.isEnabled()) {  // Custom proxy is enabled.
710                     proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
711                 } else {  // Custom proxy is disabled.
712                     proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
713                 }
714             } else {  // Light theme.
715                 // Set the main proxy icon to be enabled.
716                 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
717
718                 // Set the custom proxy URL icon according to its status.
719                 if (proxyCustomUrlPreference.isEnabled()) {  // Custom proxy is enabled.
720                     proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
721                 } else {  // Custom proxy is disabled.
722                     proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
723                 }
724             }
725         }
726
727         // Set the full screen browsing mode icons.
728         if (fullScreenBrowsingMode) {  // Full screen browsing mode is enabled.
729             // Set the `fullScreenBrowsingModePreference` icon according to the theme.
730             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
731                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
732             } else {
733                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
734             }
735
736             // Set the hide app bar icon.
737             if (sharedPreferences.getBoolean("hide_app_bar", true)) {  // Hide app bar is enabled.
738                 // Set the icon according to the theme.
739                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
740                     hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
741                 } else {
742                     hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
743                 }
744             } else {  // Hide app bar is disabled.
745                 // Set the icon according to the theme.
746                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
747                     hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
748                 } else {
749                     hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
750                 }
751             }
752         } else {  // Full screen browsing mode is disabled.
753             // Set the icons according to the theme.
754             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
755                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
756                 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
757             } else {
758                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
759                 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
760             }
761         }
762
763         // Set the clear everything preference icon.
764         if (clearEverything) {
765             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
766                 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
767             } else {
768                 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
769             }
770         } else {
771             clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
772         }
773
774         // Set the clear cookies preference icon.
775         if (clearEverything || sharedPreferences.getBoolean("clear_cookies", true)) {
776             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
777                 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
778             } else {
779                 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
780             }
781         } else {
782             clearCookiesPreference.setIcon(R.drawable.cookies_warning);
783         }
784
785         // Set the clear DOM storage preference icon.
786         if (clearEverything || sharedPreferences.getBoolean("clear_dom_storage", true)) {
787             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
788                 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
789             } else {
790                 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
791             }
792         } else {
793             clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
794         }
795
796         // Set the clear form data preference icon if the API < 26.  It has no effect on newer versions of Android.
797         if (Build.VERSION.SDK_INT < 26) {
798             if (clearEverything || sharedPreferences.getBoolean("clear_form_data", true)) {
799                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
800                     clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
801                 } else {
802                     clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
803                 }
804             } else {
805                 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
806             }
807         }
808
809         // Set the clear logcat preference icon.
810         if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
811             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
812                 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
813             } else {
814                 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
815             }
816         } else {
817             clearLogcatPreference.setIcon(R.drawable.bug_warning);
818         }
819
820         // Set the clear cache preference icon.
821         if (clearEverything || sharedPreferences.getBoolean("clear_cache", true)) {
822             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
823                 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
824             } else {
825                 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
826             }
827         } else {
828             clearCachePreference.setIcon(R.drawable.cache_warning);
829         }
830
831         // Set the open intents in new tab preference icon.
832         if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
833             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
834                 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
835             } else {
836                 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
837             }
838         } else {
839             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
840                 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
841             } else {
842                 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
843             }
844         }
845
846         // Set the swipe to refresh preference icon.
847         if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
848             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
849                 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
850             } else {
851                 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
852             }
853         } else {
854             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
855                 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
856             } else {
857                 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
858             }
859         }
860
861         // Set the download with external app preference icon.
862         if (sharedPreferences.getBoolean(getString(R.string.download_with_external_app_key), false)) {
863             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
864                 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_day);
865             } else {
866                 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_night);
867             }
868         } else {
869             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
870                 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_day);
871             } else {
872                 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_night);
873             }
874         }
875
876         // Set the scroll app bar preference icon.
877         if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
878             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
879                 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
880             } else {
881                 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
882             }
883         } else {
884             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
885                 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
886             } else {
887                 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
888             }
889         }
890
891         // Set the display additional app bar icons preference icon.
892         if (sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false)) {
893             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
894                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
895             } else {
896                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
897             }
898         } else {
899             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
900                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
901             } else {
902                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
903             }
904         }
905
906         // Set the WebView theme preference icon.
907         switch (webViewThemeEntryNumber) {
908             case 0:  // The system default WebView theme is selected.
909                 // Set the icon according to the app theme.
910                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
911                     webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
912                 } else {
913                     webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
914                 }
915                 break;
916
917             case 1:  // The light WebView theme is selected.
918                 // Set the icon according to the app theme.
919                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
920                     webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
921                 } else {
922                     webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
923                 }
924                 break;
925
926             case 2:  // The dark WebView theme is selected.
927                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
928                     webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
929                 } else {
930                     webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
931                 }
932                 break;
933         }
934
935         // Set the wide viewport preference icon.
936         if (sharedPreferences.getBoolean("wide_viewport", true)) {
937             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
938                 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
939             } else {
940                 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
941             }
942         } else {
943             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
944                 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
945             } else {
946                 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
947             }
948         }
949
950         // Set the display webpage images preference icon.
951         if (sharedPreferences.getBoolean("display_webpage_images", true)) {
952             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
953                 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
954             } else {
955                 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
956             }
957         } else {
958             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
959                 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
960             } else {
961                 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
962             }
963         }
964
965         // Get the shared preferences change listener.
966         sharedPreferenceChangeListener = getSharedPreferencesChangeListener(requireContext());
967
968         // Register the listener.
969         sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
970     }
971
972     // The listener should be unregistered when the app is paused.
973     @Override
974     public void onPause() {
975         // Run the default commands.
976         super.onPause();
977
978         // Get a handle for the shared preferences.
979         SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
980
981         // Unregister the shared preferences listener.
982         sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
983     }
984
985     // The listener should be re-registered when the app is resumed.
986     @Override
987     public void onResume() {
988         // Run the default commands.
989         super.onResume();
990
991         // Get a new shared preferences change listener.
992         sharedPreferenceChangeListener = getSharedPreferencesChangeListener(requireContext());
993
994         // Get a handle for the shared preferences.
995         SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
996
997         // Re-register the shared preferences listener.
998         sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
999     }
1000
1001     // 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.
1002     private SharedPreferences.OnSharedPreferenceChangeListener getSharedPreferencesChangeListener(Context context) {
1003         // Return the shared preference change listener.
1004         return (SharedPreferences sharedPreferences, String key) -> {
1005             switch (key) {
1006                 case "javascript":
1007                     // Update the icons and the DOM storage preference status.
1008                     if (sharedPreferences.getBoolean("javascript", false)) {  // The JavaScript preference is enabled.
1009                         // Update the icon for the JavaScript preference.
1010                         javaScriptPreference.setIcon(R.drawable.javascript_enabled);
1011
1012                         // Update the status of the DOM storage preference.
1013                         domStoragePreference.setEnabled(true);
1014
1015                         // Update the icon for the DOM storage preference.
1016                         if (sharedPreferences.getBoolean("dom_storage", false)) {
1017                             domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
1018                         } else {
1019                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1020                                 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1021                             } else {
1022                                 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1023                             }
1024                         }
1025                     } else {  // The JavaScript preference is disabled.
1026                         // Update the icon for the JavaScript preference.
1027                         javaScriptPreference.setIcon(R.drawable.privacy_mode);
1028
1029                         // Update the status of the DOM storage preference.
1030                         domStoragePreference.setEnabled(false);
1031
1032                         // Set the icon for DOM storage preference to be ghosted.
1033                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1034                             domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
1035                         } else {
1036                             domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
1037                         }
1038                     }
1039                     break;
1040
1041                 case "cookies":
1042                     // Update the icon.
1043                     if (sharedPreferences.getBoolean(context.getString(R.string.cookies_key), false)) {
1044                         cookiesPreference.setIcon(R.drawable.cookies_enabled);
1045                     } else {
1046                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1047                             cookiesPreference.setIcon(R.drawable.cookies_disabled_day);
1048                         } else {
1049                             cookiesPreference.setIcon(R.drawable.cookies_disabled_night);
1050                         }
1051                     }
1052                     break;
1053
1054                 case "dom_storage":
1055                     // Update the icon.
1056                     if (sharedPreferences.getBoolean("dom_storage", false)) {
1057                         domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
1058                     } else {
1059                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1060                             domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1061                         } else {
1062                             domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1063                         }
1064                     }
1065                     break;
1066
1067                 // Save form data can be removed once the minimum API >= 26.
1068                 case "save_form_data":
1069                     // Update the icon.
1070                     if (sharedPreferences.getBoolean("save_form_data", false)) {
1071                         formDataPreference.setIcon(R.drawable.form_data_enabled);
1072                     } else {
1073                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1074                             formDataPreference.setIcon(R.drawable.form_data_disabled_day);
1075                         } else {
1076                             formDataPreference.setIcon(R.drawable.form_data_disabled_night);
1077                         }
1078                     }
1079                     break;
1080
1081                 case "user_agent":
1082                     // Get the new user agent name.
1083                     String newUserAgentName = sharedPreferences.getString("user_agent", context.getString(R.string.user_agent_default_value));
1084
1085                     // Get the array position for the new user agent name.
1086                     int newUserAgentArrayPosition = userAgentNamesArray.getPosition(newUserAgentName);
1087
1088                     // Get the translated new user agent name.
1089                     String translatedNewUserAgentName = translatedUserAgentNamesArray[newUserAgentArrayPosition];
1090
1091                     // Populate the user agent summary.
1092                     switch (newUserAgentArrayPosition) {
1093                         case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
1094                             // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
1095                             userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + defaultUserAgent);
1096
1097                             // Disable the custom user agent preference.
1098                             customUserAgentPreference.setEnabled(false);
1099
1100                             // Set the custom user agent preference icon according to the theme.
1101                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1102                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1103                             } else {
1104                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1105                             }
1106                             break;
1107
1108                         case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
1109                             // Set the summary text.
1110                             userAgentPreference.setSummary(R.string.custom_user_agent);
1111
1112                             // Enable the custom user agent preference.
1113                             customUserAgentPreference.setEnabled(true);
1114
1115                             // Set the custom user agent preference icon according to the theme.
1116                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1117                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
1118                             } else {
1119                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
1120                             }
1121                             break;
1122
1123                         default:
1124                             // Get the user agent summary from the user agent data array.
1125                             userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + userAgentDataArray[newUserAgentArrayPosition]);
1126
1127                             // Disable the custom user agent preference.
1128                             customUserAgentPreference.setEnabled(false);
1129
1130                             // Set the custom user agent preference icon according to the theme.
1131                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1132                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1133                             } else {
1134                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1135                             }
1136                     }
1137                     break;
1138
1139                 case "custom_user_agent":
1140                     // Set the new custom user agent as the summary text for the preference.
1141                     customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", context.getString(R.string.custom_user_agent_default_value)));
1142                     break;
1143
1144                 case "incognito_mode":
1145                     // Update the icon.
1146                     if (sharedPreferences.getBoolean("incognito_mode", false)) {
1147                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1148                             incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
1149                         } else {
1150                             incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
1151                         }
1152                     } else {
1153                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1154                             incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
1155                         } else {
1156                             incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
1157                         }
1158                     }
1159                     break;
1160
1161                 case "allow_screenshots":
1162                     // Update the icon.
1163                     if (sharedPreferences.getBoolean(context.getString(R.string.allow_screenshots_key), false)) {
1164                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1165                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
1166                         } else {
1167                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
1168                         }
1169                     } else {
1170                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1171                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
1172                         } else {
1173                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
1174                         }
1175                     }
1176
1177                     // Create an intent to restart Privacy Browser.
1178                     Intent allowScreenshotsRestartIntent = requireActivity().getParentActivityIntent();
1179
1180                     // Assert that the intent is not null to remove the lint error below.
1181                     assert allowScreenshotsRestartIntent != null;
1182
1183                     // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack.  It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
1184                     allowScreenshotsRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
1185
1186                     // Create a handler to restart the activity.
1187                     Handler allowScreenshotsRestartHandler = new Handler(Looper.getMainLooper());
1188
1189                     // Create a runnable to restart the activity.
1190                     Runnable allowScreenshotsRestartRunnable = () -> {
1191                         // Restart the activity.
1192                         startActivity(allowScreenshotsRestartIntent);
1193
1194                         // Kill this instance of Privacy Browser.  Otherwise, the app exhibits sporadic behavior after the restart.
1195                         System.exit(0);
1196                     };
1197
1198                     // Restart the activity after 150 milliseconds, so that the app has enough time to save the change to the preference.
1199                     allowScreenshotsRestartHandler.postDelayed(allowScreenshotsRestartRunnable, 150);
1200                     break;
1201
1202                 case "easylist":
1203                     // Update the icon.
1204                     if (sharedPreferences.getBoolean("easylist", true)) {
1205                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1206                             easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
1207                         } else {
1208                             easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
1209                         }
1210                     } else {
1211                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1212                             easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
1213                         } else {
1214                             easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
1215                         }
1216                     }
1217                     break;
1218
1219                 case "easyprivacy":
1220                     // Update the icon.
1221                     if (sharedPreferences.getBoolean("easyprivacy", true)) {
1222                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1223                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1224                         } else {
1225                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1226                         }
1227                     } else {
1228                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1229                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1230                         } else {
1231                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1232                         }
1233                     }
1234                     break;
1235
1236                 case "fanboys_annoyance_list":
1237                     boolean currentFanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
1238                     boolean currentFanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
1239
1240                     // Update the Fanboy icons.
1241                     if (currentFanboyAnnoyanceList) {  // Fanboy's annoyance list is enabled.
1242                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1243                             // Update the Fanboy's annoyance list icon.
1244                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
1245
1246                             // Update the Fanboy's social blocking list icon.
1247                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
1248                         } else {
1249                             // Update the Fanboy's annoyance list icon.
1250                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
1251
1252                             // Update the Fanboy's social blocking list icon.
1253                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
1254                         }
1255                     } else {  // Fanboy's annoyance list is disabled.
1256                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1257                             // Update the Fanboy's annoyance list icon.
1258                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
1259
1260                             // Update the Fanboy's social blocking list icon.
1261                             if (currentFanboySocialBlockingList) {
1262                                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1263                             } else {
1264                                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1265                             }
1266                         } else {
1267                             // Update the Fanboy's annoyance list icon.
1268                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_day);
1269
1270                             // Update the Fanboy's social blocking list icon.
1271                             if (currentFanboySocialBlockingList) {
1272                                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1273                             } else {
1274                                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1275                             }
1276                         }
1277                     }
1278
1279                     // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list preference is disabled.
1280                     fanboySocialBlockingListPreference.setEnabled(!currentFanboyAnnoyanceList);
1281                     break;
1282
1283                 case "fanboys_social_blocking_list":
1284                     // Update the icon.
1285                     if (sharedPreferences.getBoolean("fanboys_social_blocking_list", true)) {
1286                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1287                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1288                         } else {
1289                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1290                         }
1291                     } else {
1292                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1293                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1294                         } else {
1295                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1296                         }
1297                     }
1298                     break;
1299
1300                 case "ultralist":
1301                     // Update the icon.
1302                     if (sharedPreferences.getBoolean("ultralist", true)) {
1303                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1304                             ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
1305                         } else {
1306                             ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
1307                         }
1308                     } else {
1309                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1310                             ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
1311                         } else {
1312                             ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
1313                         }
1314                     }
1315                     break;
1316
1317                 case "ultraprivacy":
1318                     // Update the icon.
1319                     if (sharedPreferences.getBoolean("ultraprivacy", true)) {
1320                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1321                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1322                         } else {
1323                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1324                         }
1325                     } else {
1326                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1327                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1328                         } else {
1329                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1330                         }
1331                     }
1332                     break;
1333
1334                 case "block_all_third_party_requests":
1335                     // Update the icon.
1336                     if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
1337                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1338                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
1339                         } else {
1340                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
1341                         }
1342                     } else {
1343                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1344                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
1345                         } else {
1346                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
1347                         }
1348                     }
1349                     break;
1350
1351                 case "google_analytics":
1352                     // Update the icon.
1353                     if (sharedPreferences.getBoolean("google_analytics", true)) {
1354                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1355                             googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
1356                         } else {
1357                             googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
1358                         }
1359                     } else {
1360                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1361                             googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
1362                         } else {
1363                             googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
1364                         }
1365                     }
1366                     break;
1367
1368                 case "facebook_click_ids":
1369                     // Update the icon.
1370                     if (sharedPreferences.getBoolean("facebook_click_ids", true)) {
1371                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1372                             facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
1373                         } else {
1374                             facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
1375                         }
1376                     } else {
1377                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1378                             facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
1379                         } else {
1380                             facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
1381                         }
1382                     }
1383                     break;
1384
1385                 case "twitter_amp_redirects":
1386                     // Update the icon.
1387                     if (sharedPreferences.getBoolean("twitter_amp_redirects", true)) {
1388                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1389                             twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
1390                         } else {
1391                             twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
1392                         }
1393                     } else {
1394                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1395                             twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
1396                         } else {
1397                             twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
1398                         }
1399                     }
1400                     break;
1401
1402                 case "search":
1403                     // Store the new search string.
1404                     String newSearchString = sharedPreferences.getString("search", context.getString(R.string.search_default_value));
1405
1406                     // Update the search and search custom URL preferences.
1407                     if (newSearchString.equals("Custom URL")) {  // `Custom URL` is selected.
1408                         // Set the summary text to `R.string.custom_url`, which is translated.
1409                         searchPreference.setSummary(R.string.custom_url);
1410
1411                         // Enable `searchCustomURLPreference`.
1412                         searchCustomURLPreference.setEnabled(true);
1413
1414                         // Set the `searchCustomURLPreference` according to the theme.
1415                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1416                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
1417                         } else {
1418                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
1419                         }
1420                     } else {  // `Custom URL` is not selected.
1421                         // Set the summary text to `newSearchString`.
1422                         searchPreference.setSummary(newSearchString);
1423
1424                         // Disable `searchCustomURLPreference`.
1425                         searchCustomURLPreference.setEnabled(false);
1426
1427                         // Set the `searchCustomURLPreference` according to the theme.
1428                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1429                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
1430                         } else {
1431                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
1432                         }
1433                     }
1434                     break;
1435
1436                 case "search_custom_url":
1437                     // Set the new search custom URL as the summary text for the preference.
1438                     searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", context.getString(R.string.search_custom_url_default_value)));
1439                     break;
1440
1441                 case "proxy":
1442                     // Get current proxy string.
1443                     String currentProxyString = sharedPreferences.getString("proxy", context.getString(R.string.proxy_default_value));
1444
1445                     // Update the summary text for the proxy preference.
1446                     switch (currentProxyString) {
1447                         case ProxyHelper.NONE:
1448                             proxyPreference.setSummary(context.getString(R.string.no_proxy_enabled));
1449                             break;
1450
1451                         case ProxyHelper.TOR:
1452                             if (Build.VERSION.SDK_INT == 19) {  // Proxying through SOCKS doesn't work on Android KitKat.
1453                                 proxyPreference.setSummary(context.getString(R.string.tor_enabled_kitkat));
1454                             } else {
1455                                 proxyPreference.setSummary(context.getString(R.string.tor_enabled));
1456                             }
1457                             break;
1458
1459                         case ProxyHelper.I2P:
1460                             proxyPreference.setSummary(context.getString(R.string.i2p_enabled));
1461                             break;
1462
1463                         case ProxyHelper.CUSTOM:
1464                             proxyPreference.setSummary(context.getString(R.string.custom_proxy));
1465                             break;
1466                     }
1467
1468                     // Update the status of the custom URL preference.
1469                     proxyCustomUrlPreference.setEnabled(currentProxyString.equals("Custom"));
1470
1471                     // Update the icons.
1472                     if (currentProxyString.equals("None")) {  // Proxying is disabled.
1473                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {  // Dark theme.
1474                             // Set the main proxy icon to be disabled
1475                             proxyPreference.setIcon(R.drawable.proxy_disabled_night);
1476
1477                             // Set the custom proxy URL icon to be ghosted.
1478                             proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1479                         } else {  // Light theme.
1480                             // Set the main proxy icon to be disabled.
1481                             proxyPreference.setIcon(R.drawable.proxy_disabled_day);
1482
1483                             // Set the custom proxy URL icon to be ghosted.
1484                             proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1485                         }
1486                     } else {  // Proxying is enabled.
1487                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {  // Dark theme.
1488                             // Set the main proxy icon to be enabled.
1489                             proxyPreference.setIcon(R.drawable.proxy_enabled_night);
1490
1491                             /// Set the custom proxy URL icon according to its status.
1492                             if (proxyCustomUrlPreference.isEnabled()) {  // Custom proxy is enabled.
1493                                 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
1494                             } else {  // Custom proxy is disabled.
1495                                 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1496                             }
1497                         } else {  // Light theme.
1498                             // Set the main proxy icon to be enabled.
1499                             proxyPreference.setIcon(R.drawable.proxy_enabled_day);
1500
1501                             // Set the custom proxy URL icon according to its status.
1502                             if (proxyCustomUrlPreference.isEnabled()) {  // Custom proxy is enabled.
1503                                 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
1504                             } else {  // Custom proxy is disabled.
1505                                 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1506                             }
1507                         }
1508                     }
1509                     break;
1510
1511                 case "proxy_custom_url":
1512                     // Set the summary text for the proxy custom URL.
1513                     proxyCustomUrlPreference.setSummary(sharedPreferences.getString("proxy_custom_url", context.getString(R.string.proxy_custom_url_default_value)));
1514                     break;
1515
1516                 case "full_screen_browsing_mode":
1517                     if (sharedPreferences.getBoolean("full_screen_browsing_mode", false)) {  // Full screen browsing is enabled.
1518                         // Set the full screen browsing mode preference icon according to the theme.
1519                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1520                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
1521                         } else {
1522                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
1523                         }
1524
1525                         // Set the hide app bar preference icon.
1526                         if (sharedPreferences.getBoolean("hide_app_bar", true)) {  //  Hide app bar is enabled.
1527                             // Set the icon according to the theme.
1528                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1529                                 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1530                             } else {
1531                                 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1532                             }
1533                         } else {  // Hide app bar is disabled.
1534                             // Set the icon according to the theme.
1535                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1536                                 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1537                             } else {
1538                                 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1539                             }
1540                         }
1541                     } else {  // Full screen browsing is disabled.
1542                         // Update the icons according to the theme.
1543                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1544                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
1545                             hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
1546                         } else {
1547                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
1548                             hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
1549                         }
1550                     }
1551                     break;
1552
1553                 case "hide_app_bar":
1554                     // Update the icon.
1555                     if (sharedPreferences.getBoolean("hide_app_bar", true)) {  // Hide app bar is enabled.
1556                         // Set the icon according to the theme.
1557                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1558                             hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1559                         } else {
1560                             hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1561                         }
1562                     } else {  // Hide app bar is disabled.
1563                         // Set the icon according to the theme.
1564                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1565                             hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1566                         } else {
1567                             hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1568                         }
1569                     }
1570                     break;
1571
1572                 case "clear_everything":
1573                     // Store the new clear everything status
1574                     boolean newClearEverythingBoolean = sharedPreferences.getBoolean("clear_everything", true);
1575
1576                     // Update the status of the clear and exit preferences.
1577                     clearCookiesPreference.setEnabled(!newClearEverythingBoolean);
1578                     clearDomStoragePreference.setEnabled(!newClearEverythingBoolean);
1579                     clearFormDataPreference.setEnabled(!newClearEverythingBoolean);  // This line can be removed once the minimum API >= 26.
1580                     clearLogcatPreference.setEnabled(!newClearEverythingBoolean);
1581                     clearCachePreference.setEnabled(!newClearEverythingBoolean);
1582
1583                     // Update the clear everything preference icon.
1584                     if (newClearEverythingBoolean) {
1585                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1586                             clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
1587                         } else {
1588                             clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
1589                         }
1590                     } else {
1591                         clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
1592                     }
1593
1594                     // Update the clear cookies preference icon.
1595                     if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) {
1596                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1597                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1598                         } else {
1599                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1600                         }
1601                     } else {
1602                         clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1603                     }
1604
1605                     // Update the clear dom storage preference icon.
1606                     if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) {
1607                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1608                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1609                         } else {
1610                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1611                         }
1612                     } else {
1613                         clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1614                     }
1615
1616                     // Update the clear form data preference icon if the API < 26.
1617                     if (Build.VERSION.SDK_INT < 26) {
1618                         if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) {
1619                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1620                                 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1621                             } else {
1622                                 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1623                             }
1624                         } else {
1625                             clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1626                         }
1627                     }
1628
1629                     // Update the clear logcat preference icon.
1630                     if (newClearEverythingBoolean || sharedPreferences.getBoolean(context.getString(R.string.clear_logcat_key), true)) {
1631                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1632                             clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
1633                         } else {
1634                             clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1635                         }
1636                     } else {
1637                         clearLogcatPreference.setIcon(R.drawable.cache_warning);
1638                     }
1639
1640                     // Update the clear cache preference icon.
1641                     if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) {
1642                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1643                             clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1644                         } else {
1645                             clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1646                         }
1647                     } else {
1648                         clearCachePreference.setIcon(R.drawable.cache_warning);
1649                     }
1650                     break;
1651
1652                 case "clear_cookies":
1653                     // Update the icon.
1654                     if (sharedPreferences.getBoolean("clear_cookies", true)) {
1655                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1656                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1657                         } else {
1658                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1659                         }
1660                     } else {
1661                         clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1662                     }
1663                     break;
1664
1665                 case "clear_dom_storage":
1666                     // Update the icon.
1667                     if (sharedPreferences.getBoolean("clear_dom_storage", true)) {
1668                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1669                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1670                         } else {
1671                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1672                         }
1673                     } else {
1674                         clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1675                     }
1676                     break;
1677
1678                 // This section can be removed once the minimum API >= 26.
1679                 case "clear_form_data":
1680                     // Update the icon.
1681                     if (sharedPreferences.getBoolean("clear_form_data", true)) {
1682                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1683                             clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1684                         } else {
1685                             clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1686                         }
1687                     } else {
1688                         clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1689                     }
1690                     break;
1691
1692                 case "clear_logcat":
1693                     // Update the icon.
1694                     if (sharedPreferences.getBoolean(context.getString(R.string.clear_logcat_key), true)) {
1695                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1696                             clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
1697                         } else {
1698                             clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1699                         }
1700                     } else {
1701                         clearLogcatPreference.setIcon(R.drawable.bug_warning);
1702                     }
1703                     break;
1704
1705                 case "clear_cache":
1706                     // Update the icon.
1707                     if (sharedPreferences.getBoolean("clear_cache", true)) {
1708                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1709                             clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1710                         } else {
1711                             clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1712                         }
1713                     } else {
1714                         clearCachePreference.setIcon(R.drawable.cache_warning);
1715                     }
1716                     break;
1717
1718                 case "homepage":
1719                     // Set the new homepage URL as the summary text for the Homepage preference.
1720                     homepagePreference.setSummary(sharedPreferences.getString("homepage", context.getString(R.string.homepage_default_value)));
1721                     break;
1722
1723                 case "font_size":
1724                     // Update the font size summary text.
1725                     fontSizePreference.setSummary(sharedPreferences.getString("font_size", context.getString(R.string.font_size_default_value)) + "%");
1726                     break;
1727
1728                 case "open_intents_in_new_tab":
1729                     // Update the icon.
1730                     if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
1731                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1732                             openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
1733                         } else {
1734                             openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
1735                         }
1736                     } else {
1737                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1738                             openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
1739                         } else {
1740                             openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
1741                         }
1742                     }
1743                     break;
1744
1745                 case "swipe_to_refresh":
1746                     // Update the icon.
1747                     if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
1748                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1749                             swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
1750                         } else {
1751                             swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
1752                         }
1753                     } else {
1754                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1755                             swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
1756                         } else {
1757                             swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
1758                         }
1759                     }
1760                     break;
1761
1762                 case "download_with_external_app":
1763                     // Update the icon.
1764                     if (sharedPreferences.getBoolean(context.getString(R.string.download_with_external_app_key), false)) {
1765                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1766                             downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_day);
1767                         } else {
1768                             downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_night);
1769                         }
1770                     } else {
1771                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1772                             downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_day);
1773                         } else {
1774                             downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_night);
1775                         }
1776                     }
1777                     break;
1778
1779                 case "scroll_app_bar":
1780                     // Update the icon.
1781                     if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
1782                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1783                             scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1784                         } else {
1785                             scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1786                         }
1787                     } else {
1788                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1789                             scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1790                         } else {
1791                             scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1792                         }
1793                     }
1794                     break;
1795
1796                 case "display_additional_app_bar_icons":
1797                     // Update the icon.
1798                     if (sharedPreferences.getBoolean(context.getString(R.string.display_additional_app_bar_icons_key), false)) {
1799                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1800                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
1801                         } else {
1802                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
1803                         }
1804                     } else {
1805                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1806                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
1807                         } else {
1808                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
1809                         }
1810                     }
1811                     break;
1812
1813                 case "app_theme":
1814                     // Get the new theme.
1815                     String newAppTheme = sharedPreferences.getString("app_theme", context.getString(R.string.app_theme_default_value));
1816
1817                     // Update the system according to the new theme.  A switch statement cannot be used because the theme entry values string array is not a compile time constant.
1818                     if (newAppTheme.equals(appThemeEntryValuesStringArray[1])) {  // The light theme is selected.
1819                         // Update the theme preference summary text.
1820                         appThemePreference.setSummary(appThemeEntriesStringArray[1]);
1821
1822                         // Apply the new theme.
1823                         AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
1824                     } else if (newAppTheme.equals(appThemeEntryValuesStringArray[2])) {  // The dark theme is selected.
1825                         // Update the theme preference summary text.
1826                         appThemePreference.setSummary(appThemeEntriesStringArray[2]);
1827
1828                         // Apply the new theme.
1829                         AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
1830                     } else {  // The system default theme is selected.
1831                         // Update the theme preference summary text.
1832                         appThemePreference.setSummary(appThemeEntriesStringArray[0]);
1833
1834                         // Apply the new theme.
1835                         if (Build.VERSION.SDK_INT >= 28) {  // The system default theme is supported.
1836                             // Follow the system default theme.
1837                             AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
1838                         } else {// The system default theme is not supported.
1839                             // Follow the battery saver mode.
1840                             AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
1841                         }
1842                     }
1843
1844                     // Update the current theme status.
1845                     currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
1846                     break;
1847
1848                 case "webview_theme":
1849                     // Get the new WebView theme.
1850                     String newWebViewTheme = sharedPreferences.getString("webview_theme", context.getString(R.string.webview_theme_default_value));
1851
1852                     // Define a new WebView theme entry number.
1853                     int newWebViewThemeEntryNumber;
1854
1855                     // Get the webView theme entry number that matches the new WebView theme.  A switch statement cannot be used because the theme entry values string array is not a compile time constant.
1856                     if (newWebViewTheme.equals(webViewThemeEntriesStringArray[1])) {  // The light theme is selected.
1857                         // Store the new WebView theme entry number.
1858                         newWebViewThemeEntryNumber = 1;
1859                     } else if (newWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) {  // The dark theme is selected.
1860                         // Store the WebView theme entry number.
1861                         newWebViewThemeEntryNumber = 2;
1862                     } else {  // The system default theme is selected.
1863                         // Store the WebView theme entry number.
1864                         newWebViewThemeEntryNumber = 0;
1865                     }
1866
1867                     // Update the icon.
1868                     switch (newWebViewThemeEntryNumber) {
1869                         case 0:  // The system default WebView theme is selected.
1870                             // Set the icon according to the app theme.
1871                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1872                                 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
1873                             } else {
1874                                 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1875                             }
1876                             break;
1877
1878                         case 1:  // The system default WebView theme is selected.
1879                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1880                                 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
1881                             } else {
1882                                 webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
1883                             }
1884                             break;
1885
1886                         case 2:  // The system default WebView theme is selected.
1887                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1888                                 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
1889                             } else {
1890                                 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1891                             }
1892                             break;
1893                     }
1894
1895                     // Set the current theme as the summary text for the preference.
1896                     webViewThemePreference.setSummary(webViewThemeEntriesStringArray[newWebViewThemeEntryNumber]);
1897                     break;
1898
1899                 case "wide_viewport":
1900                     // Update the icon.
1901                     if (sharedPreferences.getBoolean("wide_viewport", true)) {
1902                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1903                             wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
1904                         } else {
1905                             wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
1906                         }
1907                     } else {
1908                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1909                             wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
1910                         } else {
1911                             wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
1912                         }
1913                     }
1914                     break;
1915
1916                 case "display_webpage_images":
1917                     // Update the icon.
1918                     if (sharedPreferences.getBoolean("display_webpage_images", true)) {
1919                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1920                             displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
1921                         } else {
1922                             displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
1923                         }
1924                     } else {
1925                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1926                             displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
1927                         } else {
1928                             displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
1929                         }
1930                     }
1931                     break;
1932             }
1933         };
1934     }
1935 }