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