X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Ffragments%2FSettingsFragment.java;h=b7a829da4b1bf1642316bd002ae3259309c68ed7;hp=6130ece8584ff3f44ab1571354058c55df0c302a;hb=5917df154b320eadd4c2d935baf30f98fd6055c4;hpb=9d621a09cdc72a3ad434084b3aab297f3a7a9d44 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 6130ece8..b7a829da 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java @@ -81,7 +81,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { 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,6 +102,7 @@ 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"); @@ -147,6 +148,7 @@ 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; @@ -293,10 +295,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); @@ -361,7 +364,25 @@ public class SettingsFragment extends PreferenceFragmentCompat { String[] webViewThemeEntriesStringArray = resources.getStringArray(R.array.webview_theme_entries); String[] webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values); - // Hide the WebView theme preference if the API < 21. + // 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"); @@ -372,24 +393,6 @@ public class SettingsFragment extends PreferenceFragmentCompat { // Remove the WebView theme preference. generalCategory.removePreference(webViewThemePreference); } else { // The device is running API >= 21 - // 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 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 current theme as the summary text for the preference. webViewThemePreference.setSummary(webViewThemeEntriesStringArray[webViewThemeEntryNumber]); } @@ -510,17 +513,17 @@ public class SettingsFragment extends PreferenceFragmentCompat { } // 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); } } @@ -819,6 +822,17 @@ public class SettingsFragment extends PreferenceFragmentCompat { } } + // 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 { + clearLogcatPreference.setIcon(R.drawable.bug_cleared_night); + } + } else { + clearLogcatPreference.setIcon(R.drawable.bug_warning); + } + // Set the clear cache preference icon. if (clearEverything || savedPreferences.getBoolean("clear_cache", true)) { if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { @@ -905,6 +919,35 @@ public class SettingsFragment extends PreferenceFragmentCompat { } } + // Set the WebView theme preference icon. + switch (webViewThemeEntryNumber) { + case 0: // The system default WebView theme is selected. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemePreference.setIcon(R.drawable.webview_light_theme_day); + } else { + webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night); + } + break; + + case 1: // The light WebView theme is selected. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemePreference.setIcon(R.drawable.webview_light_theme_day); + } else { + webViewThemePreference.setIcon(R.drawable.webview_light_theme_night); + } + break; + + case 2: // The dark WebView theme is selected. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day); + } else { + webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night); + } + break; + } + // Set the wide viewport preference icon. if (savedPreferences.getBoolean("wide_viewport", true)) { if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { @@ -1158,17 +1201,17 @@ public class SettingsFragment extends PreferenceFragmentCompat { 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); } } @@ -1568,16 +1611,17 @@ 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); @@ -1588,7 +1632,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { 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); @@ -1599,7 +1643,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { 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); @@ -1623,7 +1667,18 @@ public class SettingsFragment extends PreferenceFragmentCompat { } } - // Update the `clearCachePreference` icon. + // 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_YES) { clearCachePreference.setIcon(R.drawable.cache_cleared_night); @@ -1675,6 +1730,19 @@ public class SettingsFragment extends PreferenceFragmentCompat { } break; + case "clear_logcat": + // Update the icon. + 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 { + clearLogcatPreference.setIcon(R.drawable.bug_cleared_night); + } + } else { + clearLogcatPreference.setIcon(R.drawable.bug_warning); + } + break; + case "clear_cache": // Update the icon. if (sharedPreferences.getBoolean("clear_cache", true)) { @@ -1860,6 +1928,34 @@ public class SettingsFragment extends PreferenceFragmentCompat { newWebViewThemeEntryNumber = 0; } + // 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; + + 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; + + 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 { + webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night); + } + break; + } + // Set the current theme as the summary text for the preference. webViewThemePreference.setSummary(webViewThemeEntriesStringArray[newWebViewThemeEntryNumber]); break;