]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.kt
Migrate the remaining classes to Kotlin. https://redmine.stoutner.com/issues/989
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / SettingsFragment.kt
index d73c905f65de62593c05fffeaadbab9a9438c6d3..a22734eeb4404451073f5711fae83b811a6ba06b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016-2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2016-2023 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
  *
@@ -37,7 +37,9 @@ import androidx.preference.PreferenceCategory
 import androidx.preference.PreferenceFragmentCompat
 
 import com.stoutner.privacybrowser.R
-import com.stoutner.privacybrowser.activities.MainWebViewActivity
+import com.stoutner.privacybrowser.activities.SETTINGS_CUSTOM_USER_AGENT
+import com.stoutner.privacybrowser.activities.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT
+import com.stoutner.privacybrowser.activities.UNRECOGNIZED_USER_AGENT
 import com.stoutner.privacybrowser.helpers.ProxyHelper
 import kotlin.system.exitProcess
 
@@ -173,6 +175,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
 
@@ -198,13 +209,13 @@ class SettingsFragment : PreferenceFragmentCompat() {
         when (val userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName)) {
             // The user agent name is not on the canonical list.
             // 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.
-            MainWebViewActivity.UNRECOGNIZED_USER_AGENT -> userAgentPreference.summary = userAgentName
+            UNRECOGNIZED_USER_AGENT -> userAgentPreference.summary = userAgentName
 
             // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
-            MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT -> userAgentPreference.summary = "${translatedUserAgentNamesArray[userAgentArrayPosition]}:\n$defaultUserAgent"
+            SETTINGS_WEBVIEW_DEFAULT_USER_AGENT -> userAgentPreference.summary = "${translatedUserAgentNamesArray[userAgentArrayPosition]}:\n$defaultUserAgent"
 
             // Display the custom user agent.
-            MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT -> userAgentPreference.setSummary(R.string.custom_user_agent)
+            SETTINGS_CUSTOM_USER_AGENT -> userAgentPreference.setSummary(R.string.custom_user_agent)
 
             // Get the user agent summary from the user agent data array.
             else -> userAgentPreference.summary = "${translatedUserAgentNamesArray[userAgentArrayPosition]}:\n${userAgentDataArray[userAgentArrayPosition]}"
@@ -273,8 +284,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)
@@ -650,7 +661,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
 
                     // Populate the user agent summary.
                     when (newUserAgentArrayPosition) {
-                        MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT -> {
+                        SETTINGS_WEBVIEW_DEFAULT_USER_AGENT -> {
                             // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
                             userAgentPreference.summary = "$translatedNewUserAgentName:\n$defaultUserAgent"
 
@@ -661,7 +672,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
                             customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted)
                         }
 
-                        MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT -> {
+                        SETTINGS_CUSTOM_USER_AGENT -> {
                             // Set the summary text.
                             userAgentPreference.setSummary(R.string.custom_user_agent)
 
@@ -1047,6 +1058,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
                         displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled)
                     else
                         displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled)
+
+                    // Restart Privacy Browser.
+                    restartPrivacyBrowser()
                 }
 
                 getString(R.string.app_theme_key) -> {
@@ -1090,8 +1104,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))) {