X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Ffragments%2FSettingsFragment.java;h=486a70534d99d542f5e443b04269e597624f748d;hb=bc976a00a37730c5bb863eed888b88043769ddaa;hp=75f9b31d903b0f0058dbd539f91d0d4796150bb4;hpb=27e33047e14466c84212bca02a14a7fc4ff15af8;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java index 75f9b31d..486a7053 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2020 Soren Stoutner . + * Copyright © 2016-2021 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -29,6 +29,7 @@ import android.content.res.Resources; import android.os.Build; import android.os.Bundle; import android.os.Handler; +import android.os.Looper; import android.view.LayoutInflater; import android.view.View; import android.webkit.WebView; @@ -41,7 +42,6 @@ import androidx.preference.PreferenceFragmentCompat; import com.stoutner.privacybrowser.R; import com.stoutner.privacybrowser.activities.MainWebViewActivity; -import com.stoutner.privacybrowser.helpers.DownloadLocationHelper; import com.stoutner.privacybrowser.helpers.ProxyHelper; public class SettingsFragment extends PreferenceFragmentCompat { @@ -73,15 +73,13 @@ public class SettingsFragment extends PreferenceFragmentCompat { // Get handles for the preferences. Preference javaScriptPreference = findPreference("javascript"); - Preference firstPartyCookiesPreference = findPreference("first_party_cookies"); - Preference thirdPartyCookiesPreference = findPreference("third_party_cookies"); + Preference cookiesPreference = findPreference(getString(R.string.cookies_key)); Preference domStoragePreference = findPreference("dom_storage"); Preference formDataPreference = findPreference("save_form_data"); // The form data preference can be removed once the minimum API >= 26. Preference userAgentPreference = findPreference("user_agent"); Preference customUserAgentPreference = findPreference("custom_user_agent"); Preference incognitoModePreference = findPreference("incognito_mode"); - Preference doNotTrackPreference = findPreference("do_not_track"); - Preference allowScreenshotsPreference = findPreference("allow_screenshots"); + Preference allowScreenshotsPreference = findPreference(getString(R.string.allow_screenshots_key)); Preference easyListPreference = findPreference("easylist"); Preference easyPrivacyPreference = findPreference("easyprivacy"); Preference fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list"); @@ -102,30 +100,27 @@ public class SettingsFragment extends PreferenceFragmentCompat { Preference clearCookiesPreference = findPreference("clear_cookies"); Preference clearDomStoragePreference = findPreference("clear_dom_storage"); Preference clearFormDataPreference = findPreference("clear_form_data"); // The clear form data preference can be removed once the minimum API >= 26. + Preference clearLogcatPreference = findPreference(getString(R.string.clear_logcat_key)); Preference clearCachePreference = findPreference("clear_cache"); Preference homepagePreference = findPreference("homepage"); - Preference downloadLocationPreference = findPreference("download_location"); - Preference downloadCustomLocationPreference = findPreference("download_custom_location"); Preference fontSizePreference = findPreference("font_size"); Preference openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab"); Preference swipeToRefreshPreference = findPreference("swipe_to_refresh"); Preference scrollAppBarPreference = findPreference("scroll_app_bar"); Preference displayAdditionalAppBarIconsPreference = findPreference("display_additional_app_bar_icons"); Preference appThemePreference = findPreference("app_theme"); - Preference nightModePreference = findPreference("night_mode"); + Preference webViewThemePreference = findPreference("webview_theme"); Preference wideViewportPreference = findPreference("wide_viewport"); Preference displayWebpageImagesPreference = findPreference("display_webpage_images"); // Remove the lint warnings below that the preferences might be null. assert javaScriptPreference != null; - assert firstPartyCookiesPreference != null; - assert thirdPartyCookiesPreference != null; + assert cookiesPreference != null; assert domStoragePreference != null; assert formDataPreference != null; assert userAgentPreference != null; assert customUserAgentPreference != null; assert incognitoModePreference != null; - assert doNotTrackPreference != null; assert allowScreenshotsPreference != null; assert easyListPreference != null; assert easyPrivacyPreference != null; @@ -147,52 +142,42 @@ public class SettingsFragment extends PreferenceFragmentCompat { assert clearCookiesPreference != null; assert clearDomStoragePreference != null; assert clearFormDataPreference != null; + assert clearLogcatPreference != null; assert clearCachePreference != null; assert homepagePreference != null; - assert downloadLocationPreference != null; - assert downloadCustomLocationPreference != null; assert fontSizePreference != null; assert openIntentsInNewTabPreference != null; assert swipeToRefreshPreference != null; assert scrollAppBarPreference != null; assert displayAdditionalAppBarIconsPreference != null; assert appThemePreference != null; - assert nightModePreference != null; + assert webViewThemePreference != null; assert wideViewportPreference != null; assert displayWebpageImagesPreference != null; - // Set the hide app bar preference dependency. + // Set the preference dependencies. hideAppBarPreference.setDependency("full_screen_browsing_mode"); + domStoragePreference.setDependency("javascript"); // Get strings from the preferences. String userAgentName = savedPreferences.getString("user_agent", getString(R.string.user_agent_default_value)); String searchString = savedPreferences.getString("search", getString(R.string.search_default_value)); String proxyString = savedPreferences.getString("proxy", getString(R.string.proxy_default_value)); - String downloadLocationString = savedPreferences.getString("download_location", getString(R.string.download_location_default_value)); // Get booleans that are used in multiple places from the preferences. boolean javaScriptEnabled = savedPreferences.getBoolean("javascript", false); - boolean firstPartyCookiesEnabled = savedPreferences.getBoolean("first_party_cookies", false); - boolean thirdPartyCookiesEnabled = savedPreferences.getBoolean("third_party_cookies", false); boolean fanboyAnnoyanceListEnabled = savedPreferences.getBoolean("fanboys_annoyance_list", true); boolean fanboySocialBlockingEnabled = savedPreferences.getBoolean("fanboys_social_blocking_list", true); boolean fullScreenBrowsingMode = savedPreferences.getBoolean("full_screen_browsing_mode", false); boolean clearEverything = savedPreferences.getBoolean("clear_everything", true); - boolean nightMode = savedPreferences.getBoolean("night_mode", false); - - // Only enable the third-party cookies preference if first-party cookies are enabled and API >= 21. - thirdPartyCookiesPreference.setEnabled(firstPartyCookiesEnabled && (Build.VERSION.SDK_INT >= 21)); - - // Only enable the DOM storage preference if either JavaScript or Night Mode is enabled. - domStoragePreference.setEnabled(javaScriptEnabled || nightMode); // Remove the form data preferences if the API is >= 26 as they no longer do anything. if (Build.VERSION.SDK_INT >= 26) { - // Get the categories. + // Get handles for the categories. PreferenceCategory privacyCategory = findPreference("privacy"); PreferenceCategory clearAndExitCategory = findPreference("clear_and_exit"); - // Remove the lint warnings below that the preference categories might be null. + // Remove the incorrect lint warnings below that the preference categories might be null. assert privacyCategory != null; assert clearAndExitCategory != null; @@ -297,10 +282,11 @@ public class SettingsFragment extends PreferenceFragmentCompat { proxyCustomUrlPreference.setEnabled(proxyString.equals("Custom")); - // Set the status of the Clear and Exit preferences. + // Set the status of the clear and exit preferences. clearCookiesPreference.setEnabled(!clearEverything); clearDomStoragePreference.setEnabled(!clearEverything); clearFormDataPreference.setEnabled(!clearEverything); // The form data line can be removed once the minimum API is >= 26. + clearLogcatPreference.setEnabled(!clearEverything); clearCachePreference.setEnabled(!clearEverything); @@ -308,49 +294,29 @@ public class SettingsFragment extends PreferenceFragmentCompat { homepagePreference.setSummary(savedPreferences.getString("homepage", getString(R.string.homepage_default_value))); - // Get the download location string arrays. - String[] downloadLocationEntriesStringArray = resources.getStringArray(R.array.download_location_entries); - String[] downloadLocationEntryValuesStringArray = resources.getStringArray(R.array.download_location_entry_values); - - // Instantiate the download location helper. - DownloadLocationHelper downloadLocationHelper = new DownloadLocationHelper(); - - // Check to see if a download custom location is selected. - if (downloadLocationString.equals(downloadLocationEntryValuesStringArray[3])) { // A download custom location is selected. - // Set the download location summary text to be `Custom`. - downloadLocationPreference.setSummary(downloadLocationEntriesStringArray[3]); - } else { // A custom download location is not selected. - // Set the download location summary text to be the download location. - downloadLocationPreference.setSummary(downloadLocationHelper.getDownloadLocation(context)); - - // Disable the download custom location preference. - downloadCustomLocationPreference.setEnabled(false); - } - - // Set the summary text for the download custom location (the default is `"`). - downloadCustomLocationPreference.setSummary(savedPreferences.getString("download_custom_location", getString(R.string.download_custom_location_default_value))); - - // Set the font size as the summary text for the preference. fontSizePreference.setSummary(savedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%"); - // Get the theme string arrays. + // Get the app theme string arrays. String[] appThemeEntriesStringArray = resources.getStringArray(R.array.app_theme_entries); String[] appThemeEntryValuesStringArray = resources.getStringArray(R.array.app_theme_entry_values); - // Get the current theme. + // Get the current app theme. String currentAppTheme = savedPreferences.getString("app_theme", getString(R.string.app_theme_default_value)); - // Define a theme entry number. + // Define an app theme entry number. int appThemeEntryNumber; - // Get the theme entry number that matches the current theme. A switch statement cannot be used because the theme entry values string array is not a compile time constant. + // 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. if (currentAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected. + // Store the app theme entry number. appThemeEntryNumber = 1; } else if (currentAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected. + // Store the app theme entry number. appThemeEntryNumber = 2; } else { // The system default theme is selected. + // Store the app theme entry number. appThemeEntryNumber = 0; } @@ -358,62 +324,78 @@ public class SettingsFragment extends PreferenceFragmentCompat { appThemePreference.setSummary(appThemeEntriesStringArray[appThemeEntryNumber]); - // Disable the JavaScript preference if Night Mode is enabled. JavaScript will be enabled for all web pages. - javaScriptPreference.setEnabled(!nightMode); + // Get the WebView theme string arrays. + String[] webViewThemeEntriesStringArray = resources.getStringArray(R.array.webview_theme_entries); + String[] webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values); + + // Get the current WebView theme. + String currentWebViewTheme = savedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value)); + + // Define a WebView theme entry number. + int webViewThemeEntryNumber; + + // 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. + if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[1])) { // The light theme is selected. + // Store the WebView theme entry number. + webViewThemeEntryNumber = 1; + } else if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected. + // Store the WebView theme entry number. + webViewThemeEntryNumber = 2; + } else { // The system default theme is selected. + // Store the WebView theme entry number. + webViewThemeEntryNumber = 0; + } + + // Set the visibility of the WebView theme preference. + if (Build.VERSION.SDK_INT < 21) { // The device is running API 19. + // Get a handle for the general category. + PreferenceCategory generalCategory = findPreference("general"); + + // Remove the incorrect lint warning below that the general preference category might be null. + assert generalCategory != null; + + // Remove the WebView theme preference. + generalCategory.removePreference(webViewThemePreference); + } else { // The device is running API >= 21 + // Set the current theme as the summary text for the preference. + webViewThemePreference.setSummary(webViewThemeEntriesStringArray[webViewThemeEntryNumber]); + } + // Set the JavaScript icon. - if (javaScriptEnabled || nightMode) { + if (javaScriptEnabled) { javaScriptPreference.setIcon(R.drawable.javascript_enabled); } else { javaScriptPreference.setIcon(R.drawable.privacy_mode); } - // Set the first-party cookies icon. - if (firstPartyCookiesEnabled) { - firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled); - } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night); - } else { - firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day); - } - } - - // Set the third party cookies icon. - if (firstPartyCookiesEnabled && Build.VERSION.SDK_INT >= 21) { - if (thirdPartyCookiesEnabled) { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning); - } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night); - } else { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day); - } - } + // Set the cookies icon. + if (savedPreferences.getBoolean(getString(R.string.cookies_key), false)) { + cookiesPreference.setIcon(R.drawable.cookies_enabled); } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + cookiesPreference.setIcon(R.drawable.cookies_disabled_day); } else { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day); + cookiesPreference.setIcon(R.drawable.cookies_disabled_night); } } // Set the DOM storage icon. - if (javaScriptEnabled || nightMode) { // The preference is enabled. + if (javaScriptEnabled) { // The preference is enabled. if (savedPreferences.getBoolean("dom_storage", false)) { // DOM storage is enabled. domStoragePreference.setIcon(R.drawable.dom_storage_enabled); } else { // DOM storage is disabled. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day); + } else { + domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night); } } } else { // The preference is disabled. The icon should be ghosted. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day); + } else { + domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night); } } @@ -422,26 +404,26 @@ public class SettingsFragment extends PreferenceFragmentCompat { if (savedPreferences.getBoolean("save_form_data", false)) { formDataPreference.setIcon(R.drawable.form_data_enabled); } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - formDataPreference.setIcon(R.drawable.form_data_disabled_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { formDataPreference.setIcon(R.drawable.form_data_disabled_day); + } else { + formDataPreference.setIcon(R.drawable.form_data_disabled_night); } } } // Set the custom user agent icon. if (customUserAgentPreference.isEnabled()) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day); + } else { + customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night); } } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day); + } else { + customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night); } } @@ -460,33 +442,18 @@ public class SettingsFragment extends PreferenceFragmentCompat { } } - // Set the Do Not Track icon. - if (savedPreferences.getBoolean("do_not_track", false)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_night); - } else { - doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_day); - } - } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_night); - } else { - doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_day); - } - } - // Set the allow screenshots icon. - if (savedPreferences.getBoolean("allow_screenshots", false)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night); - } else { + if (savedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day); + } else { + allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night); } } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day); + } else { + allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night); } } @@ -741,10 +708,10 @@ public class SettingsFragment extends PreferenceFragmentCompat { // Set the clear everything preference icon. if (clearEverything) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day); + } else { + clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night); } } else { clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled); @@ -752,10 +719,10 @@ public class SettingsFragment extends PreferenceFragmentCompat { // Set the clear cookies preference icon. if (clearEverything || savedPreferences.getBoolean("clear_cookies", true)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day); + } else { + clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night); } } else { clearCookiesPreference.setIcon(R.drawable.cookies_warning); @@ -785,30 +752,26 @@ public class SettingsFragment extends PreferenceFragmentCompat { } } - // Set the clear cache preference icon. - if (clearEverything || savedPreferences.getBoolean("clear_cache", true)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - clearCachePreference.setIcon(R.drawable.cache_cleared_night); + // Set the clear logcat preference icon. + if (clearEverything || savedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + clearLogcatPreference.setIcon(R.drawable.bug_cleared_day); } else { - clearCachePreference.setIcon(R.drawable.cache_cleared_day); + clearLogcatPreference.setIcon(R.drawable.bug_cleared_night); } } else { - clearCachePreference.setIcon(R.drawable.cache_warning); + clearLogcatPreference.setIcon(R.drawable.bug_warning); } - // Set the download custom location icon. - if (downloadCustomLocationPreference.isEnabled()) { + // Set the clear cache preference icon. + if (clearEverything || savedPreferences.getBoolean("clear_cache", true)) { if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_night); + clearCachePreference.setIcon(R.drawable.cache_cleared_night); } else { - downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_day); + clearCachePreference.setIcon(R.drawable.cache_cleared_day); } } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_night); - } else { - downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_day); - } + clearCachePreference.setIcon(R.drawable.cache_warning); } // Set the open intents in new tab preference icon. @@ -871,19 +834,33 @@ public class SettingsFragment extends PreferenceFragmentCompat { } } - // Set the night mode preference icon. - if (nightMode) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - nightModePreference.setIcon(R.drawable.night_mode_enabled_night); - } else { - nightModePreference.setIcon(R.drawable.night_mode_enabled_day); - } - } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - nightModePreference.setIcon(R.drawable.night_mode_disabled_night); - } else { - nightModePreference.setIcon(R.drawable.night_mode_disabled_day); - } + // Set the WebView theme preference icon. + switch (webViewThemeEntryNumber) { + case 0: // The system default WebView theme is selected. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemePreference.setIcon(R.drawable.webview_light_theme_day); + } else { + webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night); + } + break; + + case 1: // The light WebView theme is selected. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemePreference.setIcon(R.drawable.webview_light_theme_day); + } else { + webViewThemePreference.setIcon(R.drawable.webview_light_theme_night); + } + break; + + case 2: // The dark WebView theme is selected. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day); + } else { + webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night); + } + break; } // Set the wide viewport preference icon. @@ -933,10 +910,10 @@ public class SettingsFragment extends PreferenceFragmentCompat { if (sharedPreferences.getBoolean("dom_storage", false)) { domStoragePreference.setIcon(R.drawable.dom_storage_enabled); } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day); + } else { + domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night); } } } else { // The JavaScript preference is disabled. @@ -947,67 +924,23 @@ public class SettingsFragment extends PreferenceFragmentCompat { domStoragePreference.setEnabled(false); // Set the icon for DOM storage preference to be ghosted. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day); - } - } - break; - - case "first_party_cookies": - // Update the icons for `first_party_cookies` and `third_party_cookies`. - if (sharedPreferences.getBoolean("first_party_cookies", false)) { - // Set the icon for `first_party_cookies`. - firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled); - - // Update the icon for `third_party_cookies`. - if (Build.VERSION.SDK_INT >= 21) { - if (sharedPreferences.getBoolean("third_party_cookies", false)) { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning); - } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night); - } else { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day); - } - } - } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night); - } else { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day); - } - } - } else { // `first_party_cookies` is `false`. - // Update the icon for `first_party_cookies`. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night); - } else { - firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day); - } - - // Set the icon for `third_party_cookies` to be ghosted. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night); } else { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day); + domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night); } } - - // Enable `third_party_cookies` if `first_party_cookies` is `true` and API >= 21. - thirdPartyCookiesPreference.setEnabled(sharedPreferences.getBoolean("first_party_cookies", false) && (Build.VERSION.SDK_INT >= 21)); break; - case "third_party_cookies": + case "cookies": // Update the icon. - if (sharedPreferences.getBoolean("third_party_cookies", false)) { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning); + if (sharedPreferences.getBoolean(getString(R.string.cookies_key), false)) { + cookiesPreference.setIcon(R.drawable.cookies_enabled); } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + cookiesPreference.setIcon(R.drawable.cookies_disabled_day); } else { - thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day); + cookiesPreference.setIcon(R.drawable.cookies_disabled_night); } } break; @@ -1017,10 +950,10 @@ public class SettingsFragment extends PreferenceFragmentCompat { if (sharedPreferences.getBoolean("dom_storage", false)) { domStoragePreference.setIcon(R.drawable.dom_storage_enabled); } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day); + } else { + domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night); } } break; @@ -1031,10 +964,10 @@ public class SettingsFragment extends PreferenceFragmentCompat { if (sharedPreferences.getBoolean("save_form_data", false)) { formDataPreference.setIcon(R.drawable.form_data_enabled); } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - formDataPreference.setIcon(R.drawable.form_data_disabled_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { formDataPreference.setIcon(R.drawable.form_data_disabled_day); + } else { + formDataPreference.setIcon(R.drawable.form_data_disabled_night); } } break; @@ -1119,37 +1052,19 @@ public class SettingsFragment extends PreferenceFragmentCompat { } break; - case "do_not_track": - // Update the icon. - if (sharedPreferences.getBoolean("do_not_track", false)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_night); - } else { - doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_day); - } - } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_night); - } else { - doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_day); - } - } - - break; - case "allow_screenshots": // Update the icon. - if (sharedPreferences.getBoolean("allow_screenshots", false)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night); - } else { + if (sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day); + } else { + allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night); } } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day); + } else { + allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night); } } @@ -1163,7 +1078,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { allowScreenshotsRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // Create a handler to restart the activity. - Handler allowScreenshotsRestartHandler = new Handler(); + Handler allowScreenshotsRestartHandler = new Handler(Looper.getMainLooper()); // Create a runnable to restart the activity. Runnable allowScreenshotsRestartRunnable = () -> { @@ -1549,43 +1464,44 @@ public class SettingsFragment extends PreferenceFragmentCompat { break; case "clear_everything": - // Store the new `clear_everything` status + // Store the new clear everything status boolean newClearEverythingBoolean = sharedPreferences.getBoolean("clear_everything", true); - // Update the status of the `Clear and Exit` preferences. + // Update the status of the clear and exit preferences. clearCookiesPreference.setEnabled(!newClearEverythingBoolean); clearDomStoragePreference.setEnabled(!newClearEverythingBoolean); clearFormDataPreference.setEnabled(!newClearEverythingBoolean); // This line can be removed once the minimum API >= 26. + clearLogcatPreference.setEnabled(!newClearEverythingBoolean); clearCachePreference.setEnabled(!newClearEverythingBoolean); - // Update the `clearEverythingPreference` icon. + // Update the clear everything preference icon. if (newClearEverythingBoolean) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day); + } else { + clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night); } } else { clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled); } - // Update the `clearCookiesPreference` icon. + // Update the clear cookies preference icon. if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day); + } else { + clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night); } } else { clearCookiesPreference.setIcon(R.drawable.cookies_warning); } - // Update the `clearDomStoragePreference` icon. + // Update the clear dom storage preference icon. if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day); + } else { + clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night); } } else { clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning); @@ -1594,22 +1510,33 @@ public class SettingsFragment extends PreferenceFragmentCompat { // Update the clear form data preference icon if the API < 26. if (Build.VERSION.SDK_INT < 26) { if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day); + } else { + clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night); } } else { clearFormDataPreference.setIcon(R.drawable.form_data_warning); } } - // Update the `clearCachePreference` icon. - if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - clearCachePreference.setIcon(R.drawable.cache_cleared_night); + // Update the clear logcat preference icon. + if (newClearEverythingBoolean || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + clearLogcatPreference.setIcon(R.drawable.bug_cleared_day); } else { + clearLogcatPreference.setIcon(R.drawable.bug_cleared_night); + } + } else { + clearLogcatPreference.setIcon(R.drawable.cache_warning); + } + + // Update the clear cache preference icon. + if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { clearCachePreference.setIcon(R.drawable.cache_cleared_day); + } else { + clearCachePreference.setIcon(R.drawable.cache_cleared_night); } } else { clearCachePreference.setIcon(R.drawable.cache_warning); @@ -1619,10 +1546,10 @@ public class SettingsFragment extends PreferenceFragmentCompat { case "clear_cookies": // Update the icon. if (sharedPreferences.getBoolean("clear_cookies", true)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day); + } else { + clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night); } } else { clearCookiesPreference.setIcon(R.drawable.cookies_warning); @@ -1632,10 +1559,10 @@ public class SettingsFragment extends PreferenceFragmentCompat { case "clear_dom_storage": // Update the icon. if (sharedPreferences.getBoolean("clear_dom_storage", true)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day); + } else { + clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night); } } else { clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning); @@ -1646,72 +1573,45 @@ public class SettingsFragment extends PreferenceFragmentCompat { case "clear_form_data": // Update the icon. if (sharedPreferences.getBoolean("clear_form_data", true)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day); + } else { + clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night); } } else { clearFormDataPreference.setIcon(R.drawable.form_data_warning); } break; - case "clear_cache": + case "clear_logcat": // Update the icon. - if (sharedPreferences.getBoolean("clear_cache", true)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - clearCachePreference.setIcon(R.drawable.cache_cleared_night); + if (sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + clearLogcatPreference.setIcon(R.drawable.bug_cleared_day); } else { - clearCachePreference.setIcon(R.drawable.cache_cleared_day); + clearLogcatPreference.setIcon(R.drawable.bug_cleared_night); } } else { - clearCachePreference.setIcon(R.drawable.cache_warning); + clearLogcatPreference.setIcon(R.drawable.bug_warning); } break; - case "homepage": - // Set the new homepage URL as the summary text for the Homepage preference. - homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value))); - break; - - case "download_location": - // Get the new download location. - String newDownloadLocationString = sharedPreferences.getString("download_location", getString(R.string.download_location_default_value)); - - // Check to see if a download custom location is selected. - if (newDownloadLocationString.equals(downloadLocationEntryValuesStringArray[3])) { // A download custom location is selected. - // Set the download location summary text to be `Custom`. - downloadLocationPreference.setSummary(downloadLocationEntriesStringArray[3]); - - // Enable the download custom location preference. - downloadCustomLocationPreference.setEnabled(true); - } else { // A download custom location is not selected. - // Set the download location summary text to be the download location. - downloadLocationPreference.setSummary(downloadLocationHelper.getDownloadLocation(context)); - - // Disable the download custom location. - downloadCustomLocationPreference.setEnabled(newDownloadLocationString.equals(downloadLocationEntryValuesStringArray[3])); - } - - // Update the download custom location icon. - if (downloadCustomLocationPreference.isEnabled()) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_night); + case "clear_cache": + // Update the icon. + if (sharedPreferences.getBoolean("clear_cache", true)) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + clearCachePreference.setIcon(R.drawable.cache_cleared_day); } else { - downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_day); + clearCachePreference.setIcon(R.drawable.cache_cleared_night); } } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_night); - } else { - downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_day); - } + clearCachePreference.setIcon(R.drawable.cache_warning); } break; - case "download_custom_location": - // Set the new download custom location as the summary text for the preference. - downloadCustomLocationPreference.setSummary(sharedPreferences.getString("download_custom_location", getString(R.string.download_custom_location_default_value))); + case "homepage": + // Set the new homepage URL as the summary text for the Homepage preference. + homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value))); break; case "font_size": @@ -1822,55 +1722,55 @@ public class SettingsFragment extends PreferenceFragmentCompat { currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; break; - case "night_mode": - // Store the current night mode status. - boolean currentNightModeBoolean = sharedPreferences.getBoolean("night_mode", false); - boolean currentJavaScriptBoolean = sharedPreferences.getBoolean("javascript", false); + case "webview_theme": + // Get the new WebView theme. + String newWebViewTheme = sharedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value)); - // Update the icon. - if (currentNightModeBoolean) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - nightModePreference.setIcon(R.drawable.night_mode_enabled_night); - } else { - nightModePreference.setIcon(R.drawable.night_mode_enabled_day); - } - } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - nightModePreference.setIcon(R.drawable.night_mode_disabled_night); - } else { - nightModePreference.setIcon(R.drawable.night_mode_disabled_day); - } + // Define a new WebView theme entry number. + int newWebViewThemeEntryNumber; + + // 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. + if (newWebViewTheme.equals(webViewThemeEntriesStringArray[1])) { // The light theme is selected. + // Store the new WebView theme entry number. + newWebViewThemeEntryNumber = 1; + } else if (newWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected. + // Store the WebView theme entry number. + newWebViewThemeEntryNumber = 2; + } else { // The system default theme is selected. + // Store the WebView theme entry number. + newWebViewThemeEntryNumber = 0; } - // Update the status of `javaScriptPreference` and `domStoragePreference`. - javaScriptPreference.setEnabled(!currentNightModeBoolean); - domStoragePreference.setEnabled(currentNightModeBoolean || currentJavaScriptBoolean); + // Update the icon. + switch (newWebViewThemeEntryNumber) { + case 0: // The system default WebView theme is selected. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemePreference.setIcon(R.drawable.webview_light_theme_day); + } else { + webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night); + } + break; - // Update the `javaScriptPreference` icon. - if (currentNightModeBoolean || currentJavaScriptBoolean) { - javaScriptPreference.setIcon(R.drawable.javascript_enabled); - } else { - javaScriptPreference.setIcon(R.drawable.privacy_mode); - } + case 1: // The system default WebView theme is selected. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemePreference.setIcon(R.drawable.webview_light_theme_day); + } else { + webViewThemePreference.setIcon(R.drawable.webview_light_theme_night); + } + break; - // Update the DOM storage preference icon. - if (currentNightModeBoolean || currentJavaScriptBoolean) { // The preference is enabled. - if (sharedPreferences.getBoolean("dom_storage", false)) { // DOM storage is enabled. - domStoragePreference.setIcon(R.drawable.dom_storage_enabled); - } else { // DOM storage is disabled. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night); + case 2: // The system default WebView theme is selected. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day); } else { - domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day); + webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night); } - } - } else { // The preference is disabled. The icon should be ghosted. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night); - } else { - domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day); - } + break; } + + // Set the current theme as the summary text for the preference. + webViewThemePreference.setSummary(webViewThemeEntriesStringArray[newWebViewThemeEntryNumber]); break; case "wide_viewport":