]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.kt
Fix WebView's dark mode on API 29-32. https://redmine.stoutner.com/issues/927
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / SettingsFragment.kt
index c6fb15fbba6df558f07d8b73a3034e22384ad894..2ce103dcbda524fdbe74db3cbe538836ca6f3e9d 100644 (file)
@@ -60,7 +60,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
     private lateinit var formDataPreference: Preference  // The form data preference can be removed once the minimum API >= 26.
     private lateinit var userAgentPreference: Preference
     private lateinit var customUserAgentPreference: Preference
-    private lateinit var xRequestedWithHeaderPreference: Preference
     private lateinit var incognitoModePreference: Preference
     private lateinit var allowScreenshotsPreference: Preference
     private lateinit var easyListPreference: Preference
@@ -111,7 +110,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
         formDataPreference = findPreference(getString(R.string.save_form_data_key))!!  // The form data preference can be removed once the minimum API >= 26.
         userAgentPreference = findPreference(getString(R.string.user_agent_key))!!
         customUserAgentPreference = findPreference(getString(R.string.custom_user_agent_key))!!
-        xRequestedWithHeaderPreference = findPreference(getString(R.string.x_requested_with_header_key))!!
         incognitoModePreference = findPreference(getString(R.string.incognito_mode_key))!!
         allowScreenshotsPreference = findPreference(getString(R.string.allow_screenshots_key))!!
         easyListPreference = findPreference(getString(R.string.easylist_key))!!
@@ -175,6 +173,15 @@ class SettingsFragment : PreferenceFragmentCompat() {
             clearAndExitCategory.removePreference(clearFormDataPreference)
         }
 
+        // Remove the WebView theme preference if the API < 29.
+        if (Build.VERSION.SDK_INT < 29) {
+            // Get a handle for the general category.
+            val generalCategory = findPreference<PreferenceCategory>(getString(R.string.general_category_key))!!
+
+            // Remove the WebView theme preference.
+            generalCategory.removePreference(webViewThemePreference)
+        }
+
         // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled.
         fanboySocialBlockingListPreference.isEnabled = !fanboyAnnoyanceListEnabled
 
@@ -275,8 +282,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
         // Set the current theme as the summary text for the preference.
         appThemePreference.summary = appThemeEntriesStringArray[appThemeEntryNumber]
 
-        // Enable the WebView theme preference if the API < 33 or the app theme is not set to light.  Google no longer allows light themes to display dark WebViews.
-        webViewThemePreference.isEnabled = ((Build.VERSION.SDK_INT < 33) || (appThemeEntryNumber != 1))
+        // Enable the WebView theme preference if the app theme is not set to light.  Google does not allow light themes to display dark WebViews.
+        webViewThemePreference.isEnabled = (appThemeEntryNumber != 1)
 
         // Get the WebView theme string arrays.
         webViewThemeEntriesStringArray = resources.getStringArray(R.array.webview_theme_entries)
@@ -328,12 +335,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
         else
             customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted)
 
-        // Set the X-Requested With header icon.
-        if (sharedPreferences.getBoolean(getString(R.string.x_requested_with_header_key), true))
-            xRequestedWithHeaderPreference.setIcon(R.drawable.x_requested_with_header_enabled)
-        else
-            xRequestedWithHeaderPreference.setIcon(R.drawable.x_requested_with_header_disabled)
-
         // Set the incognito mode icon.
         if (sharedPreferences.getBoolean(getString(R.string.incognito_mode_key), false))
             incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled)
@@ -698,17 +699,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
                     customUserAgentPreference.summary = sharedPreferences.getString(getString(R.string.custom_user_agent_key), getString(R.string.custom_user_agent_default_value))
                 }
 
-                getString(R.string.x_requested_with_header_key) -> {
-                    // Update the icon.
-                    if (sharedPreferences.getBoolean(getString(R.string.x_requested_with_header_key), true))
-                        xRequestedWithHeaderPreference.setIcon(R.drawable.x_requested_with_header_enabled)
-                    else
-                        xRequestedWithHeaderPreference.setIcon(R.drawable.x_requested_with_header_disabled)
-
-                    // Restart Privacy Browser.
-                    restartPrivacyBrowser()
-                }
-
                 getString(R.string.incognito_mode_key) -> {
                     // Update the icon.
                     if (sharedPreferences.getBoolean(getString(R.string.incognito_mode_key), false))
@@ -1069,7 +1059,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
                 }
 
                 getString(R.string.app_theme_key) -> {
-                    // 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.
+                    // Get the app theme entry number that matches the current app theme.
                     val appThemeEntryNumber: Int = when (sharedPreferences.getString(getString(R.string.app_theme_key), getString(R.string.app_theme_default_value))) {
                         appThemeEntryValuesStringArray[1] -> 1  // The light theme is selected.
                         appThemeEntryValuesStringArray[2] -> 2  // The dark theme is selected.
@@ -1109,8 +1099,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
                         }
                     }
 
-                    // Enable the WebView theme preference if the API < 33 or the app theme is set to light.
-                    webViewThemePreference.isEnabled = ((Build.VERSION.SDK_INT < 33) || (appThemeEntryNumber != 1))
+                    // Enable the WebView theme preference if the app theme is not set to light.  Google does not allow light themes to display dark WebViews.
+                    webViewThemePreference.isEnabled = (appThemeEntryNumber != 1)
 
                     // Get the webView theme entry number that matches the new WebView theme.
                     val webViewThemeEntryNumber: Int = when (sharedPreferences.getString(getString(R.string.webview_theme_key), getString(R.string.webview_theme_default_value))) {