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=4ae52c94c00698e7498cb394a68f76d48f579dfd;hp=006fa2163c1dbbd719f69f38afe47a2a87ceccdc;hb=ab11ca2de00c56982e46627c8e7fc670462b0b3c;hpb=27e33047e14466c84212bca02a14a7fc4ff15af8 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 006fa216..4ae52c94 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-2020 Soren Stoutner . + * Copyright © 2017-2021 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -44,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; @@ -62,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. @@ -78,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. @@ -86,7 +93,7 @@ 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(); @@ -104,37 +111,35 @@ 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 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); ImageView javaScriptImageView = domainSettingsView.findViewById(R.id.javascript_imageview); - Switch javaScriptSwitch = domainSettingsView.findViewById(R.id.javascript_switch); - ImageView firstPartyCookiesImageView = domainSettingsView.findViewById(R.id.first_party_cookies_imageview); - Switch firstPartyCookiesSwitch = domainSettingsView.findViewById(R.id.first_party_cookies_switch); - LinearLayout thirdPartyCookiesLinearLayout = domainSettingsView.findViewById(R.id.third_party_cookies_linearlayout); - ImageView thirdPartyCookiesImageView = domainSettingsView.findViewById(R.id.third_party_cookies_imageview); - Switch thirdPartyCookiesSwitch = domainSettingsView.findViewById(R.id.third_party_cookies_switch); + SwitchCompat javaScriptSwitch = domainSettingsView.findViewById(R.id.javascript_switch); + ImageView cookiesImageView = domainSettingsView.findViewById(R.id.cookies_imageview); + SwitchCompat cookiesSwitch = domainSettingsView.findViewById(R.id.cookies_switch); ImageView domStorageImageView = domainSettingsView.findViewById(R.id.dom_storage_imageview); - Switch domStorageSwitch = domainSettingsView.findViewById(R.id.dom_storage_switch); + 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 formDataSwitch = domainSettingsView.findViewById(R.id.form_data_switch); // The form data views can be remove once the minimum API >= 26. + 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 easyListSwitch = domainSettingsView.findViewById(R.id.easylist_switch); + SwitchCompat easyListSwitch = domainSettingsView.findViewById(R.id.easylist_switch); ImageView easyPrivacyImageView = domainSettingsView.findViewById(R.id.easyprivacy_imageview); - Switch easyPrivacySwitch = domainSettingsView.findViewById(R.id.easyprivacy_switch); + SwitchCompat easyPrivacySwitch = domainSettingsView.findViewById(R.id.easyprivacy_switch); ImageView fanboysAnnoyanceListImageView = domainSettingsView.findViewById(R.id.fanboys_annoyance_list_imageview); - Switch fanboysAnnoyanceListSwitch = domainSettingsView.findViewById(R.id.fanboys_annoyance_list_switch); + SwitchCompat fanboysAnnoyanceListSwitch = domainSettingsView.findViewById(R.id.fanboys_annoyance_list_switch); ImageView fanboysSocialBlockingListImageView = domainSettingsView.findViewById(R.id.fanboys_social_blocking_list_imageview); - Switch fanboysSocialBlockingListSwitch = domainSettingsView.findViewById(R.id.fanboys_social_blocking_list_switch); + SwitchCompat fanboysSocialBlockingListSwitch = domainSettingsView.findViewById(R.id.fanboys_social_blocking_list_switch); ImageView ultraListImageView = domainSettingsView.findViewById(R.id.ultralist_imageview); - Switch ultraListSwitch = domainSettingsView.findViewById(R.id.ultralist_switch); + SwitchCompat ultraListSwitch = domainSettingsView.findViewById(R.id.ultralist_switch); ImageView ultraPrivacyImageView = domainSettingsView.findViewById(R.id.ultraprivacy_imageview); - Switch ultraPrivacySwitch = domainSettingsView.findViewById(R.id.ultraprivacy_switch); + SwitchCompat ultraPrivacySwitch = domainSettingsView.findViewById(R.id.ultraprivacy_switch); ImageView blockAllThirdPartyRequestsImageView = domainSettingsView.findViewById(R.id.block_all_third_party_requests_imageview); - Switch blockAllThirdPartyRequestsSwitch = domainSettingsView.findViewById(R.id.block_all_third_party_requests_switch); + 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); @@ -144,9 +149,9 @@ public class DomainSettingsFragment extends Fragment { 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); @@ -154,7 +159,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); @@ -179,7 +184,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); @@ -204,53 +209,52 @@ public class DomainSettingsFragment extends Fragment { domainCursor.moveToFirst(); // Save the cursor entries as variables. - String domainNameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME)); - 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 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 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)); - String savedSslIssuedToCNameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME)); - String savedSslIssuedToONameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION)); - String savedSslIssuedToUNameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT)); - String savedSslIssuedByCNameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME)); - String savedSslIssuedByONameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION)); - String savedSslIssuedByUNameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT)); - int pinnedIpAddressesInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_IP_ADDRESSES)); - String savedIpAddresses = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.IP_ADDRESSES)); + String domainNameString = domainCursor.getString(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.DOMAIN_NAME)); + int javaScriptInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)); + int cookiesInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.COOKIES)); + int domStorageInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)); + int formDataInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.ENABLE_FORM_DATA)); // Form data can be remove once the minimum API >= 26. + int easyListInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.ENABLE_EASYLIST)); + int easyPrivacyInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.ENABLE_EASYPRIVACY)); + int fanboysAnnoyanceListInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST)); + int fanboysSocialBlockingListInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST)); + int ultraListInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.ULTRALIST)); + int ultraPrivacyInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY)); + int blockAllThirdPartyRequestsInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS)); + String currentUserAgentName = domainCursor.getString(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.USER_AGENT)); + int fontSizeInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.FONT_SIZE)); + int swipeToRefreshInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.SWIPE_TO_REFRESH)); + int webViewThemeInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.WEBVIEW_THEME)); + int wideViewportInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.WIDE_VIEWPORT)); + int displayImagesInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.DISPLAY_IMAGES)); + int pinnedSslCertificateInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE)); + String savedSslIssuedToCNameString = domainCursor.getString(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME)); + String savedSslIssuedToONameString = domainCursor.getString(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION)); + String savedSslIssuedToUNameString = domainCursor.getString(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT)); + String savedSslIssuedByCNameString = domainCursor.getString(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME)); + String savedSslIssuedByONameString = domainCursor.getString(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION)); + String savedSslIssuedByUNameString = domainCursor.getString(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT)); + int pinnedIpAddressesInt = domainCursor.getInt(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.PINNED_IP_ADDRESSES)); + String savedIpAddresses = domainCursor.getString(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.IP_ADDRESSES)); // Initialize the saved SSL certificate date variables. Date savedSslStartDate = null; Date savedSslEndDate = null; // Only get the saved SSL certificate dates from the cursor if they are not set to `0`. - if (domainCursor.getLong(domainCursor.getColumnIndex(DomainsDatabaseHelper.SSL_START_DATE)) != 0) { - savedSslStartDate = new Date(domainCursor.getLong(domainCursor.getColumnIndex(DomainsDatabaseHelper.SSL_START_DATE))); + if (domainCursor.getLong(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.SSL_START_DATE)) != 0) { + savedSslStartDate = new Date(domainCursor.getLong(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.SSL_START_DATE))); } - if (domainCursor.getLong(domainCursor.getColumnIndex(DomainsDatabaseHelper.SSL_END_DATE)) != 0) { - savedSslEndDate = new Date(domainCursor.getLong(domainCursor.getColumnIndex(DomainsDatabaseHelper.SSL_END_DATE))); + if (domainCursor.getLong(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.SSL_END_DATE)) != 0) { + savedSslEndDate = new Date(domainCursor.getLong(domainCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.SSL_END_DATE))); } // 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.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); @@ -258,7 +262,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); @@ -266,7 +270,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); @@ -296,16 +300,16 @@ public class DomainSettingsFragment extends Fragment { } // Create the foreground color spans. - final ForegroundColorSpan redColorSpan; final ForegroundColorSpan blueColorSpan; + final ForegroundColorSpan redColorSpan; - // 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)); + // Set the color spans according to the theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + blueColorSpan = new ForegroundColorSpan(context.getColor(R.color.blue_700)); + redColorSpan = new ForegroundColorSpan(context.getColor(R.color.red_a700)); } else { - redColorSpan = new ForegroundColorSpan(resources.getColor(R.color.red_a700)); - blueColorSpan = new ForegroundColorSpan(resources.getColor(R.color.blue_700)); + blueColorSpan = new ForegroundColorSpan(context.getColor(R.color.violet_700)); + redColorSpan = new ForegroundColorSpan(context.getColor(R.color.red_900)); } // Set the domain name from the the database cursor. @@ -365,108 +369,52 @@ 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) { - javaScriptSwitch.setEnabled(false); - } else { - javaScriptSwitch.setEnabled(true); - } - - // Set the JavaScript icon. - if ((javaScriptInt == 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 (javaScriptInt == 1) { // JavaScript is enabled. javaScriptSwitch.setChecked(true); + javaScriptImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.javascript_enabled, null)); } else { // JavaScript is disabled. 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 (firstPartyCookiesInt == 1) { // First-party cookies are enabled. - firstPartyCookiesSwitch.setChecked(true); - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_enabled)); - } else { // First-party cookies are disabled. - firstPartyCookiesSwitch.setChecked(false); + // Set the cookies switch status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. + if (cookiesInt == 1) { // Cookies are enabled. + // Turn the switch on. + cookiesSwitch.setChecked(true); + + // Set the icon. + cookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_enabled, null)); + } else { // Cookies are disabled. + // Turn the switch off + cookiesSwitch.setChecked(false); // Set the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_night)); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + cookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_day, null)); } else { - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_day)); + cookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_night, 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 (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 (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(resources.getDrawable(R.drawable.cookies_warning)); - } else { // First party cookies are enabled but third-party cookies are disabled. - // Set the third-party cookies switch to be checked. - thirdPartyCookiesSwitch.setChecked(false); - - // Set the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_night)); - } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_day)); - } - } - } else { // First-party cookies are disabled. - // Set the status of third-party cookies. - if (thirdPartyCookiesInt == 1) { - thirdPartyCookiesSwitch.setChecked(true); - } else { - thirdPartyCookiesSwitch.setChecked(false); - } - - // Disable the third-party cookies switch. - thirdPartyCookiesSwitch.setEnabled(false); - - // Set the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_night)); - } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_day)); - } - } - } else { // Third-party cookies cannot be configured for API <= 21. - // Hide the LinearLayout for third-party cookies. - thirdPartyCookiesLinearLayout.setVisibility(View.GONE); - } - // Only enable DOM storage if JavaScript is enabled. - if ((javaScriptInt == 1) || nightModeEnabled) { // JavaScript is enabled. - // Enable the DOM storage `Switch`. + if (javaScriptInt == 1) { // JavaScript is enabled. + // Enable the DOM storage switch. 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 (domStorageInt == 1) { // Both JavaScript and DOM storage are enabled. domStorageSwitch.setChecked(true); - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled)); + 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. domStorageSwitch.setChecked(false); // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_night)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_night, null)); } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_day)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_day, null)); } } } else { // JavaScript is disabled. @@ -474,37 +422,37 @@ public class DomainSettingsFragment extends Fragment { domStorageSwitch.setEnabled(false); // Set the checked status of DOM storage. - if (domStorageInt == 1) { // DOM storage is enabled but JavaScript is disabled. - domStorageSwitch.setChecked(true); - } else { // Both JavaScript and DOM storage are disabled. - domStorageSwitch.setChecked(false); - } + domStorageSwitch.setChecked(domStorageInt == 1); // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_night)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_ghosted_night, null)); } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_day)); + 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. + // 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 (formDataInt == 1) { // Form data is on. + // Turn the form data switch on. formDataSwitch.setChecked(true); - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_enabled)); + + // 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. formDataSwitch.setChecked(false); - // Set the icon according to the theme. + // 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(resources.getDrawable(R.drawable.form_data_disabled_night)); + formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_disabled_night, null)); } else { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_day)); + formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_disabled_day, null)); } } } @@ -516,9 +464,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_night)); + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_night, null)); } else { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_day)); + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_day, null)); } } else { // EasyList is off. // Turn the switch off. @@ -526,9 +474,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_night)); + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_night, null)); } else { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_day)); + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_day, null)); } } @@ -539,9 +487,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_night)); + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_night, null)); } else { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_day)); + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_day, null)); } } else { // EasyPrivacy is off. // Turn the switch off. @@ -549,9 +497,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_night)); + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_night, null)); } else { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_day)); + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_day, null)); } } @@ -562,9 +510,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_night)); + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null)); } else { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_day)); + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_day, null)); } } else { // Fanboy's Annoyance List is off. // Turn the switch off. @@ -572,55 +520,51 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_night)); + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null)); } else { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_day)); + 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_night)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_day)); + 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_night)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_day)); + 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. - if (fanboysSocialBlockingListInt == 1) { // Fanboy's Social Blocking List is on. - // Disable the switch but turn it on. - fanboysSocialBlockingListSwitch.setEnabled(false); - fanboysSocialBlockingListSwitch.setChecked(true); - } else { // Fanboy's Social Blocking List is off. - // Disable the switch and turn it off. - fanboysSocialBlockingListSwitch.setEnabled(false); - fanboysSocialBlockingListSwitch.setChecked(false); - } + // Disable Fanboy's Social Blocking List switch. + fanboysSocialBlockingListSwitch.setEnabled(false); + + // Set the status of Fanboy's Social Blocking List. + fanboysSocialBlockingListSwitch.setChecked(fanboysSocialBlockingListInt == 1); // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_night)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_ghosted_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_day)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_ghosted_day, null)); } } @@ -631,9 +575,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - ultraListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_night)); + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_night, null)); } else { - ultraListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_day)); + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_day, null)); } } else { // UltraList is off. // Turn the switch off. @@ -641,9 +585,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - ultraListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_night)); + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_night, null)); } else { - ultraListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_day)); + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_day, null)); } } @@ -654,9 +598,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_night)); + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_night, null)); } else { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_day)); + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_day, null)); } } else { // EasyPrivacy is off. // Turn the switch off. @@ -664,9 +608,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_night)); + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_night, null)); } else { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_day)); + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_day, null)); } } @@ -677,9 +621,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_enabled_night)); + 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_day)); + 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. @@ -687,9 +631,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_disabled_night)); + 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_day)); + blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_disabled_day, null)); } } @@ -807,7 +751,7 @@ public class DomainSettingsFragment extends Fragment { 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. @@ -823,16 +767,16 @@ public class DomainSettingsFragment extends Fragment { if (defaultSwipeToRefresh) { // Swipe to refresh is enabled by default. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_night)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_day)); + 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_night)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_day)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_day, null)); } } @@ -843,9 +787,9 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.ENABLED: // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_night)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_day)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_day, null)); } // Hide the swipe to refresh TextView.` @@ -855,13 +799,14 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.DISABLED: // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_night)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_day)); + 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. @@ -870,71 +815,111 @@ public class DomainSettingsFragment extends Fragment { swipeToRefreshSpinner.performClick(); }); - // Display the night mode in the spinner. - nightModeSpinner.setSelection(nightModeInt); + // 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 default night mode text. - if (defaultNightMode) { - nightModeTextView.setText(nightModeArrayAdapter.getItem(DomainsDatabaseHelper.ENABLED)); - } else { - nightModeTextView.setText(nightModeArrayAdapter.getItem(DomainsDatabaseHelper.DISABLED)); + // 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 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_night)); - } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_day)); - } - } else { // Night mode disabled by default. - // Set the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_night)); - } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_day)); - } + // 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; } - // Show night mode TextView. - nightModeTextView.setVisibility(View.VISIBLE); + // Show the WebView theme text view. + webViewThemeTextView.setVisibility(View.VISIBLE); break; - case DomainsDatabaseHelper.ENABLED: - // Set the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_night)); + 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_enabled_day)); + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme_night, null)); } - // Hide the night mode TextView. - nightModeTextView.setVisibility(View.GONE); + // Hide the WebView theme text view. + webViewThemeTextView.setVisibility(View.GONE); break; - case DomainsDatabaseHelper.DISABLED: - // Set the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_night)); + 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 { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_day)); + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); } - // Hide the night mode TextView. - nightModeTextView.setVisibility(View.GONE); + // Hide the WebView theme text view. + webViewThemeTextView.setVisibility(View.GONE); break; } - // Open the night mode spinner when the TextView is clicked. - nightModeTextView.setOnClickListener((View v) -> { - // Open the night mode spinner. - nightModeSpinner.performClick(); + // Open the WebView theme spinner when the text view is clicked. + webViewThemeTextView.setOnClickListener((View v) -> { + // Open the WebView theme spinner. + webViewThemeSpinner.performClick(); }); - // Display the wide viewport in the spinner. + // Select the wide viewport in the spinner. wideViewportSpinner.setSelection(wideViewportInt); // Set the default wide viewport text. @@ -950,15 +935,15 @@ public class DomainSettingsFragment extends Fragment { if (defaultWideViewport) { // Wide viewport enabled by default. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_night)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_day)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_day, null)); } } else { // Wide viewport disabled by default. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_night)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_day)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_day, null)); } } @@ -969,9 +954,9 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.ENABLED: // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_night)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_day)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_day, null)); } // Hide the wide viewport text view. @@ -981,9 +966,9 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.DISABLED: // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_night)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_day)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_day, null)); } // Hide the wide viewport text view. @@ -1013,16 +998,16 @@ public class DomainSettingsFragment extends Fragment { if (defaultDisplayWebpageImages) { // Display webpage images enabled by default. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_night)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_day)); + 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_night)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_day)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_day, null)); } } @@ -1033,9 +1018,9 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.ENABLED: // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_night)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_day)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_day, null)); } // Hide the display images text view. @@ -1045,9 +1030,9 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.DISABLED: // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_night)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_day)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_day, null)); } // Hide the display images text view. @@ -1068,9 +1053,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_night)); + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_night, null)); } else { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_day)); + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_day, null)); } } else { // Pinned SSL certificate is disabled. // Uncheck the switch. @@ -1078,9 +1063,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_night)); + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_night, null)); } else { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_day)); + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_day, null)); } } @@ -1255,9 +1240,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_night)); + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_night, null)); } else { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_day)); + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_day, null)); } } else { // Pinned IP Addresses is disabled. // Uncheck the switch. @@ -1265,9 +1250,9 @@ public class DomainSettingsFragment extends Fragment { // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_night)); + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_night, null)); } else { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_day)); + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_day, null)); } } @@ -1323,91 +1308,49 @@ public class DomainSettingsFragment extends Fragment { 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`. domStorageSwitch.setEnabled(true); // Update the DOM storage icon. if (domStorageSwitch.isChecked()) { // DOM storage is enabled. - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_night)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_night, null)); } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_day)); + 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`. domStorageSwitch.setEnabled(false); // Set the DOM storage icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_night)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_ghosted_night, null)); } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_day)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_ghosted_day, null)); } } }); - // Set the first-party cookies switch listener. - 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)); - - // Enable the third-party cookies switch. - thirdPartyCookiesSwitch.setEnabled(true); - - // Update the third-party cookies icon. - if (thirdPartyCookiesSwitch.isChecked()) { // Third-party cookies are enabled. - // Set the third-party cookies icon to be red. - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_warning)); - } else { // Third-party cookies are disabled. - // Set the third-party cookies icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_night)); - } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_day)); - } - } - } else { // First-party cookies are disabled. - // Update the first-party cookies icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_night)); - } else { - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_day)); - } - - // Disable the third-party cookies switch. - thirdPartyCookiesSwitch.setEnabled(false); - - // Set the third-party cookies icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_night)); + // Set the cookies switch listener. + cookiesSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + if (isChecked) { // Cookies are enabled. + // Update the cookies icon. + cookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_enabled, null)); + } else { // Cookies are disabled. + // Update the cookies icon according to the theme. + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + cookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_day, null)); } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_day)); - } - } - }); - - // Set the third-party cookies switch listener. - thirdPartyCookiesSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { - // Update the icon. - if (isChecked) { - // Set the third-party cookies icon to be red. - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_warning)); - } else { - // Update the third-party cookies icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_night)); - } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_day)); + cookiesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.cookies_disabled_night, null)); } } }); @@ -1416,13 +1359,13 @@ public class DomainSettingsFragment extends Fragment { 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_night)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_night, null)); } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_day)); + domStorageImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.dom_storage_disabled_day, null)); } } }); @@ -1432,13 +1375,13 @@ public class DomainSettingsFragment extends Fragment { 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_night)); + formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_disabled_night, null)); } else { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_day)); + formDataImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.form_data_disabled_day, null)); } } }); @@ -1450,16 +1393,16 @@ public class DomainSettingsFragment extends Fragment { if (isChecked) { // EasyList is on. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_night)); + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_night, null)); } else { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_day)); + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_day, null)); } } else { // EasyList is off. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_night)); + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_night, null)); } else { - easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_day)); + easyListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_day, null)); } } }); @@ -1470,16 +1413,16 @@ public class DomainSettingsFragment extends Fragment { if (isChecked) { // EasyPrivacy is on. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_night)); + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_night, null)); } else { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_day)); + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_day, null)); } } else { // EasyPrivacy is off. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_night)); + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_night, null)); } else { - easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_day)); + easyPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_day, null)); } } }); @@ -1490,9 +1433,9 @@ public class DomainSettingsFragment extends Fragment { if (isChecked) { // Fanboy's Annoyance List is on. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_night)); + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null)); } else { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_day)); + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_day, null)); } // Disable the Fanboy's Social Blocking List switch. @@ -1500,16 +1443,16 @@ public class DomainSettingsFragment extends Fragment { // Update the Fanboy's Social Blocking List icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_night)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_ghosted_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_day)); + 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_night)); + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null)); } else { - fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_day)); + fanboysAnnoyanceListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_day, null)); } // Enable the Fanboy's Social Blocking List switch. @@ -1519,16 +1462,16 @@ public class DomainSettingsFragment extends Fragment { if (fanboysSocialBlockingListSwitch.isChecked()) { // Fanboy's Social Blocking List is on. // Update the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_night)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_day)); + 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_night)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_day)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_day, null)); } } } @@ -1541,16 +1484,16 @@ public class DomainSettingsFragment extends Fragment { if (isChecked) { // Fanboy's Social Blocking List is on. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_night)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_enabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_day)); + 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_night)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_night, null)); } else { - fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_day)); + fanboysSocialBlockingListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.social_media_disabled_day, null)); } } }); @@ -1561,16 +1504,16 @@ public class DomainSettingsFragment extends Fragment { if (isChecked) { // UltraList is on. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - ultraListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_night)); + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_enabled_night, null)); } else { - ultraListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_day)); + 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(resources.getDrawable(R.drawable.block_ads_disabled_night)); + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_night, null)); } else { - ultraListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_day)); + ultraListImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_ads_disabled_day, null)); } } }); @@ -1581,16 +1524,16 @@ public class DomainSettingsFragment extends Fragment { if (isChecked) { // UltraPrivacy is on. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_night)); + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_night, null)); } else { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_day)); + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_enabled_day, null)); } } else { // UltraPrivacy is off. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_night)); + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_night, null)); } else { - ultraPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_day)); + ultraPrivacyImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_tracking_disabled_day, null)); } } }); @@ -1601,16 +1544,16 @@ public class DomainSettingsFragment extends Fragment { if (isChecked) { // Blocking all third-party requests is on. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_enabled_night)); + 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_day)); + 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - blockAllThirdPartyRequestsImageView.setImageDrawable(resources.getDrawable(R.drawable.block_all_third_party_requests_disabled_night)); + 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_day)); + blockAllThirdPartyRequestsImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.block_all_third_party_requests_disabled_day, null)); } } }); @@ -1721,16 +1664,16 @@ public class DomainSettingsFragment extends Fragment { if (defaultSwipeToRefresh) { // Swipe to refresh enabled by default. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_night)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_day)); + 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_night)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_day)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_day, null)); } } @@ -1741,9 +1684,9 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.ENABLED: // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_night)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_day)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_enabled_day, null)); } // Hide the swipe to refresh TextView. @@ -1753,9 +1696,9 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.DISABLED: // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_night)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_night, null)); } else { - swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_day)); + swipeToRefreshImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.refresh_disabled_day, null)); } // Hide the swipe to refresh TextView. @@ -1769,112 +1712,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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_night)); - } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_day)); - } - } else { // Night mode disabled by default. - // Set the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_night)); - } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_day)); - } - } + 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_night)); - } else { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_day)); + 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_night)); + 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_day)); + 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) { - javaScriptSwitch.setEnabled(false); - } else { - javaScriptSwitch.setEnabled(true); - } - - // Update the JavaScript icon. - if ((javaScriptInt == 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 ((javaScriptInt == 1) || currentNightModeEnabled) { // JavaScript is enabled. - // Enable the DOM storage `Switch`. - 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 (domStorageInt == 1) { // Both JavaScript and DOM storage are enabled. - domStorageSwitch.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. - domStorageSwitch.setChecked(false); - - // Set the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_night)); + 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_day)); + webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme_night, null)); } - } - } else { // JavaScript is disabled. - // Disable the DOM storage `Switch`. - domStorageSwitch.setEnabled(false); - - // Set the checked status of DOM storage. - if (domStorageInt == 1) { // DOM storage is enabled but JavaScript is disabled. - domStorageSwitch.setChecked(true); - } else { // Both JavaScript and DOM storage are disabled. - domStorageSwitch.setChecked(false); - } - // Set the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_night)); - } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_day)); - } + // Hide the WebView theme text view. + webViewThemeTextView.setVisibility(View.GONE); + break; } } @@ -1894,15 +1797,15 @@ public class DomainSettingsFragment extends Fragment { if (defaultWideViewport) { // Wide viewport is enabled by default. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_night)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_day)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_day, null)); } } else { // Wide viewport is disabled by default. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_night)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_day)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_day, null)); } } @@ -1913,9 +1816,9 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.ENABLED: // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_night)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_enabled_day)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled_day, null)); } // Hide the wide viewport text view. @@ -1925,9 +1828,9 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.DISABLED: // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_night)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_night, null)); } else { - wideViewportImageView.setImageDrawable(resources.getDrawable(R.drawable.wide_viewport_disabled_day)); + wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled_day, null)); } // Hid ethe wide viewport text view. @@ -1952,16 +1855,16 @@ public class DomainSettingsFragment extends Fragment { if (defaultDisplayWebpageImages) { // Display webpage images is enabled by default. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_night)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_day)); + 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 (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_night)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_day)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_day, null)); } } @@ -1972,9 +1875,9 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.ENABLED: // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_night)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_day)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled_day, null)); } // Hide the display images text view. @@ -1984,9 +1887,9 @@ public class DomainSettingsFragment extends Fragment { case DomainsDatabaseHelper.DISABLED: // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_night)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_night, null)); } else { - displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_day)); + displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled_day, null)); } // Hide the display images text view. @@ -2007,9 +1910,9 @@ public class DomainSettingsFragment extends Fragment { if (isChecked) { // SSL certificate pinning is enabled. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_night)); + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_night, null)); } else { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_day)); + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_day, null)); } // Update the visibility of the saved SSL certificate. @@ -2084,9 +1987,9 @@ public class DomainSettingsFragment extends Fragment { } else { // SSL certificate pinning is disabled. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_night)); + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_night, null)); } else { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_day)); + pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_day, null)); } // Hide the SSl certificates and instructions. @@ -2178,9 +2081,9 @@ public class DomainSettingsFragment extends Fragment { if (isChecked) { // IP addresses pinning is enabled. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_night)); + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_night, null)); } else { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_day)); + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled_day, null)); } // Update the visibility of the saved IP addresses card view. @@ -2233,9 +2136,9 @@ public class DomainSettingsFragment extends Fragment { } else { // IP addresses pinning is disabled. // Set the icon according to the theme. if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_night)); + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_night, null)); } else { - pinnedIpAddressesImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_day)); + pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled_day, null)); } // Hide the IP addresses card views. @@ -2320,6 +2223,10 @@ public class DomainSettingsFragment extends Fragment { } }); + // Set the scroll Y. + domainSettingsScrollView.post(() -> domainSettingsScrollView.setScrollY(scrollY)); + + // Return the domain settings view. return domainSettingsView; }