- // Set the user agent spinner listener.
- userAgentSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
- override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
- // Set the new user agent.
- when (position) {
- DOMAINS_SYSTEM_DEFAULT_USER_AGENT -> {
- // Show the user agent text view.
- userAgentTextView.visibility = View.VISIBLE
-
- // Hide the custom user agent edit text.
- customUserAgentEditText.visibility = View.GONE
-
- // 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.
- UNRECOGNIZED_USER_AGENT -> userAgentTextView.text = userAgentDefault
-
- // Display the `WebView` default user agent.
- SETTINGS_WEBVIEW_DEFAULT_USER_AGENT -> userAgentTextView.text = webViewDefaultUserAgentString
-
- // Display the custom user agent.
- SETTINGS_CUSTOM_USER_AGENT -> userAgentTextView.text = customUserAgentStringDefault
-
- // 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(context, R.color.transparent))
- }
-
- DOMAINS_WEBVIEW_DEFAULT_USER_AGENT -> {
- // Show the user agent text view.
- userAgentTextView.visibility = View.VISIBLE
-
- // Set the user agent text.
- userAgentTextView.text = webViewDefaultUserAgentString
-
- // Hide the custom user agent edit text.
- customUserAgentEditText.visibility = View.GONE
-
- // Set the background color to be blue.
- userAgentLinearLayout.setBackgroundColor(getColor(context, R.color.blue_background))
- }
-
- DOMAINS_CUSTOM_USER_AGENT -> {
- // Hide the user agent text view.
- userAgentTextView.visibility = View.GONE
-
- // Show the custom user agent edit text.
- customUserAgentEditText.visibility = View.VISIBLE
-
- // Set the current user agent name as the text.
- customUserAgentEditText.setText(currentUserAgentName)
-
- // Set the background color to be blue.
- userAgentLinearLayout.setBackgroundColor(getColor(context, R.color.blue_background))
- }
-
- else -> {
- // Show the user agent text view.
- userAgentTextView.visibility = View.VISIBLE
-
- // Set the text from the user agent data array, which has one less entry than the spinner, so the position must be decremented.
- userAgentTextView.text = userAgentDataArray[position - 1]
-
- // Hide the custom user agent edit text.
- customUserAgentEditText.visibility = View.GONE
-
- // Set the background color to be blue.
- userAgentLinearLayout.setBackgroundColor(getColor(context, R.color.blue_background))
- }
- }
- }
-
- override fun onNothingSelected(parent: AdapterView<*>?) {
- // Do nothing.
- }
- }
-