+ if (userAgentArrayPosition == MainWebViewActivity.DOMAINS_WEBVIEW_DEFAULT_USER_AGENT) { // The WebView default user agent is selected.
+ // Display the WebView default user agent.
+ userAgentTextView.setText(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.setText(userAgentDataArray[userAgentArrayPosition + 1]);
+ }
+ }
+
+ // Open the user agent spinner when the text view is clicked.
+ userAgentTextView.setOnClickListener((View v) -> {
+ // Open the user agent spinner.
+ userAgentSpinner.performClick();
+ });
+
+ // Display the font size settings.
+ if (fontSizeInt == 0) { // `0` is the code for system default font size.
+ // Set the font size to the system default
+ fontSizeSpinner.setSelection(0);
+
+ // Show the default font size text view.
+ defaultFontSizeTextView.setVisibility(View.VISIBLE);
+
+ // Hide the custom font size edit text.
+ customFontSizeEditText.setVisibility(View.GONE);
+
+ // Set the default font size as the text of the custom font size edit text. This way, if the user switches to custom it will already be populated.
+ customFontSizeEditText.setText(defaultFontSizeString);
+ } else { // A custom font size is selected.
+ // Set the spinner to the custom font size.
+ fontSizeSpinner.setSelection(1);
+
+ // Hide the default font size text view.
+ defaultFontSizeTextView.setVisibility(View.GONE);
+
+ // Show the custom font size edit text.
+ customFontSizeEditText.setVisibility(View.GONE);
+
+ // Set the custom font size.
+ customFontSizeEditText.setText(String.valueOf(fontSizeInt));
+ }
+
+ // Initialize the default font size percentage string.
+ String defaultFontSizePercentageString = defaultFontSizeString + "%";
+
+ // Set the default font size text in the text view.
+ defaultFontSizeTextView.setText(defaultFontSizePercentageString);
+
+ // Open the font size spinner when the text view is clicked.
+ defaultFontSizeTextView.setOnClickListener((View v) -> {
+ // Open the user agent spinner.
+ fontSizeSpinner.performClick();
+ });
+
+ // Select the swipe to refresh selection in the spinner.
+ swipeToRefreshSpinner.setSelection(swipeToRefreshInt);
+
+ // Set the swipe to refresh text.
+ if (defaultSwipeToRefresh) {
+ swipeToRefreshTextView.setText(swipeToRefreshArrayAdapter.getItem(DomainsDatabaseHelper.ENABLED));
+ } else {
+ swipeToRefreshTextView.setText(swipeToRefreshArrayAdapter.getItem(DomainsDatabaseHelper.DISABLED));
+ }
+
+ // Set the swipe to refresh icon and TextView settings. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
+ switch (swipeToRefreshInt) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT:
+ if (defaultSwipeToRefresh) { // Swipe to refresh is enabled by default.
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_night));
+ } else {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_day));
+ }
+ } else { // Swipe to refresh is disabled by default
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_night));
+ } else {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_day));
+ }
+ }
+
+ // Show the swipe to refresh TextView.
+ swipeToRefreshTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.ENABLED:
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_night));
+ } else {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_day));
+ }
+
+ // Hide the swipe to refresh TextView.`
+ swipeToRefreshTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.DISABLED:
+ // Set the icon according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_night));
+ } else {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_day));
+ }
+
+ // Hide the swipe to refresh TextView.
+ swipeToRefreshTextView.setVisibility(View.GONE);
+ }
+
+ // Open the swipe to refresh spinner when the TextView is clicked.
+ swipeToRefreshTextView.setOnClickListener((View v) -> {
+ // Open the swipe to refresh spinner.
+ swipeToRefreshSpinner.performClick();
+ });
+
+ // Get the WebView theme string arrays.
+ String[] webViewThemeStringArray = resources.getStringArray(R.array.webview_theme_array);
+ String[] webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values);
+
+ // Define an app WebView theme entry number.
+ int appWebViewThemeEntryNumber;
+
+ // Get the WebView theme entry number that matches the current WebView theme. A switch statement cannot be used because the WebView theme entry values string array is not a compile time constant.
+ if (defaultWebViewTheme.equals(webViewThemeEntryValuesStringArray[1])) { // The light theme is selected.
+ // Store the default WebView theme entry number.
+ appWebViewThemeEntryNumber = 1;
+ } else if (defaultWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected.
+ // Store the default WebView theme entry number.
+ appWebViewThemeEntryNumber = 2;
+ } else { // The system default theme is selected.
+ // Store the default WebView theme entry number.
+ appWebViewThemeEntryNumber = 0;
+ }
+
+ // Set the WebView theme visibility.
+ if (Build.VERSION.SDK_INT < 21) { // The WebView theme cannot be set on API 19.
+ // Get a handle for the webView theme linear layout.
+ LinearLayout webViewThemeLinearLayout = domainSettingsView.findViewById(R.id.webview_theme_linearlayout);
+
+ // Hide the WebView theme linear layout.
+ webViewThemeLinearLayout.setVisibility(View.GONE);
+ } else { // The WebView theme can be set on API >= 21.
+ // Select the WebView theme in the spinner.
+ webViewThemeSpinner.setSelection(webViewThemeInt);
+
+ // Set the WebView theme text.
+ if (appWebViewThemeEntryNumber == DomainsDatabaseHelper.SYSTEM_DEFAULT) { // The app WebView theme is system default.
+ // Set the text according to the current UI theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ webViewThemeTextView.setText(webViewThemeStringArray[DomainsDatabaseHelper.LIGHT_THEME]);
+ } else {
+ webViewThemeTextView.setText(webViewThemeStringArray[DomainsDatabaseHelper.DARK_THEME]);
+ }
+ } else { // The app WebView theme is not system default.
+ // Set the text according to the app WebView theme.
+ webViewThemeTextView.setText(webViewThemeStringArray[appWebViewThemeEntryNumber]);
+ }
+
+ // Set the WebView theme icon and text visibility. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
+ switch (webViewThemeInt) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT: // The domain WebView theme is system default.
+ // Set the icon according to the app WebView theme.
+ switch (appWebViewThemeEntryNumber) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT: // The default WebView theme is system default.
+ // Set the icon according to the app theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ // Set the light mode icon.
+ webViewThemeImageView.setImageDrawable(resources.getDrawable(R.drawable.webview_light_theme_day));
+ } else {
+ // Set the dark theme icon.
+ webViewThemeImageView.setImageDrawable(resources.getDrawable(R.drawable.webview_dark_theme_night));
+ }