]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.kt
Update the proxy app bar background color. https://redmine.stoutner.com/issues/998
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / DomainSettingsFragment.kt
index 52739a4a5a074e906e3de8141f505d1fa246be2d..23fce5d8b358c717cd8571f0ae5bb15334fef8c1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017-2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2017-2023 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
  *
@@ -45,13 +45,19 @@ import android.widget.TextView
 
 import androidx.appcompat.widget.SwitchCompat
 import androidx.cardview.widget.CardView
+import androidx.core.content.ContextCompat.getColor
 import androidx.core.content.res.ResourcesCompat
 import androidx.fragment.app.Fragment
 import androidx.preference.PreferenceManager
 
 import com.stoutner.privacybrowser.R
+import com.stoutner.privacybrowser.activities.DOMAINS_CUSTOM_USER_AGENT
+import com.stoutner.privacybrowser.activities.DOMAINS_SYSTEM_DEFAULT_USER_AGENT
+import com.stoutner.privacybrowser.activities.DOMAINS_WEBVIEW_DEFAULT_USER_AGENT
+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.activities.DomainsActivity
-import com.stoutner.privacybrowser.activities.MainWebViewActivity
 import com.stoutner.privacybrowser.helpers.DomainsDatabaseHelper
 
 import java.lang.IndexOutOfBoundsException
@@ -94,7 +100,6 @@ class DomainSettingsFragment : Fragment() {
         // Store the default settings.
         val defaultUserAgentName = sharedPreferences.getString(getString(R.string.user_agent_key), getString(R.string.user_agent_default_value))
         val defaultCustomUserAgentString = sharedPreferences.getString(getString(R.string.custom_user_agent_key), getString(R.string.custom_user_agent_default_value))
-        val defaultXRequestedWithHeader = sharedPreferences.getBoolean(getString(R.string.x_requested_with_header_key), true)
         val defaultFontSizeString = sharedPreferences.getString(getString(R.string.font_size_key), getString(R.string.font_size_default_value))
         val defaultSwipeToRefresh = sharedPreferences.getBoolean(getString(R.string.swipe_to_refresh_key), true)
         val defaultWebViewTheme = sharedPreferences.getString(getString(R.string.webview_theme_key), getString(R.string.webview_theme_default_value))
@@ -126,19 +131,17 @@ class DomainSettingsFragment : Fragment() {
         val ultraPrivacySwitch = domainSettingsView.findViewById<SwitchCompat>(R.id.ultraprivacy_switch)
         val blockAllThirdPartyRequestsImageView = domainSettingsView.findViewById<ImageView>(R.id.block_all_third_party_requests_imageview)
         val blockAllThirdPartyRequestsSwitch = domainSettingsView.findViewById<SwitchCompat>(R.id.block_all_third_party_requests_switch)
+        val userAgentLinearLayout = domainSettingsView.findViewById<LinearLayout>(R.id.user_agent_linear_layout)
         val userAgentSpinner = domainSettingsView.findViewById<Spinner>(R.id.user_agent_spinner)
         val userAgentTextView = domainSettingsView.findViewById<TextView>(R.id.user_agent_textview)
         val customUserAgentEditText = domainSettingsView.findViewById<EditText>(R.id.custom_user_agent_edittext)
-        val xRequestedWithHeaderImageView = domainSettingsView.findViewById<ImageView>(R.id.x_requested_with_header_imageview)
-        val xRequestedWithHeaderSpinner = domainSettingsView.findViewById<Spinner>(R.id.x_requested_with_header_spinner)
-        val xRequestedWithHeaderTextView = domainSettingsView.findViewById<TextView>(R.id.x_requested_with_header_textview)
-        val xRequestedWithHeaderExplanationTextView = domainSettingsView.findViewById<TextView>(R.id.x_requested_with_header_explanation_textview)
         val fontSizeSpinner = domainSettingsView.findViewById<Spinner>(R.id.font_size_spinner)
         val defaultFontSizeTextView = domainSettingsView.findViewById<TextView>(R.id.default_font_size_textview)
         val customFontSizeEditText = domainSettingsView.findViewById<EditText>(R.id.custom_font_size_edittext)
         val swipeToRefreshImageView = domainSettingsView.findViewById<ImageView>(R.id.swipe_to_refresh_imageview)
         val swipeToRefreshSpinner = domainSettingsView.findViewById<Spinner>(R.id.swipe_to_refresh_spinner)
         val swipeToRefreshTextView = domainSettingsView.findViewById<TextView>(R.id.swipe_to_refresh_textview)
+        val webViewThemeLinearLayout = domainSettingsView.findViewById<LinearLayout>(R.id.webview_theme_linearlayout)
         val webViewThemeImageView = domainSettingsView.findViewById<ImageView>(R.id.webview_theme_imageview)
         val webViewThemeSpinner = domainSettingsView.findViewById<Spinner>(R.id.webview_theme_spinner)
         val webViewThemeTextView = domainSettingsView.findViewById<TextView>(R.id.webview_theme_textview)
@@ -184,12 +187,16 @@ class DomainSettingsFragment : Fragment() {
         val currentIpAddressesRadioButton = domainSettingsView.findViewById<RadioButton>(R.id.current_ip_addresses_radiobutton)
         val currentIpAddressesTextView = domainSettingsView.findViewById<TextView>(R.id.current_ip_addresses_textview)
 
+        // Hide the WebView theme linear layout if the API < 29.
+        if (Build.VERSION.SDK_INT < 29)
+            webViewThemeLinearLayout.visibility = View.GONE
+
         // Setup the pinned labels.
-        val cNameLabel = getString(R.string.common_name) + "  "
-        val oNameLabel = getString(R.string.organization) + "  "
-        val uNameLabel = getString(R.string.organizational_unit) + "  "
-        val startDateLabel = getString(R.string.start_date) + "  "
-        val endDateLabel = getString(R.string.end_date) + "  "
+        val cNameLabel = getString(R.string.common_name)
+        val oNameLabel = getString(R.string.organization)
+        val uNameLabel = getString(R.string.organizational_unit)
+        val startDateLabel = getString(R.string.start_date)
+        val endDateLabel = getString(R.string.end_date)
 
         // Initialize the database handler.
         val domainsDatabaseHelper = DomainsDatabaseHelper(requireContext())
@@ -214,7 +221,6 @@ class DomainSettingsFragment : Fragment() {
         val ultraPrivacyInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY))
         val blockAllThirdPartyRequestsInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS))
         val currentUserAgentName = domainCursor.getString(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.USER_AGENT))
-        val xRequestedWithHeaderInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.X_REQUESTED_WITH_HEADER))
         val fontSizeInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.FONT_SIZE))
         val swipeToRefreshInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.SWIPE_TO_REFRESH))
         val webViewThemeInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.WEBVIEW_THEME))
@@ -246,7 +252,6 @@ class DomainSettingsFragment : Fragment() {
 
         // Create array adapters for the spinners.
         val translatedUserAgentArrayAdapter = ArrayAdapter.createFromResource(requireContext(), R.array.translated_domain_settings_user_agent_names, R.layout.spinner_item)
-        val xRequestedWithHeaderArrayAdapter = ArrayAdapter.createFromResource(requireContext(), R.array.x_requested_with_header_array, R.layout.spinner_item)
         val fontSizeArrayAdapter = ArrayAdapter.createFromResource(requireContext(), R.array.font_size_array, R.layout.spinner_item)
         val swipeToRefreshArrayAdapter = ArrayAdapter.createFromResource(requireContext(), R.array.swipe_to_refresh_array, R.layout.spinner_item)
         val webViewThemeArrayAdapter = ArrayAdapter.createFromResource(requireContext(), R.array.webview_theme_array, R.layout.spinner_item)
@@ -255,7 +260,6 @@ class DomainSettingsFragment : Fragment() {
 
         // Set the drop down view resource on the spinners.
         translatedUserAgentArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_items)
-        xRequestedWithHeaderArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_items)
         fontSizeArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_items)
         swipeToRefreshArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_items)
         webViewThemeArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_items)
@@ -264,7 +268,6 @@ class DomainSettingsFragment : Fragment() {
 
         // Set the array adapters for the spinners.
         userAgentSpinner.adapter = translatedUserAgentArrayAdapter
-        xRequestedWithHeaderSpinner.adapter = xRequestedWithHeaderArrayAdapter
         fontSizeSpinner.adapter = fontSizeArrayAdapter
         swipeToRefreshSpinner.adapter = swipeToRefreshArrayAdapter
         webViewThemeSpinner.adapter = webViewThemeArrayAdapter
@@ -349,33 +352,33 @@ class DomainSettingsFragment : Fragment() {
         })
 
         // Set the switch positions.
-        javaScriptSwitch.isChecked = javaScriptInt == 1
-        cookiesSwitch.isChecked = cookiesInt == 1
-        domStorageSwitch.isChecked = domStorageInt == 1
-        formDataSwitch.isChecked = formDataInt == 1 // Form data can be removed once the minimum API >= 26.
-        easyListSwitch.isChecked = easyListInt == 1
-        easyPrivacySwitch.isChecked = easyPrivacyInt == 1
-        fanboysAnnoyanceListSwitch.isChecked = fanboysAnnoyanceListInt == 1
-        fanboysSocialBlockingListSwitch.isChecked = fanboysSocialBlockingListInt == 1
-        ultraListSwitch.isChecked = ultraListInt == 1
-        ultraPrivacySwitch.isChecked = ultraPrivacyInt == 1
-        blockAllThirdPartyRequestsSwitch.isChecked = blockAllThirdPartyRequestsInt == 1
-        pinnedSslCertificateSwitch.isChecked = pinnedSslCertificateInt == 1
-        pinnedIpAddressesSwitch.isChecked = pinnedIpAddressesInt == 1
+        javaScriptSwitch.isChecked = (javaScriptInt == 1)
+        cookiesSwitch.isChecked = (cookiesInt == 1)
+        domStorageSwitch.isChecked = (domStorageInt == 1)
+        formDataSwitch.isChecked = (formDataInt == 1)  // Form data can be removed once the minimum API >= 26.
+        easyListSwitch.isChecked = (easyListInt == 1)
+        easyPrivacySwitch.isChecked = (easyPrivacyInt == 1)
+        fanboysAnnoyanceListSwitch.isChecked = (fanboysAnnoyanceListInt == 1)
+        fanboysSocialBlockingListSwitch.isChecked = (fanboysSocialBlockingListInt == 1)
+        ultraListSwitch.isChecked = (ultraListInt == 1)
+        ultraPrivacySwitch.isChecked = (ultraPrivacyInt == 1)
+        blockAllThirdPartyRequestsSwitch.isChecked = (blockAllThirdPartyRequestsInt == 1)
+        pinnedSslCertificateSwitch.isChecked = (pinnedSslCertificateInt == 1)
+        pinnedIpAddressesSwitch.isChecked = (pinnedIpAddressesInt == 1)
 
         // Set the switch icon colors.
-        cookiesImageView.isSelected = cookiesInt == 1
-        domStorageImageView.isSelected = domStorageInt == 1
-        formDataImageView.isSelected = formDataInt == 1 // Form data can be removed once the minimum API >= 26.
-        easyListImageView.isSelected = easyListInt == 1
-        easyPrivacyImageView.isSelected = easyPrivacyInt == 1
-        fanboysAnnoyanceListImageView.isSelected = fanboysAnnoyanceListInt == 1
-        fanboysSocialBlockingListImageView.isSelected = fanboysSocialBlockingListInt == 1
-        ultraListImageView.isSelected = ultraListInt == 1
-        ultraPrivacyImageView.isSelected = ultraPrivacyInt == 1
-        blockAllThirdPartyRequestsImageView.isSelected = blockAllThirdPartyRequestsInt == 1
-        pinnedSslCertificateImageView.isSelected = pinnedSslCertificateInt == 1
-        pinnedIpAddressesImageView.isSelected = pinnedIpAddressesInt == 1
+        cookiesImageView.isSelected = (cookiesInt == 1)
+        domStorageImageView.isSelected = (domStorageInt == 1)
+        formDataImageView.isSelected = (formDataInt == 1)  // Form data can be removed once the minimum API >= 26.
+        easyListImageView.isSelected = (easyListInt == 1)
+        easyPrivacyImageView.isSelected = (easyPrivacyInt == 1)
+        fanboysAnnoyanceListImageView.isSelected = (fanboysAnnoyanceListInt == 1)
+        fanboysSocialBlockingListImageView.isSelected = (fanboysSocialBlockingListInt == 1)
+        ultraListImageView.isSelected = (ultraListInt == 1)
+        ultraPrivacyImageView.isSelected = (ultraPrivacyInt == 1)
+        blockAllThirdPartyRequestsImageView.isSelected = (blockAllThirdPartyRequestsInt == 1)
+        pinnedSslCertificateImageView.isSelected = (pinnedSslCertificateInt == 1)
+        pinnedIpAddressesImageView.isSelected = (pinnedIpAddressesInt == 1)
 
         // Set the JavaScript icon.
         if (javaScriptInt == 1)
@@ -402,6 +405,14 @@ class DomainSettingsFragment : Fragment() {
         // Set the Social Blocking List icon ghosted status based on the Annoyance List status.
         fanboysSocialBlockingListImageView.isEnabled = (fanboysAnnoyanceListInt == 0)
 
+        // Open the spinners when the text view is clicked.
+        userAgentTextView.setOnClickListener { userAgentSpinner.performClick() }
+        defaultFontSizeTextView.setOnClickListener { fontSizeSpinner.performClick() }
+        swipeToRefreshTextView.setOnClickListener { swipeToRefreshSpinner.performClick() }
+        webViewThemeTextView.setOnClickListener { webViewThemeSpinner.performClick() }
+        wideViewportTextView.setOnClickListener { wideViewportSpinner.performClick() }
+        displayImagesTextView.setOnClickListener { displayWebpageImagesSpinner.performClick() }
+
         // Inflated a WebView to get the default user agent.
         // `@SuppressLint("InflateParams")` removes the warning about using `null` as the `ViewGroup`, which in this case makes sense because the bare WebView should not be displayed on the screen.
         @SuppressLint("InflateParams") val bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false)
@@ -423,21 +434,24 @@ class DomainSettingsFragment : Fragment() {
             // Set the user agent according to the system default.
             when (defaultUserAgentArrayPosition) {
                 // This is probably because it was set in an older version of Privacy Browser before the switch to persistent user agent names.
-                MainWebViewActivity.UNRECOGNIZED_USER_AGENT -> userAgentTextView.text = defaultUserAgentName
+                UNRECOGNIZED_USER_AGENT -> userAgentTextView.text = defaultUserAgentName
 
                 // Display the WebView default user agent.
-                MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT -> userAgentTextView.text = webViewDefaultUserAgentString
+                SETTINGS_WEBVIEW_DEFAULT_USER_AGENT -> userAgentTextView.text = webViewDefaultUserAgentString
 
                 // Display the custom user agent.
-                MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT -> userAgentTextView.text = defaultCustomUserAgentString
+                SETTINGS_CUSTOM_USER_AGENT -> userAgentTextView.text = defaultCustomUserAgentString
 
                 // Get the user agent string from the user agent data array.
                 else -> userAgentTextView.text = userAgentDataArray[defaultUserAgentArrayPosition]
             }
-        } else if (userAgentArrayPosition == MainWebViewActivity.UNRECOGNIZED_USER_AGENT || currentUserAgentName == getString(R.string.custom_user_agent)) {
+
+            // Set the background color to be transparent.
+            userAgentLinearLayout.setBackgroundColor(getColor(requireContext(), R.color.transparent))
+        } else if (userAgentArrayPosition == UNRECOGNIZED_USER_AGENT || currentUserAgentName == getString(R.string.custom_user_agent)) {
             // A custom user agent is stored in the current user agent name.  The second check is necessary in case the user did not change the default custom text.
             // Set the user agent spinner to `Custom user agent`.
-            userAgentSpinner.setSelection(MainWebViewActivity.DOMAINS_CUSTOM_USER_AGENT)
+            userAgentSpinner.setSelection(DOMAINS_CUSTOM_USER_AGENT)
 
             // Hide the user agent text view.
             userAgentTextView.visibility = View.GONE
@@ -445,6 +459,9 @@ class DomainSettingsFragment : Fragment() {
             // Show the custom user agent edit text and set the current user agent name as the text.
             customUserAgentEditText.visibility = View.VISIBLE
             customUserAgentEditText.setText(currentUserAgentName)
+
+            // Set the background color to be blue.
+            userAgentLinearLayout.setBackgroundColor(getColor(requireContext(), R.color.blue_background))
         } else {  // The user agent name contains one of the canonical user agents.
             // Set the user agent spinner selection.  The spinner has one more entry at the beginning than the user agent data array, so the position must be incremented.
             userAgentSpinner.setSelection(userAgentArrayPosition + 1)
@@ -456,59 +473,18 @@ class DomainSettingsFragment : Fragment() {
             customUserAgentEditText.visibility = View.GONE
 
             // Set the user agent text.
-            if (userAgentArrayPosition == MainWebViewActivity.DOMAINS_WEBVIEW_DEFAULT_USER_AGENT) {  // The WebView default user agent is selected.
+            if (userAgentArrayPosition == DOMAINS_WEBVIEW_DEFAULT_USER_AGENT) {  // The WebView default user agent is selected.
                 // Display the WebView default user agent.
                 userAgentTextView.text = webViewDefaultUserAgentString
             } else {  // A user agent besides the default is selected.
                 // Get the user agent string from the user agent data array.  The spinner has one more entry at the beginning than the user agent data array, so the position must be incremented.
                 userAgentTextView.text = userAgentDataArray[userAgentArrayPosition + 1]
             }
-        }
-
-        // Open the user agent spinner when the text view is clicked.
-        userAgentTextView.setOnClickListener { userAgentSpinner.performClick() }
-
-        // Select the X-Requested-With header selection in the spinner.
-        xRequestedWithHeaderSpinner.setSelection(xRequestedWithHeaderInt)
-
-        // Set the X-Requested-With header text.
-        if (defaultXRequestedWithHeader)
-            xRequestedWithHeaderTextView.text = xRequestedWithHeaderArrayAdapter.getItem(DomainsDatabaseHelper.ENABLED)
-        else
-            xRequestedWithHeaderTextView.text = xRequestedWithHeaderArrayAdapter.getItem(DomainsDatabaseHelper.DISABLED)
-
-        // Set the X-Requested-With header icon and text view settings.
-        when (xRequestedWithHeaderInt) {
-            DomainsDatabaseHelper.SYSTEM_DEFAULT -> {
-                // Set the icon color.
-                xRequestedWithHeaderImageView.isSelected = defaultXRequestedWithHeader
-
-                // Show the X-Requested-With header text view.
-                xRequestedWithHeaderTextView.visibility = View.VISIBLE
-            }
-
-            DomainsDatabaseHelper.ENABLED -> {
-                // Set the icon color.
-                xRequestedWithHeaderImageView.isSelected = true
-
-                // Hide the X-Requested-With header text view.
-                xRequestedWithHeaderTextView.visibility = View.GONE
-            }
 
-            DomainsDatabaseHelper.DISABLED -> {
-                // Set the icon color.
-                xRequestedWithHeaderImageView.isSelected = false
-
-                // Hide the X-Requested-With header text view.
-                xRequestedWithHeaderTextView.visibility = View.GONE
-            }
+            // Set the background color to be blue.
+            userAgentLinearLayout.setBackgroundColor(getColor(requireContext(), R.color.blue_background))
         }
 
-        // Open the X-Requested-With header spinner when the text view is clicked.
-        xRequestedWithHeaderTextView.setOnClickListener { xRequestedWithHeaderSpinner.performClick() }
-
-        // Open the X-Requested-With header spinner when the explanation text view is clicked.
-        xRequestedWithHeaderExplanationTextView.setOnClickListener { xRequestedWithHeaderSpinner.performClick() }
 
         // Display the font size settings.
         if (fontSizeInt == 0) {  // `0` is the code for system default font size.
@@ -543,9 +519,6 @@ class DomainSettingsFragment : Fragment() {
         // Set the default font size text in the text view.
         defaultFontSizeTextView.text = defaultFontSizePercentageString
 
-        // Open the font size spinner when the text view is clicked.
-        defaultFontSizeTextView.setOnClickListener { fontSizeSpinner.performClick() }
-
         // Select the swipe-to-refresh selection in the spinner.
         swipeToRefreshSpinner.setSelection(swipeToRefreshInt)
 
@@ -582,9 +555,6 @@ class DomainSettingsFragment : Fragment() {
             }
         }
 
-        // Open the swipe-to-refresh spinner when the text view is clicked.
-        swipeToRefreshTextView.setOnClickListener { swipeToRefreshSpinner.performClick() }
-
         // Get the WebView theme string arrays.
         val webViewThemeStringArray = resources.getStringArray(R.array.webview_theme_array)
         val webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values)
@@ -642,9 +612,6 @@ class DomainSettingsFragment : Fragment() {
             }
         }
 
-        // Open the WebView theme spinner when the text view is clicked.
-        webViewThemeTextView.setOnClickListener { webViewThemeSpinner.performClick() }
-
         // Select the wide viewport in the spinner.
         wideViewportSpinner.setSelection(wideViewportInt)
 
@@ -680,9 +647,6 @@ class DomainSettingsFragment : Fragment() {
             }
         }
 
-        // Open the wide viewport spinner when the text view is clicked.
-        wideViewportTextView.setOnClickListener { wideViewportSpinner.performClick() }
-
         // Display the website images mode in the spinner.
         displayWebpageImagesSpinner.setSelection(displayImagesInt)
 
@@ -719,9 +683,6 @@ class DomainSettingsFragment : Fragment() {
             }
         }
 
-        // Open the display images spinner when the text view is clicked.
-        displayImagesTextView.setOnClickListener { displayWebpageImagesSpinner.performClick() }
-
         // Store the current date.
         val currentDate = Calendar.getInstance().time
 
@@ -1004,7 +965,7 @@ class DomainSettingsFragment : Fragment() {
             override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
                 // Set the new user agent.
                 when (position) {
-                    MainWebViewActivity.DOMAINS_SYSTEM_DEFAULT_USER_AGENT -> {
+                    DOMAINS_SYSTEM_DEFAULT_USER_AGENT -> {
                         // Show the user agent text view.
                         userAgentTextView.visibility = View.VISIBLE
 
@@ -1014,20 +975,23 @@ class DomainSettingsFragment : Fragment() {
                         // Set the user text.
                         when (defaultUserAgentArrayPosition) {
                             // This is probably because it was set in an older version of Privacy Browser before the switch to persistent user agent names.
-                            MainWebViewActivity.UNRECOGNIZED_USER_AGENT -> userAgentTextView.text = defaultUserAgentName
+                            UNRECOGNIZED_USER_AGENT -> userAgentTextView.text = defaultUserAgentName
 
                             // Display the `WebView` default user agent.
-                            MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT -> userAgentTextView.text = webViewDefaultUserAgentString
+                            SETTINGS_WEBVIEW_DEFAULT_USER_AGENT -> userAgentTextView.text = webViewDefaultUserAgentString
 
                             // Display the custom user agent.
-                            MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT -> userAgentTextView.text = defaultCustomUserAgentString
+                            SETTINGS_CUSTOM_USER_AGENT -> userAgentTextView.text = defaultCustomUserAgentString
 
                             // Get the user agent string from the user agent data array.
                             else -> userAgentTextView.text = userAgentDataArray[defaultUserAgentArrayPosition]
                         }
+
+                        // Set the background color to be transparent.
+                        userAgentLinearLayout.setBackgroundColor(getColor(requireContext(), R.color.transparent))
                     }
 
-                    MainWebViewActivity.DOMAINS_WEBVIEW_DEFAULT_USER_AGENT -> {
+                    DOMAINS_WEBVIEW_DEFAULT_USER_AGENT -> {
                         // Show the user agent text view.
                         userAgentTextView.visibility = View.VISIBLE
 
@@ -1036,9 +1000,12 @@ class DomainSettingsFragment : Fragment() {
 
                         // Hide the custom user agent EditTex.
                         customUserAgentEditText.visibility = View.GONE
+
+                        // Set the background color to be blue.
+                        userAgentLinearLayout.setBackgroundColor(getColor(requireContext(), R.color.blue_background))
                     }
 
-                    MainWebViewActivity.DOMAINS_CUSTOM_USER_AGENT -> {
+                    DOMAINS_CUSTOM_USER_AGENT -> {
                         // Hide the user agent TextView.
                         userAgentTextView.visibility = View.GONE
 
@@ -1047,6 +1014,9 @@ class DomainSettingsFragment : Fragment() {
 
                         // Set the current user agent name as the text.
                         customUserAgentEditText.setText(currentUserAgentName)
+
+                        // Set the background color to be blue.
+                        userAgentLinearLayout.setBackgroundColor(getColor(requireContext(), R.color.blue_background))
                     }
 
                     else -> {
@@ -1058,42 +1028,9 @@ class DomainSettingsFragment : Fragment() {
 
                         // Hide the custom user agent edit text.
                         customUserAgentEditText.visibility = View.GONE
-                    }
-                }
-            }
-
-            override fun onNothingSelected(parent: AdapterView<*>?) {
-                // Do nothing.
-            }
-        }
-
-        // Set the X-Requested-With header spinner listener.
-        xRequestedWithHeaderSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
-            override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
-                // Update the icon and the visibility of the text view.
-                when (position) {
-                    DomainsDatabaseHelper.SYSTEM_DEFAULT -> {
-                        // Set the icon color.
-                        xRequestedWithHeaderImageView.isSelected = defaultXRequestedWithHeader
-
-                        // Show the X-Requested-With header text view.
-                        xRequestedWithHeaderTextView.visibility = View.VISIBLE
-                    }
-
-                    DomainsDatabaseHelper.ENABLED -> {
-                        // Set the icon color.
-                        xRequestedWithHeaderImageView.isSelected = true
-
-                        // Hide the X-Requested-With header text view.
-                        xRequestedWithHeaderTextView.visibility = View.GONE
-                    }
-
-                    DomainsDatabaseHelper.DISABLED -> {
-                        // Set the icon color.
-                        xRequestedWithHeaderImageView.isSelected = false
 
-                        // Hide the X-Requested-With header text view.
-                        xRequestedWithHeaderTextView.visibility = View.GONE
+                        // Set the background color to be blue.
+                        userAgentLinearLayout.setBackgroundColor(getColor(requireContext(), R.color.blue_background))
                     }
                 }
             }