+ // Get the current settings status.
+ val javaScriptInt = calculateSettingsInt(currentWebView!!.settings.javaScriptEnabled, sharedPreferences.getBoolean(getString(R.string.javascript_key), false))
+ val cookiesInt = calculateSettingsInt(currentWebView!!.acceptCookies, sharedPreferences.getBoolean(getString(R.string.cookies_key), false))
+ val domStorageInt = calculateSettingsInt(currentWebView!!.settings.domStorageEnabled, sharedPreferences.getBoolean(getString(R.string.dom_storage_key), false))
+ val easyListInt = calculateSettingsInt(currentWebView!!.easyListEnabled, sharedPreferences.getBoolean(getString(R.string.easylist_key), true))
+ val easyPrivacyInt = calculateSettingsInt(currentWebView!!.easyPrivacyEnabled, sharedPreferences.getBoolean(getString(R.string.easyprivacy_key), true))
+ val fanboysAnnoyanceListInt = calculateSettingsInt(currentWebView!!.fanboysAnnoyanceListEnabled, sharedPreferences.getBoolean(getString(R.string.fanboys_annoyance_list_key), true))
+ val fanboysSocialBlockingListInt = calculateSettingsInt(currentWebView!!.fanboysSocialBlockingListEnabled, sharedPreferences.getBoolean(getString(R.string.fanboys_social_blocking_list_key), true))
+ val ultraListInt = calculateSettingsInt(currentWebView!!.ultraListEnabled, sharedPreferences.getBoolean(getString(R.string.ultralist_key), true))
+ val ultraPrivacyInt = calculateSettingsInt(currentWebView!!.ultraPrivacyEnabled, sharedPreferences.getBoolean(getString(R.string.ultraprivacy_key), true))
+ val blockAllThirdPartyRequestsInt = calculateSettingsInt(currentWebView!!.blockAllThirdPartyRequests, sharedPreferences.getBoolean(getString(R.string.block_all_third_party_requests_key), true))
+ val swipeToRefreshInt = calculateSettingsInt(currentWebView!!.swipeToRefresh, sharedPreferences.getBoolean(getString(R.string.swipe_to_refresh_key), true))
+ val wideViewportInt = calculateSettingsInt(currentWebView!!.settings.useWideViewPort, sharedPreferences.getBoolean(getString(R.string.wide_viewport_key), true))
+ val displayImagesInt = calculateSettingsInt(currentWebView!!.settings.loadsImagesAutomatically, sharedPreferences.getBoolean(getString(R.string.display_webpage_images_key), true))
+
+ // Initialize the form data int.
+ var formDataInt = SYSTEM_DEFAULT
+
+ // Set the form data int, which can be removed once the minimum API >= 26.
+ @Suppress("DEPRECATION")
+ if (Build.VERSION.SDK_INT < 26) {
+ // Get the form data status.
+ val formDataEnabled = currentWebView!!.settings.saveFormData
+
+ // Calculate the form data Int.
+ formDataInt = calculateSettingsInt(formDataEnabled, sharedPreferences.getBoolean(getString(R.string.save_form_data_key), false))
+ }
+
+ // Get the current user agent string.
+ val currentUserAgentString = currentWebView!!.settings.userAgentString
+
+ // Get the user agent string array position.
+ val userAgentStringArrayPosition = userAgentDataArrayAdapter.getPosition(currentUserAgentString)
+
+ // Set the user agent name.
+ val userAgentName = if ((userAgentStringArrayPosition >= 0) && (defaultUserAgentName == userAgentNamesArray[userAgentStringArrayPosition])) { // The system default user agent is in use.
+ getString(R.string.system_default_user_agent)
+ } else { // An on-the-fly user agent is being used (or the WebView default user agent is applied).
+ when (userAgentStringArrayPosition) {
+ UNRECOGNIZED_USER_AGENT -> { // The user agent is unrecognized.
+ if (currentUserAgentString == webViewDefaultUserAgent) { // The WebView default user agent is being used.
+ if (defaultUserAgentName == getString(R.string.webview_default)) { // The WebView default user agent is the system default.
+ // Set the user agent name to be the system default.
+ getString(R.string.system_default_user_agent)
+ } else { // The WebView default user agent is set as an on-the-fly setting.
+ // Set the default user agent name.
+ getString(R.string.webview_default)
+ }
+ } else { // A custom user agent is being used.
+ if (defaultUserAgentName == getString(R.string.custom_user_agent_non_translatable)) { // The system custom user agent is in use.
+ // Set the user agent name to be the system default.
+ getString(R.string.system_default_user_agent)
+ } else { // An on-the-fly custom user agent is in use.
+ // Store the user agent as currently applied.
+ currentUserAgentString
+ }
+ }
+ }
+
+ else -> // Store the standard user agent name.
+ userAgentNamesArray[userAgentStringArrayPosition]
+ }
+ }
+
+ // Get the current text zoom integer.
+ val textZoomInt = currentWebView!!.settings.textZoom
+
+ // Set the font size integer.
+ val fontSizeInt = if (textZoomInt == defaultFontSizeString.toInt()) // The current system default is used, which is encoded as a zoom of `0`.
+ SYSTEM_DEFAULT
+ else // A custom font size is used.
+ textZoomInt
+
+ // Get the current WebView dark theme status.
+ val webViewDarkThemeCurrentlyEnabled = if (WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) // Algorithmic darkening is supported.
+ WebSettingsCompat.isAlgorithmicDarkeningAllowed(currentWebView!!.settings)
+ else // Algorithmic darkening is not supported.
+ false
+
+ // Get the default WebView dark theme setting.
+ val defaultWebViewDarkThemeEnabled = if (WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) { // Algorithmic darkening is supported.
+ when (defaultWebViewTheme) {
+ webViewThemeEntryValuesStringArray[1] -> // The dark theme is disabled by default.
+ false
+
+ webViewThemeEntryValuesStringArray[2] -> // The dark theme is enabled by default.
+ true
+
+ else -> { // The system default theme is selected.
+ // Get the current app theme status.
+ val currentAppThemeStatus = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
+
+ // Check if the current app theme is dark.
+ currentAppThemeStatus == Configuration.UI_MODE_NIGHT_YES
+ }
+ }
+ } else { // Algorithmic darkening is not supported.
+ false
+ }
+
+ // Set the WebView theme int.
+ val webViewThemeInt = if (webViewDarkThemeCurrentlyEnabled == defaultWebViewDarkThemeEnabled) // The current WebView theme matches the default.
+ SYSTEM_DEFAULT
+ else if (webViewDarkThemeCurrentlyEnabled) // The current WebView theme is dark and that is not the default.
+ DARK_THEME
+ else // The current WebView theme is light and that is not the default.
+ LIGHT_THEME
+