X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Ffragments%2FDomainSettingsFragment.java;h=35d626935039f0c5a151df734ba148bf83d53c58;hp=5386b77dbb2135b9f7e76d469d700df9af7a9d37;hb=b82022327701273b1b56419e8d6042895c0bc7b9;hpb=5ec8d4fbc50f8fc88e883086fbce0e7c041c5527 diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java index 5386b77d..35d62693 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java @@ -1,5 +1,5 @@ /* - * Copyright © 2017-2019 Soren Stoutner . + * Copyright © 2017-2020 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -22,6 +22,7 @@ package com.stoutner.privacybrowser.fragments; import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; import android.os.Build; @@ -43,12 +44,14 @@ import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RadioButton; +import android.widget.ScrollView; import android.widget.Spinner; -import android.widget.Switch; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.appcompat.widget.SwitchCompat; import androidx.cardview.widget.CardView; +import androidx.core.content.res.ResourcesCompat; import androidx.fragment.app.Fragment; // The AndroidX fragment must be used until minimum API >= 23. Otherwise `getContext()` does not work. import com.stoutner.privacybrowser.R; @@ -61,12 +64,16 @@ import java.util.Calendar; import java.util.Date; public class DomainSettingsFragment extends Fragment { - // `DATABASE_ID` is used by activities calling this fragment. + // Initialize the public class constants. These are used by activities calling this fragment. public static final String DATABASE_ID = "database_id"; + public static final String SCROLL_Y = "scroll_y"; - // `databaseId` is public static so it can be accessed from `DomainsActivity`. It is also used in `onCreate()` and `onCreateView()`. + // Define the public variables. `databaseId` is public static so it can be accessed from `DomainsActivity`. It is also used in `onCreate()` and `onCreateView()`. public static int databaseId; + // Define the class variables. + private int scrollY; + @Override public void onCreate(Bundle savedInstanceState) { // Run the default commands. @@ -77,6 +84,7 @@ public class DomainSettingsFragment extends Fragment { // Store the database id in `databaseId`. databaseId = getArguments().getInt(DATABASE_ID); + scrollY = getArguments().getInt(SCROLL_Y); } // The deprecated `getDrawable()` must be used until the minimum API >= 21. @@ -85,13 +93,16 @@ public class DomainSettingsFragment extends Fragment { // Inflate `domain_settings_fragment`. `false` does not attach it to the root `container`. View domainSettingsView = inflater.inflate(R.layout.domain_settings_fragment, container, false); - // Get a handle for the context and the resources. + // Get handles for the context and the resources. Context context = getContext(); Resources resources = getResources(); // Remove the error below that the context might be null. assert context != null; + // Get the current theme status. + int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + // Get a handle for the shared preference. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); @@ -100,47 +111,50 @@ public class DomainSettingsFragment extends Fragment { String defaultCustomUserAgentString = sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)); String defaultFontSizeString = sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)); boolean defaultSwipeToRefresh = sharedPreferences.getBoolean("swipe_to_refresh", true); - boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false); - boolean defaultNightMode = sharedPreferences.getBoolean("night_mode", false); + String defaultWebViewTheme = sharedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value)); boolean defaultWideViewport = sharedPreferences.getBoolean("wide_viewport", true); boolean defaultDisplayWebpageImages = sharedPreferences.getBoolean("display_webpage_images", true); - // Get handles for the views in the fragment. + // Get handles for the views. + ScrollView domainSettingsScrollView = domainSettingsView.findViewById(R.id.domain_settings_scrollview); EditText domainNameEditText = domainSettingsView.findViewById(R.id.domain_settings_name_edittext); - Switch javaScriptEnabledSwitch = domainSettingsView.findViewById(R.id.javascript_switch); ImageView javaScriptImageView = domainSettingsView.findViewById(R.id.javascript_imageview); - Switch firstPartyCookiesEnabledSwitch = domainSettingsView.findViewById(R.id.first_party_cookies_switch); + SwitchCompat javaScriptSwitch = domainSettingsView.findViewById(R.id.javascript_switch); ImageView firstPartyCookiesImageView = domainSettingsView.findViewById(R.id.first_party_cookies_imageview); + SwitchCompat firstPartyCookiesSwitch = domainSettingsView.findViewById(R.id.first_party_cookies_switch); LinearLayout thirdPartyCookiesLinearLayout = domainSettingsView.findViewById(R.id.third_party_cookies_linearlayout); - Switch thirdPartyCookiesEnabledSwitch = domainSettingsView.findViewById(R.id.third_party_cookies_switch); ImageView thirdPartyCookiesImageView = domainSettingsView.findViewById(R.id.third_party_cookies_imageview); - Switch domStorageEnabledSwitch = domainSettingsView.findViewById(R.id.dom_storage_switch); + SwitchCompat thirdPartyCookiesSwitch = domainSettingsView.findViewById(R.id.third_party_cookies_switch); ImageView domStorageImageView = domainSettingsView.findViewById(R.id.dom_storage_imageview); - Switch formDataEnabledSwitch = domainSettingsView.findViewById(R.id.form_data_switch); // The form data views can be remove once the minimum API >= 26. + SwitchCompat domStorageSwitch = domainSettingsView.findViewById(R.id.dom_storage_switch); ImageView formDataImageView = domainSettingsView.findViewById(R.id.form_data_imageview); // The form data views can be remove once the minimum API >= 26. - Switch easyListSwitch = domainSettingsView.findViewById(R.id.easylist_switch); + SwitchCompat formDataSwitch = domainSettingsView.findViewById(R.id.form_data_switch); // The form data views can be remove once the minimum API >= 26. ImageView easyListImageView = domainSettingsView.findViewById(R.id.easylist_imageview); - Switch easyPrivacySwitch = domainSettingsView.findViewById(R.id.easyprivacy_switch); + SwitchCompat easyListSwitch = domainSettingsView.findViewById(R.id.easylist_switch); ImageView easyPrivacyImageView = domainSettingsView.findViewById(R.id.easyprivacy_imageview); - Switch fanboysAnnoyanceListSwitch = domainSettingsView.findViewById(R.id.fanboys_annoyance_list_switch); + SwitchCompat easyPrivacySwitch = domainSettingsView.findViewById(R.id.easyprivacy_switch); ImageView fanboysAnnoyanceListImageView = domainSettingsView.findViewById(R.id.fanboys_annoyance_list_imageview); - Switch fanboysSocialBlockingListSwitch = domainSettingsView.findViewById(R.id.fanboys_social_blocking_list_switch); + SwitchCompat fanboysAnnoyanceListSwitch = domainSettingsView.findViewById(R.id.fanboys_annoyance_list_switch); ImageView fanboysSocialBlockingListImageView = domainSettingsView.findViewById(R.id.fanboys_social_blocking_list_imageview); - Switch ultraPrivacySwitch = domainSettingsView.findViewById(R.id.ultraprivacy_switch); + SwitchCompat fanboysSocialBlockingListSwitch = domainSettingsView.findViewById(R.id.fanboys_social_blocking_list_switch); + ImageView ultraListImageView = domainSettingsView.findViewById(R.id.ultralist_imageview); + SwitchCompat ultraListSwitch = domainSettingsView.findViewById(R.id.ultralist_switch); ImageView ultraPrivacyImageView = domainSettingsView.findViewById(R.id.ultraprivacy_imageview); - Switch blockAllThirdPartyRequestsSwitch = domainSettingsView.findViewById(R.id.block_all_third_party_requests_switch); + SwitchCompat ultraPrivacySwitch = domainSettingsView.findViewById(R.id.ultraprivacy_switch); ImageView blockAllThirdPartyRequestsImageView = domainSettingsView.findViewById(R.id.block_all_third_party_requests_imageview); + SwitchCompat blockAllThirdPartyRequestsSwitch = domainSettingsView.findViewById(R.id.block_all_third_party_requests_switch); Spinner userAgentSpinner = domainSettingsView.findViewById(R.id.user_agent_spinner); TextView userAgentTextView = domainSettingsView.findViewById(R.id.user_agent_textview); EditText customUserAgentEditText = domainSettingsView.findViewById(R.id.custom_user_agent_edittext); Spinner fontSizeSpinner = domainSettingsView.findViewById(R.id.font_size_spinner); - TextView fontSizeTextView = domainSettingsView.findViewById(R.id.font_size_textview); + TextView defaultFontSizeTextView = domainSettingsView.findViewById(R.id.default_font_size_textview); + EditText customFontSizeEditText = domainSettingsView.findViewById(R.id.custom_font_size_edittext); ImageView swipeToRefreshImageView = domainSettingsView.findViewById(R.id.swipe_to_refresh_imageview); Spinner swipeToRefreshSpinner = domainSettingsView.findViewById(R.id.swipe_to_refresh_spinner); TextView swipeToRefreshTextView = domainSettingsView.findViewById(R.id.swipe_to_refresh_textview); - ImageView nightModeImageView = domainSettingsView.findViewById(R.id.night_mode_imageview); - Spinner nightModeSpinner = domainSettingsView.findViewById(R.id.night_mode_spinner); - TextView nightModeTextView = domainSettingsView.findViewById(R.id.night_mode_textview); + ImageView webViewThemeImageView = domainSettingsView.findViewById(R.id.webview_theme_imageview); + Spinner webViewThemeSpinner = domainSettingsView.findViewById(R.id.webview_theme_spinner); + TextView webViewThemeTextView = domainSettingsView.findViewById(R.id.webview_theme_textview); ImageView wideViewportImageView = domainSettingsView.findViewById(R.id.wide_viewport_imageview); Spinner wideViewportSpinner = domainSettingsView.findViewById(R.id.wide_viewport_spinner); TextView wideViewportTextView = domainSettingsView.findViewById(R.id.wide_viewport_textview); @@ -148,7 +162,7 @@ public class DomainSettingsFragment extends Fragment { Spinner displayWebpageImagesSpinner = domainSettingsView.findViewById(R.id.display_webpage_images_spinner); TextView displayImagesTextView = domainSettingsView.findViewById(R.id.display_webpage_images_textview); ImageView pinnedSslCertificateImageView = domainSettingsView.findViewById(R.id.pinned_ssl_certificate_imageview); - Switch pinnedSslCertificateSwitch = domainSettingsView.findViewById(R.id.pinned_ssl_certificate_switch); + SwitchCompat pinnedSslCertificateSwitch = domainSettingsView.findViewById(R.id.pinned_ssl_certificate_switch); CardView savedSslCardView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_cardview); LinearLayout savedSslCertificateLinearLayout = domainSettingsView.findViewById(R.id.saved_ssl_certificate_linearlayout); RadioButton savedSslCertificateRadioButton = domainSettingsView.findViewById(R.id.saved_ssl_certificate_radiobutton); @@ -173,7 +187,7 @@ public class DomainSettingsFragment extends Fragment { TextView currentSslEndDateTextView = domainSettingsView.findViewById(R.id.current_website_certificate_end_date); TextView noCurrentWebsiteCertificateTextView = domainSettingsView.findViewById(R.id.no_current_website_certificate); ImageView pinnedIpAddressesImageView = domainSettingsView.findViewById(R.id.pinned_ip_addresses_imageview); - Switch pinnedIpAddressesSwitch = domainSettingsView.findViewById(R.id.pinned_ip_addresses_switch); + SwitchCompat pinnedIpAddressesSwitch = domainSettingsView.findViewById(R.id.pinned_ip_addresses_switch); CardView savedIpAddressesCardView = domainSettingsView.findViewById(R.id.saved_ip_addresses_cardview); LinearLayout savedIpAddressesLinearLayout = domainSettingsView.findViewById(R.id.saved_ip_addresses_linearlayout); RadioButton savedIpAddressesRadioButton = domainSettingsView.findViewById(R.id.saved_ip_addresses_radiobutton); @@ -199,21 +213,22 @@ public class DomainSettingsFragment extends Fragment { // Save the cursor entries as variables. String domainNameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME)); - int javaScriptEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)); - int firstPartyCookiesEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)); - int thirdPartyCookiesEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)); - int domStorageEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)); - int formDataEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)); // Form data can be remove once the minimum API >= 26. - int easyListEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYLIST)); - int easyPrivacyEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYPRIVACY)); + int javaScriptInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)); + int firstPartyCookiesInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)); + int thirdPartyCookiesInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)); + int domStorageInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)); + int formDataInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)); // Form data can be remove once the minimum API >= 26. + int easyListInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYLIST)); + int easyPrivacyInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYPRIVACY)); int fanboysAnnoyanceListInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST)); int fanboysSocialBlockingListInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST)); - int ultraPrivacyEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY)); + int ultraListInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ULTRALIST)); + int ultraPrivacyInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY)); int blockAllThirdPartyRequestsInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS)); String currentUserAgentName = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.USER_AGENT)); int fontSizeInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.FONT_SIZE)); int swipeToRefreshInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.SWIPE_TO_REFRESH)); - int nightModeInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.NIGHT_MODE)); + int webViewThemeInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.WEBVIEW_THEME)); int wideViewportInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.WIDE_VIEWPORT)); int displayImagesInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.DISPLAY_IMAGES)); int pinnedSslCertificateInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE)); @@ -241,10 +256,9 @@ public class DomainSettingsFragment extends Fragment { // Create array adapters for the spinners. ArrayAdapter translatedUserAgentArrayAdapter = ArrayAdapter.createFromResource(context, R.array.translated_domain_settings_user_agent_names, R.layout.spinner_item); - ArrayAdapter fontSizeArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_font_size_entries, R.layout.spinner_item); - ArrayAdapter fontSizeEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_font_size_entry_values, R.layout.spinner_item); + ArrayAdapter fontSizeArrayAdapter = ArrayAdapter.createFromResource(context, R.array.font_size_array, R.layout.spinner_item); ArrayAdapter swipeToRefreshArrayAdapter = ArrayAdapter.createFromResource(context, R.array.swipe_to_refresh_array, R.layout.spinner_item); - ArrayAdapter nightModeArrayAdapter = ArrayAdapter.createFromResource(context, R.array.night_mode_array, R.layout.spinner_item); + ArrayAdapter webViewThemeArrayAdapter = ArrayAdapter.createFromResource(context, R.array.webview_theme_array, R.layout.spinner_item); ArrayAdapter wideViewportArrayAdapter = ArrayAdapter.createFromResource(context, R.array.wide_viewport_array, R.layout.spinner_item); ArrayAdapter displayImagesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.display_webpage_images_array, R.layout.spinner_item); @@ -252,7 +266,7 @@ public class DomainSettingsFragment extends Fragment { translatedUserAgentArrayAdapter.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); - nightModeArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_items); + webViewThemeArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_items); wideViewportArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_items); displayImagesArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_items); @@ -260,7 +274,7 @@ public class DomainSettingsFragment extends Fragment { userAgentSpinner.setAdapter(translatedUserAgentArrayAdapter); fontSizeSpinner.setAdapter(fontSizeArrayAdapter); swipeToRefreshSpinner.setAdapter(swipeToRefreshArrayAdapter); - nightModeSpinner.setAdapter(nightModeArrayAdapter); + webViewThemeSpinner.setAdapter(webViewThemeArrayAdapter); wideViewportSpinner.setAdapter(wideViewportArrayAdapter); displayWebpageImagesSpinner.setAdapter(displayImagesArrayAdapter); @@ -289,16 +303,16 @@ public class DomainSettingsFragment extends Fragment { savedSslEndDateStringBuilder = new SpannableStringBuilder(endDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(savedSslEndDate)); } - // Create a red foreground color span. The deprecated `resources.getColor` must be used until the minimum API >= 23. - final ForegroundColorSpan redColorSpan = new ForegroundColorSpan(resources.getColor(R.color.red_a700)); - - // Create a blue foreground color span. + // Create the foreground color spans. + final ForegroundColorSpan redColorSpan; final ForegroundColorSpan blueColorSpan; - // Set the blue color span according to the theme. The deprecated `resources.getColor` must be used until the minimum API >= 23. - if (darkTheme) { - blueColorSpan = new ForegroundColorSpan(resources.getColor(R.color.blue_400)); + // Set the color spans according to the theme. The deprecated `resources` must be used until the minimum API >= 23. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + redColorSpan = new ForegroundColorSpan(resources.getColor(R.color.red_900)); + blueColorSpan = new ForegroundColorSpan(resources.getColor(R.color.violet_500)); } else { + redColorSpan = new ForegroundColorSpan(resources.getColor(R.color.red_a700)); blueColorSpan = new ForegroundColorSpan(resources.getColor(R.color.blue_700)); } @@ -359,79 +373,68 @@ public class DomainSettingsFragment extends Fragment { } }); - // Create a boolean to track if night mode is enabled. - boolean nightModeEnabled = (nightModeInt == DomainsDatabaseHelper.ENABLED) || ((nightModeInt == DomainsDatabaseHelper.SYSTEM_DEFAULT) && defaultNightMode); - - // Disable the JavaScript switch if night mode is enabled. - if (nightModeEnabled) { - javaScriptEnabledSwitch.setEnabled(false); - } else { - javaScriptEnabledSwitch.setEnabled(true); - } - - // Set the JavaScript icon. - if ((javaScriptEnabledInt == 1) || nightModeEnabled) { - javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.javascript_enabled)); - } else { - javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.privacy_mode)); - } - // Set the JavaScript switch status. - if (javaScriptEnabledInt == 1) { // JavaScript is enabled. - javaScriptEnabledSwitch.setChecked(true); + if (javaScriptInt == 1) { // JavaScript is enabled. + javaScriptSwitch.setChecked(true); + javaScriptImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.javascript_enabled, null)); } else { // JavaScript is disabled. - javaScriptEnabledSwitch.setChecked(false); + javaScriptSwitch.setChecked(false); + javaScriptImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.privacy_mode, null)); } // Set the first-party cookies status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. - if (firstPartyCookiesEnabledInt == 1) { // First-party cookies are enabled. - firstPartyCookiesEnabledSwitch.setChecked(true); - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_enabled)); + if (firstPartyCookiesInt == 1) { // First-party cookies are enabled. + firstPartyCookiesSwitch.setChecked(true); + firstPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_enabled, null)); } else { // First-party cookies are disabled. - firstPartyCookiesEnabledSwitch.setChecked(false); + firstPartyCookiesSwitch.setChecked(false); // Set the icon according to the theme. - if (darkTheme) { - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + firstPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_night, null)); } else { - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light)); + firstPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_day, null)); } } // Only display third-party cookies if SDK_INT >= 21. if (Build.VERSION.SDK_INT >= 21) { // Third-party cookies can be configured for API >= 21. // Only enable third-party-cookies if first-party cookies are enabled. - if (firstPartyCookiesEnabledInt == 1) { // First-party cookies are enabled. + if (firstPartyCookiesInt == 1) { // First-party cookies are enabled. // Set the third-party cookies status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. - if (thirdPartyCookiesEnabledInt == 1) { // Both first-party and third-party cookies are enabled. - thirdPartyCookiesEnabledSwitch.setChecked(true); - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_warning)); + if (thirdPartyCookiesInt == 1) { // Both first-party and third-party cookies are enabled. + // Set the third-party cookies switch to be checked. + thirdPartyCookiesSwitch.setChecked(true); + + // Set the icon to be red. + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_warning, null)); } else { // First party cookies are enabled but third-party cookies are disabled. - thirdPartyCookiesEnabledSwitch.setChecked(false); + // Set the third-party cookies switch to be checked. + thirdPartyCookiesSwitch.setChecked(false); // Set the icon according to the theme. - if (darkTheme) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_night, null)); } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light)); + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_day, null)); } } } else { // First-party cookies are disabled. // Set the status of third-party cookies. - if (thirdPartyCookiesEnabledInt == 1) { - thirdPartyCookiesEnabledSwitch.setChecked(true); + if (thirdPartyCookiesInt == 1) { + thirdPartyCookiesSwitch.setChecked(true); } else { - thirdPartyCookiesEnabledSwitch.setChecked(false); + thirdPartyCookiesSwitch.setChecked(false); } // Disable the third-party cookies switch. - thirdPartyCookiesEnabledSwitch.setEnabled(false); + thirdPartyCookiesSwitch.setEnabled(false); // Set the icon according to the theme. - if (darkTheme) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_ghosted_night, null)); } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_light)); + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_ghosted_day, null)); } } } else { // Third-party cookies cannot be configured for API <= 21. @@ -440,108 +443,112 @@ public class DomainSettingsFragment extends Fragment { } // Only enable DOM storage if JavaScript is enabled. - if ((javaScriptEnabledInt == 1) || nightModeEnabled) { // JavaScript is enabled. + if (javaScriptInt == 1) { // JavaScript is enabled. // Enable the DOM storage `Switch`. - domStorageEnabledSwitch.setEnabled(true); + domStorageSwitch.setEnabled(true); // Set the DOM storage status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. - if (domStorageEnabledInt == 1) { // Both JavaScript and DOM storage are enabled. - domStorageEnabledSwitch.setChecked(true); - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled)); + if (domStorageInt == 1) { // Both JavaScript and DOM storage are enabled. + domStorageSwitch.setChecked(true); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_enabled, null)); } else { // JavaScript is enabled but DOM storage is disabled. // Set the DOM storage switch to off. - domStorageEnabledSwitch.setChecked(false); + domStorageSwitch.setChecked(false); // Set the icon according to the theme. - if (darkTheme) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_night, null)); } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_day, null)); } } } else { // JavaScript is disabled. // Disable the DOM storage `Switch`. - domStorageEnabledSwitch.setEnabled(false); + domStorageSwitch.setEnabled(false); // Set the checked status of DOM storage. - if (domStorageEnabledInt == 1) { // DOM storage is enabled but JavaScript is disabled. - domStorageEnabledSwitch.setChecked(true); + if (domStorageInt == 1) { // DOM storage is enabled but JavaScript is disabled. + domStorageSwitch.setChecked(true); } else { // Both JavaScript and DOM storage are disabled. - domStorageEnabledSwitch.setChecked(false); + domStorageSwitch.setChecked(false); } // Set the icon according to the theme. - if (darkTheme) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_ghosted_night, null)); } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_light)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_ghosted_day, null)); } } - // Set the form data status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. Form data can be removed once the minimum API >= 26. + // Set the form data visibility. Form data can be removed once the minimum API >= 26. if (Build.VERSION.SDK_INT >= 26) { // Form data no longer applies to newer versions of Android. - // Hide the form data switch. - formDataEnabledSwitch.setVisibility(View.GONE); + // Hide the form data image view and switch. + formDataImageView.setVisibility(View.GONE); + formDataSwitch.setVisibility(View.GONE); } else { // Form data should be displayed because this is an older version of Android. - if (formDataEnabledInt == 1) { // Form data is on. - formDataEnabledSwitch.setChecked(true); - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_enabled)); + if (formDataInt == 1) { // Form data is on. + // Turn the form data switch on. + formDataSwitch.setChecked(true); + + // Set the form data icon. + formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_enabled, null)); } else { // Form data is off. // Turn the form data switch to off. - formDataEnabledSwitch.setChecked(false); + formDataSwitch.setChecked(false); - // Set the icon according to the theme. - if (darkTheme) { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_dark)); + // Set the icon according to the theme. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_disabled_night, null)); } else { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_light)); + formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_disabled_day, null)); } } } // Set the EasyList status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. - if (easyListEnabledInt == 1) { // EasyList is on. + if (easyListInt == 1) { // EasyList is on. // Turn the switch on. easyListSwitch.setChecked(true); // Set the icon according to the theme. - if (darkTheme) { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_night, null)); } else { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_light)); + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_day, null)); } } else { // EasyList is off. // Turn the switch off. easyListSwitch.setChecked(false); // Set the icon according to the theme. - if (darkTheme) { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_night, null)); } else { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_light)); + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_day, null)); } } // Set the EasyPrivacy status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. - if (easyPrivacyEnabledInt == 1) { // EasyPrivacy is on. + if (easyPrivacyInt == 1) { // EasyPrivacy is on. // Turn the switch on. easyPrivacySwitch.setChecked(true); // Set the icon according to the theme. - if (darkTheme) { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_night, null)); } else { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_light)); + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_day, null)); } } else { // EasyPrivacy is off. // Turn the switch off. easyPrivacySwitch.setChecked(false); // Set the icon according to the theme. - if (darkTheme) { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_night, null)); } else { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_light)); + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_day, null)); } } @@ -551,89 +558,114 @@ public class DomainSettingsFragment extends Fragment { fanboysAnnoyanceListSwitch.setChecked(true); // Set the icon according to the theme. - if (darkTheme) { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null)); } else { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light)); + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_day, null)); } } else { // Fanboy's Annoyance List is off. // Turn the switch off. fanboysAnnoyanceListSwitch.setChecked(false); // Set the icon according to the theme. - if (darkTheme) { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null)); } else { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light)); + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_day, null)); } } // Only enable Fanboy's Social Blocking List if Fanboy's Annoyance List is off. if (fanboysAnnoyanceListInt == 0) { // Fanboy's Annoyance List is on. + // Enable Fanboy's Social Blocking List switch. + fanboysSocialBlockingListSwitch.setEnabled(true); + // Enable Fanboy's Social Blocking List. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. if (fanboysSocialBlockingListInt == 1) { // Fanboy's Social Blocking List is on. - // Enable the switch and turn it on. - fanboysSocialBlockingListSwitch.setEnabled(true); + // Turn on Fanboy's Social Blocking List switch. fanboysSocialBlockingListSwitch.setChecked(true); // Set the icon according to the theme. - if (darkTheme) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_day, null)); } } else { // Fanboy's Social Blocking List is off. - // Enable the switch but turn it off. - fanboysSocialBlockingListSwitch.setEnabled(true); + // Turn off Fanboy's Social Blocking List switch. fanboysSocialBlockingListSwitch.setChecked(false); // Set the icon according to the theme. - if (darkTheme) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_day, null)); } } } else { // Fanboy's Annoyance List is on. - // Disable Fanboy's Social Blocking List. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. + // Disable Fanboy's Social Blocking List switch. + fanboysSocialBlockingListSwitch.setEnabled(false); + + // Handle the status of Fanboy's Social Blocking List. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. if (fanboysSocialBlockingListInt == 1) { // Fanboy's Social Blocking List is on. - // Disable the switch but turn it on. - fanboysSocialBlockingListSwitch.setEnabled(false); + // Turn on Fanboy's Social Blocking List switch. fanboysSocialBlockingListSwitch.setChecked(true); } else { // Fanboy's Social Blocking List is off. - // Disable the switch and turn it off. - fanboysSocialBlockingListSwitch.setEnabled(false); + // Turn off Fanboy's Social Blocking List switch. fanboysSocialBlockingListSwitch.setChecked(false); } // Set the icon according to the theme. - if (darkTheme) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_ghosted_night, null)); + } else { + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_ghosted_day, null)); + } + } + + // Set the UltraList status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. + if (ultraListInt == 1) { // UltraList is on. + // Turn the switch on. + ultraListSwitch.setChecked(true); + + // Set the icon according to the theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_night, null)); + } else { + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_day, null)); + } + } else { // UltraList is off. + // Turn the switch off. + ultraListSwitch.setChecked(false); + + // Set the icon according to the theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_light)); + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_day, null)); } } // Set the UltraPrivacy status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. - if (ultraPrivacyEnabledInt == 1) { // UltraPrivacy is on. + if (ultraPrivacyInt == 1) { // UltraPrivacy is on. // Turn the switch on. ultraPrivacySwitch.setChecked(true); // Set the icon according to the theme. - if (darkTheme) { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_night, null)); } else { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_light)); + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_day, null)); } } else { // EasyPrivacy is off. // Turn the switch off. ultraPrivacySwitch.setChecked(false); // Set the icon according to the theme. - if (darkTheme) { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_night, null)); } else { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_light)); + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_day, null)); } } @@ -643,20 +675,20 @@ public class DomainSettingsFragment extends Fragment { blockAllThirdPartyRequestsSwitch.setChecked(true); // Set the icon according to the theme. - if (darkTheme) { - blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_enabled_night, null)); } else { - blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_enabled_light)); + blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_enabled_day, null)); } } else { // Blocking all third-party requests is off. // Turn the switch off. blockAllThirdPartyRequestsSwitch.setChecked(false); // Set the icon according to the theme. - if (darkTheme) { - blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_disabled_night, null)); } else { - blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_disabled_light)); + blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_disabled_day, null)); } } @@ -735,28 +767,46 @@ public class DomainSettingsFragment extends Fragment { userAgentSpinner.performClick(); }); - // Set the selected font size. - int fontSizeArrayPosition = fontSizeEntryValuesArrayAdapter.getPosition(String.valueOf(fontSizeInt)); - fontSizeSpinner.setSelection(fontSizeArrayPosition); + // 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); - // Set the default font size text. - int defaultFontSizeArrayPosition = fontSizeEntryValuesArrayAdapter.getPosition(defaultFontSizeString); - fontSizeTextView.setText(fontSizeArrayAdapter.getItem(defaultFontSizeArrayPosition)); + // Hide the custom font size edit text. + customFontSizeEditText.setVisibility(View.GONE); - // Set the display options for the font size TextView. - if (fontSizeArrayPosition == 0) { // System default font size is selected. Display `fontSizeTextView`. - fontSizeTextView.setVisibility(View.VISIBLE); - } else { // A custom font size is specified. Hide `fontSizeTextView`. - fontSizeTextView.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)); } - // Open the font size spinner when the TextView is clicked. - fontSizeTextView.setOnClickListener((View v) -> { + // 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(); }); - // Display the swipe to refresh selection in the spinner. + // Select the swipe to refresh selection in the spinner. swipeToRefreshSpinner.setSelection(swipeToRefreshInt); // Set the swipe to refresh text. @@ -771,17 +821,17 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.SYSTEM_DEFAULT: if (defaultSwipeToRefresh) { // Swipe to refresh is enabled by default. // Set the icon according to the theme. - if (darkTheme) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_light)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_day, null)); } } else { // Swipe to refresh is disabled by default // Set the icon according to the theme. - if (darkTheme) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_light)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_day, null)); } } @@ -791,10 +841,10 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.ENABLED: // Set the icon according to the theme. - if (darkTheme) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_light)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_day, null)); } // Hide the swipe to refresh TextView.` @@ -803,14 +853,15 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.DISABLED: // Set the icon according to the theme. - if (darkTheme) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_light)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_day, null)); } // Hide the swipe to refresh TextView. swipeToRefreshTextView.setVisibility(View.GONE); + break; } // Open the swipe to refresh spinner when the TextView is clicked. @@ -819,71 +870,120 @@ public class DomainSettingsFragment extends Fragment { swipeToRefreshSpinner.performClick(); }); - // Display the night mode in the spinner. - nightModeSpinner.setSelection(nightModeInt); - - // Set the default night mode text. - if (defaultNightMode) { - nightModeTextView.setText(nightModeArrayAdapter.getItem(DomainsDatabaseHelper.ENABLED)); - } else { - nightModeTextView.setText(nightModeArrayAdapter.getItem(DomainsDatabaseHelper.DISABLED)); + // 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 night mode icon and TextView settings. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. - switch (nightModeInt) { - case DomainsDatabaseHelper.SYSTEM_DEFAULT: - if (defaultNightMode) { // Night mode enabled by default. - // Set the icon according to the theme. - if (darkTheme) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark)); - } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light)); + // 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(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null)); + } else { + // Set the dark theme icon. + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); + } + break; + + case DomainsDatabaseHelper.LIGHT_THEME: // the default WebView theme is light. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null)); + } else { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_night, null)); + } + break; + + case DomainsDatabaseHelper.DARK_THEME: // the default WebView theme is dark. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_day, null)); + } else { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); } + break; } - } else { // Night mode disabled by default. - // Set the icon according to the theme. - if (darkTheme) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark)); + + // Show the WebView theme text view. + webViewThemeTextView.setVisibility(View.VISIBLE); + break; + + case DomainsDatabaseHelper.LIGHT_THEME: // The domain WebView theme is light. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null)); } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light)); + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_night, null)); } - } - // Show night mode TextView. - nightModeTextView.setVisibility(View.VISIBLE); - break; - - case DomainsDatabaseHelper.ENABLED: - // Set the icon according to the theme. - if (darkTheme) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark)); - } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light)); - } + // Hide the WebView theme text view. + webViewThemeTextView.setVisibility(View.GONE); + break; - // Hide the night mode TextView. - nightModeTextView.setVisibility(View.GONE); - break; + case DomainsDatabaseHelper.DARK_THEME: // The domain WebView theme is dark. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_day, null)); + } else { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); + } - case DomainsDatabaseHelper.DISABLED: - // Set the icon according to the theme. - if (darkTheme) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark)); - } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light)); - } + // Hide the WebView theme text view. + webViewThemeTextView.setVisibility(View.GONE); + break; + } - // Hide the night mode TextView. - nightModeTextView.setVisibility(View.GONE); - break; + // Open the WebView theme spinner when the text view is clicked. + webViewThemeTextView.setOnClickListener((View v) -> { + // Open the WebView theme spinner. + webViewThemeSpinner.performClick(); + }); } - // Open the night mode spinner when the TextView is clicked. - nightModeTextView.setOnClickListener((View v) -> { - // Open the night mode spinner. - nightModeSpinner.performClick(); - }); - - // Display the wide viewport in the spinner. + // Select the wide viewport in the spinner. wideViewportSpinner.setSelection(wideViewportInt); // Set the default wide viewport text. @@ -898,16 +998,16 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.SYSTEM_DEFAULT: if (defaultWideViewport) { // Wide viewport enabled by default. // Set the icon according to the theme. - if (darkTheme) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_light)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_day, null)); } } else { // Wide viewport disabled by default. - if (darkTheme) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_light)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_day, null)); } } @@ -917,10 +1017,10 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.ENABLED: // Set the icon according to the theme. - if (darkTheme) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_light)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_day, null)); } // Hide the wide viewport text view. @@ -929,10 +1029,10 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.DISABLED: // Set the icon according to the theme. - if (darkTheme) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_light)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_day, null)); } // Hide the wide viewport text view. @@ -961,17 +1061,17 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.SYSTEM_DEFAULT: if (defaultDisplayWebpageImages) { // Display webpage images enabled by default. // Set the icon according to the theme. - if (darkTheme) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_light)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_day, null)); } } else { // Display webpage images disabled by default. // Set the icon according to the theme. - if (darkTheme) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_light)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_day, null)); } } @@ -981,10 +1081,10 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.ENABLED: // Set the icon according to the theme. - if (darkTheme) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_light)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_day, null)); } // Hide the display images text view. @@ -993,10 +1093,10 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.DISABLED: // Set the icon according to the theme. - if (darkTheme) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_light)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_day, null)); } // Hide the display images text view. @@ -1016,20 +1116,20 @@ public class DomainSettingsFragment extends Fragment { pinnedSslCertificateSwitch.setChecked(true); // Set the icon according to the theme. - if (darkTheme) { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_night, null)); } else { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_light)); + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_day, null)); } } else { // Pinned SSL certificate is disabled. // Uncheck the switch. pinnedSslCertificateSwitch.setChecked(false); // Set the icon according to the theme. - if (darkTheme) { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_night, null)); } else { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_light)); + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_day, null)); } } @@ -1170,7 +1270,7 @@ public class DomainSettingsFragment extends Fragment { currentWebsiteCertificateRadioButton.setChecked(false); // Darken the background of the current website SSL certificate linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -1203,20 +1303,20 @@ public class DomainSettingsFragment extends Fragment { pinnedIpAddressesSwitch.setChecked(true); // Set the icon according to the theme. - if (darkTheme) { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_night, null)); } else { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_light)); + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_day, null)); } } else { // Pinned IP Addresses is disabled. // Uncheck the switch. pinnedIpAddressesSwitch.setChecked(false); // Set the icon according to the theme. - if (darkTheme) { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_night, null)); } else { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_light)); + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_day, null)); } } @@ -1245,7 +1345,7 @@ public class DomainSettingsFragment extends Fragment { currentIpAddressesRadioButton.setChecked(false); // Darken the background of the current IP addresses linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -1269,123 +1369,125 @@ public class DomainSettingsFragment extends Fragment { // Set the JavaScript switch listener. - javaScriptEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + javaScriptSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { if (isChecked) { // JavaScript is enabled. // Update the JavaScript icon. - javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.javascript_enabled)); + javaScriptImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.javascript_enabled, null)); // Enable the DOM storage `Switch`. - domStorageEnabledSwitch.setEnabled(true); + domStorageSwitch.setEnabled(true); // Update the DOM storage icon. - if (domStorageEnabledSwitch.isChecked()) { // DOM storage is enabled. - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled)); + if (domStorageSwitch.isChecked()) { // DOM storage is enabled. + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_enabled, null)); } else { // DOM storage is disabled. // Set the icon according to the theme. - if (darkTheme) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_night, null)); } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_day, null)); } } } else { // JavaScript is disabled. // Update the JavaScript icon. - javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.privacy_mode)); + javaScriptImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.privacy_mode, null)); // Disable the DOM storage `Switch`. - domStorageEnabledSwitch.setEnabled(false); + domStorageSwitch.setEnabled(false); // Set the DOM storage icon according to the theme. - if (darkTheme) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_ghosted_night, null)); } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_light)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_ghosted_day, null)); } } }); // Set the first-party cookies switch listener. - firstPartyCookiesEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + firstPartyCookiesSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { if (isChecked) { // First-party cookies are enabled. // Update the first-party cookies icon. - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_enabled)); + firstPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_enabled, null)); // Enable the third-party cookies switch. - thirdPartyCookiesEnabledSwitch.setEnabled(true); + thirdPartyCookiesSwitch.setEnabled(true); // Update the third-party cookies icon. - if (thirdPartyCookiesEnabledSwitch.isChecked()) { // Third-party cookies are enabled. - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_warning)); + if (thirdPartyCookiesSwitch.isChecked()) { // Third-party cookies are enabled. + // Set the third-party cookies icon to be red. + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_warning, null)); } else { // Third-party cookies are disabled. // Set the third-party cookies icon according to the theme. - if (darkTheme) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_night, null)); } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light)); + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_day, null)); } } } else { // First-party cookies are disabled. // Update the first-party cookies icon according to the theme. - if (darkTheme) { - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + firstPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_night, null)); } else { - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light)); + firstPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_day, null)); } // Disable the third-party cookies switch. - thirdPartyCookiesEnabledSwitch.setEnabled(false); + thirdPartyCookiesSwitch.setEnabled(false); // Set the third-party cookies icon according to the theme. - if (darkTheme) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_ghosted_night, null)); } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_light)); + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_ghosted_day, null)); } } }); // Set the third-party cookies switch listener. - thirdPartyCookiesEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + thirdPartyCookiesSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { // Update the icon. if (isChecked) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_warning)); + // Set the third-party cookies icon to be red. + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_warning, null)); } else { // Update the third-party cookies icon according to the theme. - if (darkTheme) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_night, null)); } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light)); + thirdPartyCookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_day, null)); } } }); // Set the DOM Storage switch listener. - domStorageEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + domStorageSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { // Update the icon. if (isChecked) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_enabled, null)); } else { // Set the icon according to the theme. - if (darkTheme) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_night, null)); } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_day, null)); } } }); // Set the form data switch listener. It can be removed once the minimum API >= 26. if (Build.VERSION.SDK_INT < 26) { - formDataEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + formDataSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { // Update the icon. if (isChecked) { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_enabled)); + formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_enabled, null)); } else { // Set the icon according to the theme. - if (darkTheme) { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_disabled_night, null)); } else { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_light)); + formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_disabled_day, null)); } } }); @@ -1396,17 +1498,17 @@ public class DomainSettingsFragment extends Fragment { // Update the icon. if (isChecked) { // EasyList is on. // Set the icon according to the theme. - if (darkTheme) { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_night, null)); } else { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_light)); + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_day, null)); } } else { // EasyList is off. // Set the icon according to the theme. - if (darkTheme) { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_night, null)); } else { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_light)); + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_day, null)); } } }); @@ -1416,17 +1518,17 @@ public class DomainSettingsFragment extends Fragment { // Update the icon. if (isChecked) { // EasyPrivacy is on. // Set the icon according to the theme. - if (darkTheme) { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_night, null)); } else { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_light)); + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_day, null)); } } else { // EasyPrivacy is off. // Set the icon according to the theme. - if (darkTheme) { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_night, null)); } else { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_light)); + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_day, null)); } } }); @@ -1436,27 +1538,27 @@ public class DomainSettingsFragment extends Fragment { // Update the icon and Fanboy's Social Blocking List. if (isChecked) { // Fanboy's Annoyance List is on. // Set the icon according to the theme. - if (darkTheme) { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null)); } else { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light)); + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_day, null)); } // Disable the Fanboy's Social Blocking List switch. fanboysSocialBlockingListSwitch.setEnabled(false); // Update the Fanboy's Social Blocking List icon according to the theme. - if (darkTheme) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_ghosted_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_light)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_ghosted_day, null)); } } else { // Fanboy's Annoyance List is off. // Set the icon according to the theme. - if (darkTheme) { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null)); } else { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light)); + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_day, null)); } // Enable the Fanboy's Social Blocking List switch. @@ -1465,17 +1567,17 @@ public class DomainSettingsFragment extends Fragment { // Update the Fanboy's Social Blocking List icon. if (fanboysSocialBlockingListSwitch.isChecked()) { // Fanboy's Social Blocking List is on. // Update the icon according to the theme. - if (darkTheme) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_day, null)); } } else { // Fanboy's Social Blocking List is off. // Update the icon according to the theme. - if (darkTheme) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_day, null)); } } } @@ -1487,17 +1589,37 @@ public class DomainSettingsFragment extends Fragment { // Update the icon. if (isChecked) { // Fanboy's Social Blocking List is on. // Set the icon according to the theme. - if (darkTheme) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_day, null)); } } else { // Fanboy's Social Blocking List is off. // Set the icon according to the theme. - if (darkTheme) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_day, null)); + } + } + }); + + // Set the UltraList switch listener. + ultraListSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + // Update the icon. + if (isChecked) { // UltraList is on. + // Set the icon according to the theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_night, null)); + } else { + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_day, null)); + } + } else { // UltraList is off. + // Set the icon according to the theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_night, null)); + } else { + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_day, null)); } } }); @@ -1507,17 +1629,17 @@ public class DomainSettingsFragment extends Fragment { // Update the icon. if (isChecked) { // UltraPrivacy is on. // Set the icon according to the theme. - if (darkTheme) { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_night, null)); } else { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_light)); + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_day, null)); } } else { // UltraPrivacy is off. // Set the icon according to the theme. - if (darkTheme) { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_night, null)); } else { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_light)); + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_day, null)); } } }); @@ -1527,17 +1649,17 @@ public class DomainSettingsFragment extends Fragment { // Update the icon. if (isChecked) { // Blocking all third-party requests is on. // Set the icon according to the theme. - if (darkTheme) { - blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_enabled_night, null)); } else { - blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_enabled_light)); + blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_enabled_day, null)); } } else { // Blocking all third-party requests is off. // Set the icon according to the theme. - if (darkTheme) { - blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_disabled_night, null)); } else { - blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_disabled_light)); + blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_disabled_day, null)); } } }); @@ -1616,11 +1738,19 @@ public class DomainSettingsFragment extends Fragment { fontSizeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - // Update the display options for `fontSizeTextView`. - if (position == 0) { // System default font size has been selected. Display `fontSizeTextView`. - fontSizeTextView.setVisibility(View.VISIBLE); - } else { // A custom font size has been selected. Hide `fontSizeTextView`. - fontSizeTextView.setVisibility(View.GONE); + // Update the font size display options. + if (position == 0) { // The system default font size has been selected. + // Show the default font size text view. + defaultFontSizeTextView.setVisibility(View.VISIBLE); + + // Hide the custom font size edit text. + customFontSizeEditText.setVisibility(View.GONE); + } else { // A custom font size has been selected. + // Hide the default font size text view. + defaultFontSizeTextView.setVisibility(View.GONE); + + // Show the custom font size edit text. + customFontSizeEditText.setVisibility(View.VISIBLE); } } @@ -1639,17 +1769,17 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.SYSTEM_DEFAULT: if (defaultSwipeToRefresh) { // Swipe to refresh enabled by default. // Set the icon according to the theme. - if (darkTheme) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_light)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_day, null)); } } else { // Swipe to refresh disabled by default. // Set the icon according to the theme. - if (darkTheme) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_light)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_day, null)); } } @@ -1659,10 +1789,10 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.ENABLED: // Set the icon according to the theme. - if (darkTheme) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_light)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_day, null)); } // Hide the swipe to refresh TextView. @@ -1671,10 +1801,10 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.DISABLED: // Set the icon according to the theme. - if (darkTheme) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_light)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_day, null)); } // Hide the swipe to refresh TextView. @@ -1688,112 +1818,72 @@ public class DomainSettingsFragment extends Fragment { } }); - // Set the night mode spinner listener. - nightModeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + // Set the WebView theme spinner listener. + webViewThemeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - // Update the icon and the visibility of `nightModeTextView`. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. + // Update the icon and the visibility of the WebView theme text view. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. switch (position) { - case DomainsDatabaseHelper.SYSTEM_DEFAULT: - if (defaultNightMode) { // Night mode enabled by default. - // Set the icon according to the theme. - if (darkTheme) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark)); - } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light)); - } - } else { // Night mode disabled by default. - // Set the icon according to the theme. - if (darkTheme) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark)); - } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light)); - } - } + 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(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null)); + } else { + // Set the dark theme icon. + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); + } + break; - // Show the night mode TextView. - nightModeTextView.setVisibility(View.VISIBLE); - break; + case DomainsDatabaseHelper.LIGHT_THEME: // The default WebView theme is light. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null)); + } else { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_night, null)); + } + break; - case DomainsDatabaseHelper.ENABLED: - // Set the icon according to the theme. - if (darkTheme) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark)); - } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light)); + case DomainsDatabaseHelper.DARK_THEME: // The default WebView theme is dark. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_day, null)); + } else { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); + } + break; } - // Hide `nightModeTextView`. - nightModeTextView.setVisibility(View.GONE); + // Show the WebView theme text view. + webViewThemeTextView.setVisibility(View.VISIBLE); break; - case DomainsDatabaseHelper.DISABLED: - // Set the icon according to the theme. - if (darkTheme) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark)); + case DomainsDatabaseHelper.LIGHT_THEME: // The domain WebView theme is light. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_day, null)); } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light)); + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_night, null)); } - // Hide `nightModeTextView`. - nightModeTextView.setVisibility(View.GONE); + // Hide the WebView theme text view. + webViewThemeTextView.setVisibility(View.GONE); break; - } - - // Create a `boolean` to store the current night mode setting. - boolean currentNightModeEnabled = (position == DomainsDatabaseHelper.ENABLED) || ((position == DomainsDatabaseHelper.SYSTEM_DEFAULT) && defaultNightMode); - // Disable the JavaScript `Switch` if night mode is enabled. - if (currentNightModeEnabled) { - javaScriptEnabledSwitch.setEnabled(false); - } else { - javaScriptEnabledSwitch.setEnabled(true); - } - - // Update the JavaScript icon. - if ((javaScriptEnabledInt == 1) || currentNightModeEnabled) { - javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.javascript_enabled)); - } else { - javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.privacy_mode)); - } - - // Update the DOM storage status. - if ((javaScriptEnabledInt == 1) || currentNightModeEnabled) { // JavaScript is enabled. - // Enable the DOM storage `Switch`. - domStorageEnabledSwitch.setEnabled(true); - - // Set the DOM storage status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. - if (domStorageEnabledInt == 1) { // Both JavaScript and DOM storage are enabled. - domStorageEnabledSwitch.setChecked(true); - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled)); - } else { // JavaScript is enabled but DOM storage is disabled. - // Set the DOM storage switch to off. - domStorageEnabledSwitch.setChecked(false); - - // Set the icon according to the theme. - if (darkTheme) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark)); + case DomainsDatabaseHelper.DARK_THEME: // The domain WebView theme is dark. + // Set the icon according to the app theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_day, null)); } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light)); + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); } - } - } else { // JavaScript is disabled. - // Disable the DOM storage `Switch`. - domStorageEnabledSwitch.setEnabled(false); - - // Set the checked status of DOM storage. - if (domStorageEnabledInt == 1) { // DOM storage is enabled but JavaScript is disabled. - domStorageEnabledSwitch.setChecked(true); - } else { // Both JavaScript and DOM storage are disabled. - domStorageEnabledSwitch.setChecked(false); - } - // Set the icon according to the theme. - if (darkTheme) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_dark)); - } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_light)); - } + // Hide the WebView theme text view. + webViewThemeTextView.setVisibility(View.GONE); + break; } } @@ -1812,16 +1902,16 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.SYSTEM_DEFAULT: if (defaultWideViewport) { // Wide viewport is enabled by default. // Set the icon according to the theme. - if (darkTheme) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_light)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_day, null)); } } else { // Wide viewport is disabled by default. - if (darkTheme) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_light)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_day, null)); } } @@ -1831,10 +1921,10 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.ENABLED: // Set the icon according to the theme. - if (darkTheme) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_light)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_day, null)); } // Hide the wide viewport text view. @@ -1843,10 +1933,10 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.DISABLED: // Set the icon according to the theme. - if (darkTheme) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_light)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_day, null)); } // Hid ethe wide viewport text view. @@ -1870,17 +1960,17 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.SYSTEM_DEFAULT: if (defaultDisplayWebpageImages) { // Display webpage images is enabled by default. // Set the icon according to the theme. - if (darkTheme) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_light)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_day, null)); } } else { // Display webpage images is disabled by default. // Set the icon according to the theme. - if (darkTheme) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_light)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_day, null)); } } @@ -1890,10 +1980,10 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.ENABLED: // Set the icon according to the theme. - if (darkTheme) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_light)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_day, null)); } // Hide the display images text view. @@ -1902,10 +1992,10 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.DISABLED: // Set the icon according to the theme. - if (darkTheme) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_light)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_day, null)); } // Hide the display images text view. @@ -1925,10 +2015,10 @@ public class DomainSettingsFragment extends Fragment { // Update the icon. if (isChecked) { // SSL certificate pinning is enabled. // Set the icon according to the theme. - if (darkTheme) { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_night, null)); } else { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_light)); + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_day, null)); } // Update the visibility of the saved SSL certificate. @@ -1965,7 +2055,7 @@ public class DomainSettingsFragment extends Fragment { savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent); // Darken the background of the current website SSL certificate linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -1984,7 +2074,7 @@ public class DomainSettingsFragment extends Fragment { currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent); // Darken the background of the saved SSL certificate linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -2002,10 +2092,10 @@ public class DomainSettingsFragment extends Fragment { } } else { // SSL certificate pinning is disabled. // Set the icon according to the theme. - if (darkTheme) { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_night, null)); } else { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_light)); + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_day, null)); } // Hide the SSl certificates and instructions. @@ -2030,7 +2120,7 @@ public class DomainSettingsFragment extends Fragment { savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent); // Darken the background of the current website SSL certificate linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -2048,7 +2138,7 @@ public class DomainSettingsFragment extends Fragment { savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent); // Darken the background of the current website SSL certificate linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -2066,7 +2156,7 @@ public class DomainSettingsFragment extends Fragment { currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent); // Darken the background of the saved SSL certificate linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -2084,7 +2174,7 @@ public class DomainSettingsFragment extends Fragment { currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent); // Darken the background of the saved SSL certificate linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -2096,10 +2186,10 @@ public class DomainSettingsFragment extends Fragment { // Update the icon. if (isChecked) { // IP addresses pinning is enabled. // Set the icon according to the theme. - if (darkTheme) { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_night, null)); } else { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_light)); + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_day, null)); } // Update the visibility of the saved IP addresses card view. @@ -2124,7 +2214,7 @@ public class DomainSettingsFragment extends Fragment { savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent); // Darken the background of the current IP addresses linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -2140,7 +2230,7 @@ public class DomainSettingsFragment extends Fragment { currentIpAddressesLinearLayout.setBackgroundResource(R.color.transparent); // Darken the background of the saved IP addresses linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -2151,10 +2241,10 @@ public class DomainSettingsFragment extends Fragment { currentIpAddressesCardView.getParent().requestChildFocus(currentIpAddressesCardView, currentIpAddressesCardView); } else { // IP addresses pinning is disabled. // Set the icon according to the theme. - if (darkTheme) { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_dark)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_night, null)); } else { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_light)); + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_day, null)); } // Hide the IP addresses card views. @@ -2178,7 +2268,7 @@ public class DomainSettingsFragment extends Fragment { savedIpAddressesLinearLayout.setBackgroundResource(R.color.transparent); // Darken the background of the current IP addresses linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -2196,7 +2286,7 @@ public class DomainSettingsFragment extends Fragment { savedIpAddressesLinearLayout.setBackgroundResource(R.color.transparent); // Darken the background of the current IP addresses linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -2214,7 +2304,7 @@ public class DomainSettingsFragment extends Fragment { currentIpAddressesLinearLayout.setBackgroundResource(R.color.transparent); // Darken the background of the saved IP addresses linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11); @@ -2232,13 +2322,17 @@ public class DomainSettingsFragment extends Fragment { currentIpAddressesLinearLayout.setBackgroundResource(R.color.transparent); // Darken the background of the saved IP addresses linear layout according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33); } else { savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11); } }); + // Set the scroll Y. + domainSettingsScrollView.post(() -> domainSettingsScrollView.setScrollY(scrollY)); + + // Return the domain settings view. return domainSettingsView; }