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=d003a99a59ceddb8277a0997718cb9af55580fce;hp=3889ef7fc36d394f0296704b60d5771604aa69f4;hb=49e94a767e452d451a722bbb068e46458e404ed9;hpb=2e89243b891eaa56a55a992c3513a337236f56e6 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 3889ef7f..d003a99a 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 Soren Stoutner . + * Copyright © 2017-2018 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -29,6 +29,7 @@ import android.os.Build; import android.os.Bundle; // We have to use `android.support.v4.app.Fragment` until minimum API >= 23. Otherwise we cannot call `getContext()`. import android.preference.PreferenceManager; +import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.text.Editable; import android.text.SpannableStringBuilder; @@ -69,6 +70,9 @@ public class DomainSettingsFragment extends Fragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + // Remove the lint warning that `getArguments` might be null. + assert getArguments() != null; + // Store the database id in `databaseId`. databaseId = getArguments().getInt(DATABASE_ID); } @@ -76,7 +80,7 @@ public class DomainSettingsFragment extends Fragment { // We have to use the deprecated `getDrawable()` until the minimum API >= 21. @SuppressWarnings("deprecation") @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate `domain_settings_fragment`. `false` does not attach it to the root `container`. View domainSettingsView = inflater.inflate(R.layout.domain_settings_fragment, container, false); @@ -87,56 +91,60 @@ public class DomainSettingsFragment extends Fragment { // Get a handle for the shared preference. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); - // Store the default user agent string values. + // Store the default settings. final String defaultUserAgentString = sharedPreferences.getString("user_agent", "PrivacyBrowser/1.0"); final String defaultCustomUserAgentString = sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0"); String defaultFontSizeString = sharedPreferences.getString("default_font_size", "100"); - boolean defaultDisplayWebpageImagesBoolean = sharedPreferences.getBoolean("display_website_images", true); + final boolean defaultDisplayWebpageImagesBoolean = sharedPreferences.getBoolean("display_website_images", true); + final boolean defaultNightModeBoolean = sharedPreferences.getBoolean("night_mode", false); // Get handles for the views in the fragment. - final EditText domainNameEditText = (EditText) domainSettingsView.findViewById(R.id.domain_settings_name_edittext); - Switch javaScriptEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_javascript_switch); - final ImageView javaScriptImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_javascript_imageview); - Switch firstPartyCookiesEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_first_party_cookies_switch); - final ImageView firstPartyCookiesImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_first_party_cookies_imageview); - LinearLayout thirdPartyCookiesLinearLayout = (LinearLayout) domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_linearlayout); - final Switch thirdPartyCookiesEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_switch); - final ImageView thirdPartyCookiesImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_imageview); - final Switch domStorageEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_dom_storage_switch); - final ImageView domStorageImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_dom_storage_imageview); - Switch formDataEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_form_data_switch); - final ImageView formDataImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_form_data_imageview); - Spinner userAgentSpinner = (Spinner) domainSettingsView.findViewById(R.id.domain_settings_user_agent_spinner); - final TextView userAgentTextView = (TextView) domainSettingsView.findViewById(R.id.domain_settings_user_agent_textview); - final EditText customUserAgentEditText = (EditText) domainSettingsView.findViewById(R.id.domain_settings_custom_user_agent_edittext); - Spinner fontSizeSpinner = (Spinner) domainSettingsView.findViewById(R.id.domain_settings_font_size_spinner); - final TextView fontSizeTextView = (TextView) domainSettingsView.findViewById(R.id.domain_settings_font_size_textview); - final ImageView displayWebpageImagesImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_display_webpage_images_imageview); - Spinner displayWebpageImagesSpinner = (Spinner) domainSettingsView.findViewById(R.id.domain_settings_display_webpage_images_spinner); - final TextView displayImagesTextView = (TextView) domainSettingsView.findViewById(R.id.domain_settings_display_webpage_images_textview); - final ImageView pinnedSslCertificateImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_pinned_ssl_certificate_imageview); - Switch pinnedSslCertificateSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_pinned_ssl_certificate_switch); - final LinearLayout savedSslCertificateLinearLayout = (LinearLayout) domainSettingsView.findViewById(R.id.saved_ssl_certificate_linearlayout); - final RadioButton savedSslCertificateRadioButton = (RadioButton) domainSettingsView.findViewById(R.id.saved_ssl_certificate_radiobutton); - final TextView savedSslCertificateIssuedToCNameTextView = (TextView) domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_to_cname); - TextView savedSslCertificateIssuedToONameTextView = (TextView) domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_to_oname); - TextView savedSslCertificateIssuedToUNameTextView = (TextView) domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_to_uname); - TextView savedSslCertificateIssuedByCNameTextView = (TextView) domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_by_cname); - TextView savedSslCertificateIssuedByONameTextView = (TextView) domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_by_oname); - TextView savedSslCertificateIssuedByUNameTextView = (TextView) domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_by_uname); - TextView savedSslCertificateStartDateTextView = (TextView) domainSettingsView.findViewById(R.id.saved_ssl_certificate_start_date); - TextView savedSslCertificateEndDateTextView = (TextView) domainSettingsView.findViewById(R.id.saved_ssl_certificate_end_date); - final LinearLayout currentWebsiteCertificateLinearLayout = (LinearLayout) domainSettingsView.findViewById(R.id.current_website_certificate_linearlayout); - final RadioButton currentWebsiteCertificateRadioButton = (RadioButton) domainSettingsView.findViewById(R.id.current_website_certificate_radiobutton); - final TextView currentWebsiteCertificateIssuedToCNameTextView = (TextView) domainSettingsView.findViewById(R.id.current_website_certificate_issued_to_cname); - TextView currentWebsiteCertificateIssuedToONameTextView = (TextView) domainSettingsView.findViewById(R.id.current_website_certificate_issued_to_oname); - TextView currentWebsiteCertificateIssuedToUNameTextView = (TextView) domainSettingsView.findViewById(R.id.current_website_certificate_issued_to_uname); - TextView currentWebsiteCertificateIssuedByCNameTextView = (TextView) domainSettingsView.findViewById(R.id.current_website_certificate_issued_by_cname); - TextView currentWebsiteCertificateIssuedByONameTextView = (TextView) domainSettingsView.findViewById(R.id.current_website_certificate_issued_by_oname); - TextView currentWebsiteCertificateIssuedByUNameTextView = (TextView) domainSettingsView.findViewById(R.id.current_website_certificate_issued_by_uname); - TextView currentWebsiteCertificateStartDateTextView = (TextView) domainSettingsView.findViewById(R.id.current_website_certificate_start_date); - TextView currentWebsiteCertificateEndDateTextView = (TextView) domainSettingsView.findViewById(R.id.current_website_certificate_end_date); - final TextView noCurrentWebsiteCertificateTextView = (TextView) domainSettingsView.findViewById(R.id.no_current_website_certificate); + final EditText domainNameEditText = domainSettingsView.findViewById(R.id.domain_settings_name_edittext); + final Switch javaScriptEnabledSwitch = domainSettingsView.findViewById(R.id.domain_settings_javascript_switch); + final ImageView javaScriptImageView = domainSettingsView.findViewById(R.id.domain_settings_javascript_imageview); + Switch firstPartyCookiesEnabledSwitch = domainSettingsView.findViewById(R.id.domain_settings_first_party_cookies_switch); + final ImageView firstPartyCookiesImageView = domainSettingsView.findViewById(R.id.domain_settings_first_party_cookies_imageview); + LinearLayout thirdPartyCookiesLinearLayout = domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_linearlayout); + final Switch thirdPartyCookiesEnabledSwitch = domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_switch); + final ImageView thirdPartyCookiesImageView = domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_imageview); + final Switch domStorageEnabledSwitch = domainSettingsView.findViewById(R.id.domain_settings_dom_storage_switch); + final ImageView domStorageImageView = domainSettingsView.findViewById(R.id.domain_settings_dom_storage_imageview); + Switch formDataEnabledSwitch = domainSettingsView.findViewById(R.id.domain_settings_form_data_switch); + final ImageView formDataImageView = domainSettingsView.findViewById(R.id.domain_settings_form_data_imageview); + final Spinner userAgentSpinner = domainSettingsView.findViewById(R.id.domain_settings_user_agent_spinner); + final TextView userAgentTextView = domainSettingsView.findViewById(R.id.domain_settings_user_agent_textview); + final EditText customUserAgentEditText = domainSettingsView.findViewById(R.id.domain_settings_custom_user_agent_edittext); + final Spinner fontSizeSpinner = domainSettingsView.findViewById(R.id.domain_settings_font_size_spinner); + final TextView fontSizeTextView = domainSettingsView.findViewById(R.id.domain_settings_font_size_textview); + final ImageView displayWebpageImagesImageView = domainSettingsView.findViewById(R.id.domain_settings_display_webpage_images_imageview); + final Spinner displayWebpageImagesSpinner = domainSettingsView.findViewById(R.id.domain_settings_display_webpage_images_spinner); + final TextView displayImagesTextView = domainSettingsView.findViewById(R.id.domain_settings_display_webpage_images_textview); + final ImageView nightModeImageView = domainSettingsView.findViewById(R.id.domain_settings_night_mode_imageview); + final Spinner nightModeSpinner = domainSettingsView.findViewById(R.id.domain_settings_night_mode_spinner); + final TextView nightModeTextView = domainSettingsView.findViewById(R.id.domain_settings_night_mode_textview); + final ImageView pinnedSslCertificateImageView = domainSettingsView.findViewById(R.id.domain_settings_pinned_ssl_certificate_imageview); + Switch pinnedSslCertificateSwitch = domainSettingsView.findViewById(R.id.domain_settings_pinned_ssl_certificate_switch); + final LinearLayout savedSslCertificateLinearLayout = domainSettingsView.findViewById(R.id.saved_ssl_certificate_linearlayout); + final RadioButton savedSslCertificateRadioButton = domainSettingsView.findViewById(R.id.saved_ssl_certificate_radiobutton); + final TextView savedSslCertificateIssuedToCNameTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_to_cname); + TextView savedSslCertificateIssuedToONameTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_to_oname); + TextView savedSslCertificateIssuedToUNameTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_to_uname); + TextView savedSslCertificateIssuedByCNameTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_by_cname); + TextView savedSslCertificateIssuedByONameTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_by_oname); + TextView savedSslCertificateIssuedByUNameTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_issued_by_uname); + TextView savedSslCertificateStartDateTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_start_date); + TextView savedSslCertificateEndDateTextView = domainSettingsView.findViewById(R.id.saved_ssl_certificate_end_date); + final LinearLayout currentWebsiteCertificateLinearLayout = domainSettingsView.findViewById(R.id.current_website_certificate_linearlayout); + final RadioButton currentWebsiteCertificateRadioButton = domainSettingsView.findViewById(R.id.current_website_certificate_radiobutton); + final TextView currentWebsiteCertificateIssuedToCNameTextView = domainSettingsView.findViewById(R.id.current_website_certificate_issued_to_cname); + TextView currentWebsiteCertificateIssuedToONameTextView = domainSettingsView.findViewById(R.id.current_website_certificate_issued_to_oname); + TextView currentWebsiteCertificateIssuedToUNameTextView = domainSettingsView.findViewById(R.id.current_website_certificate_issued_to_uname); + TextView currentWebsiteCertificateIssuedByCNameTextView = domainSettingsView.findViewById(R.id.current_website_certificate_issued_by_cname); + TextView currentWebsiteCertificateIssuedByONameTextView = domainSettingsView.findViewById(R.id.current_website_certificate_issued_by_oname); + TextView currentWebsiteCertificateIssuedByUNameTextView = domainSettingsView.findViewById(R.id.current_website_certificate_issued_by_uname); + TextView currentWebsiteCertificateStartDateTextView = domainSettingsView.findViewById(R.id.current_website_certificate_start_date); + TextView currentWebsiteCertificateEndDateTextView = domainSettingsView.findViewById(R.id.current_website_certificate_end_date); + final TextView noCurrentWebsiteCertificateTextView = domainSettingsView.findViewById(R.id.no_current_website_certificate); // Setup the SSL certificate labels. final String cNameLabel = getString(R.string.common_name) + " "; @@ -157,14 +165,15 @@ public class DomainSettingsFragment extends Fragment { // Save the `Cursor` entries as variables. String domainNameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME)); - int javaScriptEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)); + final int javaScriptEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)); int firstPartyCookiesEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)); int thirdPartyCookiesEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)); - int domStorageEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)); + final int domStorageEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)); int formDataEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)); final String currentUserAgentString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.USER_AGENT)); int fontSizeInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.FONT_SIZE)); int displayImagesInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.DISPLAY_IMAGES)); + int nightModeInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.NIGHT_MODE)); int pinnedSslCertificateInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE)); final String savedSslCertificateIssuedToCNameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME)); String savedSslCertificateIssuedToONameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION)); @@ -187,21 +196,24 @@ public class DomainSettingsFragment extends Fragment { } // Create `ArrayAdapters` for the `Spinners`and their `entry values`. - ArrayAdapter userAgentArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_user_agent_entries, R.layout.spinner_item); - final ArrayAdapter userAgentEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_user_agent_entry_values, R.layout.spinner_item); - ArrayAdapter fontSizeArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_font_size_entries, R.layout.spinner_item); - ArrayAdapter fontSizeEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_font_size_entry_values, R.layout.spinner_item); - final ArrayAdapter displayImagesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.display_website_images_array, R.layout.spinner_item); + ArrayAdapter userAgentArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_user_agent_entries, R.layout.domain_settings_spinner_item); + final ArrayAdapter userAgentEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_user_agent_entry_values, R.layout.domain_settings_spinner_item); + ArrayAdapter fontSizeArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_font_size_entries, R.layout.domain_settings_spinner_item); + ArrayAdapter fontSizeEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.domain_settings_font_size_entry_values, R.layout.domain_settings_spinner_item); + final ArrayAdapter displayImagesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.display_webpage_images_array, R.layout.domain_settings_spinner_item); + ArrayAdapter nightModeArrayAdapter = ArrayAdapter.createFromResource(context, R.array.night_mode_array, R.layout.domain_settings_spinner_item); // Set the `DropDownViewResource` on the `Spinners`. - userAgentArrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item); - fontSizeArrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item); - displayImagesArrayAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item); + userAgentArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_item); + fontSizeArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_item); + displayImagesArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_item); + nightModeArrayAdapter.setDropDownViewResource(R.layout.domain_settings_spinner_dropdown_item); // Set the `ArrayAdapters` for the `Spinners`. userAgentSpinner.setAdapter(userAgentArrayAdapter); fontSizeSpinner.setAdapter(fontSizeArrayAdapter); displayWebpageImagesSpinner.setAdapter(displayImagesArrayAdapter); + nightModeSpinner.setAdapter(nightModeArrayAdapter); // Create a `SpannableStringBuilder` for each `TextView` that needs multiple colors of text. SpannableStringBuilder savedSslCertificateIssuedToCNameStringBuilder = new SpannableStringBuilder(cNameLabel + savedSslCertificateIssuedToCNameString); @@ -303,13 +315,28 @@ public class DomainSettingsFragment extends Fragment { } }); - // Set the JavaScript status. + // Create a `boolean` to track if night mode is enabled. + boolean nightModeEnabled = (nightModeInt == DomainsDatabaseHelper.NIGHT_MODE_ENABLED) || ((nightModeInt == DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT) && defaultNightModeBoolean); + + // Disable the JavaScript `Switch` if night mode is enabled. + if (nightModeEnabled) { + javaScriptEnabledSwitch.setEnabled(false); + } else { + javaScriptEnabledSwitch.setEnabled(true); + } + + // Set the JavaScript icon. + if ((javaScriptEnabledInt == 1) || nightModeEnabled) { + javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.javascript_enabled)); + } else { + javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.privacy_mode)); + } + + // Set the JavaScript `Switch` status. if (javaScriptEnabledInt == 1) { // JavaScript is enabled. javaScriptEnabledSwitch.setChecked(true); - javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.javascript_enabled)); } else { // JavaScript is disabled. javaScriptEnabledSwitch.setChecked(false); - javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.privacy_mode)); } // Set the first-party cookies status. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons. @@ -369,7 +396,10 @@ public class DomainSettingsFragment extends Fragment { } // Only enable DOM storage if JavaScript is enabled. - if (javaScriptEnabledInt == 1) { // JavaScript is enabled. + if ((javaScriptEnabledInt == 1) || nightModeEnabled) { // JavaScript is enabled. + // Enable the DOM storage `Switch`. + domStorageEnabledSwitch.setEnabled(true); + // Set the DOM storage status. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons. if (domStorageEnabledInt == 1) { // Both JavaScript and DOM storage are enabled. domStorageEnabledSwitch.setChecked(true); @@ -386,6 +416,9 @@ public class DomainSettingsFragment extends Fragment { } } } else { // JavaScript is disabled. + // Disable the DOM storage `Switch`. + domStorageEnabledSwitch.setEnabled(false); + // Set the checked status of DOM storage. if (domStorageEnabledInt == 1) { // DOM storage is enabled but JavaScript is disabled. domStorageEnabledSwitch.setChecked(true); @@ -393,9 +426,6 @@ public class DomainSettingsFragment extends Fragment { domStorageEnabledSwitch.setChecked(false); } - // Disable `domStorageEnabledSwitch`. - domStorageEnabledSwitch.setEnabled(false); - // Set the icon according to the theme. if (MainWebViewActivity.darkTheme) { domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_dark)); @@ -423,7 +453,7 @@ public class DomainSettingsFragment extends Fragment { // We need to inflated a `WebView` to get the default user agent. // `@SuppressLint("InflateParams")` removes the warning about using `null` as the `ViewGroup`, which in this case makes sense because we don't want to display `bare_webview` on the screen. `false` does not attach the view to the root. @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false); - WebView bareWebView = (WebView) bareWebViewLayout.findViewById(R.id.bare_webview); + WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview); final String webViewDefaultUserAgentString = bareWebView.getSettings().getUserAgentString(); // Get the position of the user agent in `userAgentEntryValuesArrayAdapter`. @@ -482,6 +512,12 @@ public class DomainSettingsFragment extends Fragment { } } + // Open the user agent spinner when the `TextView` is clicked. + userAgentTextView.setOnClickListener((View v) -> { + // Open the user agent spinner. + userAgentSpinner.performClick(); + }); + // Set the selected font size. int fontSizeArrayPosition = fontSizeEntryValuesArrayAdapter.getPosition(String.valueOf(fontSizeInt)); fontSizeSpinner.setSelection(fontSizeArrayPosition); @@ -497,27 +533,33 @@ public class DomainSettingsFragment extends Fragment { fontSizeTextView.setVisibility(View.GONE); } - // Set the selected display website images mode. + // Open the font size spinner when the `TextView` is clicked. + fontSizeTextView.setOnClickListener((View v) -> { + // Open the user agent spinner. + fontSizeSpinner.performClick(); + }); + + // Display the website images mode in the spinner. displayWebpageImagesSpinner.setSelection(displayImagesInt); // Set the default display images text. if (defaultDisplayWebpageImagesBoolean) { - displayImagesTextView.setText(displayImagesArrayAdapter.getItem(1)); + displayImagesTextView.setText(displayImagesArrayAdapter.getItem(DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_ENABLED)); } else { - displayImagesTextView.setText(displayImagesArrayAdapter.getItem(2)); + displayImagesTextView.setText(displayImagesArrayAdapter.getItem(DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_DISABLED)); } - // Set the display website images icon and `TextView` settings. + // Set the display website images icon and `TextView` settings. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons. switch (displayImagesInt) { case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT: - if (MainWebViewActivity.displayWebpageImagesBoolean) { + if (defaultDisplayWebpageImagesBoolean) { // Display webpage images enabled by default. // Set the icon according to the theme. if (MainWebViewActivity.darkTheme) { displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark)); } else { displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_light)); } - } else { + } else { // Display webpage images disabled by default. // Set the icon according to the theme. if (MainWebViewActivity.darkTheme) { displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_disabled_dark)); @@ -554,9 +596,79 @@ public class DomainSettingsFragment extends Fragment { displayImagesTextView.setVisibility(View.GONE); break; } + + // Open the display images spinner when the `TextView` is clicked. + displayImagesTextView.setOnClickListener((View v) -> { + // Open the user agent spinner. + displayWebpageImagesSpinner.performClick(); + }); + + // Display the night mode in the spinner. + nightModeSpinner.setSelection(nightModeInt); + + // Set the default night mode text. + if (defaultNightModeBoolean) { + nightModeTextView.setText(nightModeArrayAdapter.getItem(DomainsDatabaseHelper.NIGHT_MODE_ENABLED)); + } else { + nightModeTextView.setText(nightModeArrayAdapter.getItem(DomainsDatabaseHelper.NIGHT_MODE_DISABLED)); + } + + // Set the night mode icon and `TextView` settings. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons. + switch (displayImagesInt) { + case DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT: + if (defaultNightModeBoolean) { // Night mode enabled by default. + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark)); + } else { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light)); + } + } else { // Night mode disabled by default. + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark)); + } else { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light)); + } + } + + // Show `nightModeTextView`. + nightModeTextView.setVisibility(View.VISIBLE); + break; + + case DomainsDatabaseHelper.NIGHT_MODE_ENABLED: + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark)); + } else { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light)); + } + + // Hide `nightModeTextView`. + nightModeTextView.setVisibility(View.GONE); + break; + + case DomainsDatabaseHelper.NIGHT_MODE_DISABLED: + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark)); + } else { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light)); + } + + // Hide `nightModeTextView`. + nightModeTextView.setVisibility(View.GONE); + break; + } + + // Open the night mode spinner when the `TextView` is clicked. + nightModeTextView.setOnClickListener((View v) -> { + // Open the user agent spinner. + nightModeSpinner.performClick(); + }); // Set the pinned SSL certificate icon. - if (pinnedSslCertificateInt == 1) { // Pinned SSL certificate is enabled. + if (pinnedSslCertificateInt == 1) { // Pinned SSL certificate is enabled. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons. // Check the switch. pinnedSslCertificateSwitch.setChecked(true); @@ -734,137 +846,122 @@ public class DomainSettingsFragment extends Fragment { // Set the `javaScriptEnabledSwitch` `OnCheckedChangeListener()`. - javaScriptEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { // JavaScript is enabled. - // Update the JavaScript icon. - javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.javascript_enabled)); + javaScriptEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + if (isChecked) { // JavaScript is enabled. + // Update the JavaScript icon. + javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.javascript_enabled)); - // Enable the DOM storage `Switch`. - domStorageEnabledSwitch.setEnabled(true); + // Enable the DOM storage `Switch`. + domStorageEnabledSwitch.setEnabled(true); - // Update the DOM storage icon. - if (domStorageEnabledSwitch.isChecked()) { // DOM storage is enabled. - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled)); - } else { // DOM storage is disabled. - // Set the icon according to the theme. - if (MainWebViewActivity.darkTheme) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark)); - } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light)); - } - } - } else { // JavaScript is disabled. - // Update the JavaScript icon. - javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.privacy_mode)); - - // Disable the DOM storage `Switch`. - domStorageEnabledSwitch.setEnabled(false); - - // Set the DOM storage icon according to the theme. + // Update the DOM storage icon. + if (domStorageEnabledSwitch.isChecked()) { // DOM storage is enabled. + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled)); + } else { // DOM storage is disabled. + // Set the icon according to the theme. if (MainWebViewActivity.darkTheme) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_dark)); + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark)); } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_light)); + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light)); } } + } else { // JavaScript is disabled. + // Update the JavaScript icon. + javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.privacy_mode)); + + // Disable the DOM storage `Switch`. + domStorageEnabledSwitch.setEnabled(false); + + // Set the DOM storage icon according to the theme. + if (MainWebViewActivity.darkTheme) { + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_dark)); + } else { + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_light)); + } } }); // Set the `firstPartyCookiesEnabledSwitch` `OnCheckedChangeListener()`. - firstPartyCookiesEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(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`. - thirdPartyCookiesEnabledSwitch.setEnabled(true); - - // Update the third-party cookies icon. - if (thirdPartyCookiesEnabledSwitch.isChecked()) { // Third-party cookies are enabled. - 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 (MainWebViewActivity.darkTheme) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark)); - } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light)); - } - } - } else { // First-party cookies are disabled. - // Update the first-party cookies icon according to the theme. - if (MainWebViewActivity.darkTheme) { - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark)); - } else { - firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light)); - } + firstPartyCookiesEnabledSwitch.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)); - // Disable the third-party cookies `Switch`. - thirdPartyCookiesEnabledSwitch.setEnabled(false); + // Enable the third-party cookies `Switch`. + thirdPartyCookiesEnabledSwitch.setEnabled(true); + // Update the third-party cookies icon. + if (thirdPartyCookiesEnabledSwitch.isChecked()) { // Third-party cookies are enabled. + 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 (MainWebViewActivity.darkTheme) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_dark)); + thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark)); } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_light)); + thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light)); } } + } else { // First-party cookies are disabled. + // Update the first-party cookies icon according to the theme. + if (MainWebViewActivity.darkTheme) { + firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark)); + } else { + firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light)); + } + + // Disable the third-party cookies `Switch`. + thirdPartyCookiesEnabledSwitch.setEnabled(false); + + // Set the third-party cookies icon according to the theme. + if (MainWebViewActivity.darkTheme) { + thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_dark)); + } else { + thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_light)); + } } }); // Set the `thirdPartyCookiesEnabledSwitch` `OnCheckedChangeListener()`. - thirdPartyCookiesEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - // Update the icon. - if (isChecked) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_warning)); + thirdPartyCookiesEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + // Update the icon. + if (isChecked) { + thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_warning)); + } else { + // Update the third-party cookies icon according to the theme. + if (MainWebViewActivity.darkTheme) { + thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark)); } else { - // Update the third-party cookies icon according to the theme. - if (MainWebViewActivity.darkTheme) { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark)); - } else { - thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light)); - } + thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light)); } } }); // Set the `domStorageEnabledSwitch` `OnCheckedChangeListener()`. - domStorageEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - // Update the icon. - if (isChecked) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled)); + domStorageEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + // Update the icon. + if (isChecked) { + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled)); + } else { + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark)); } else { - // Set the icon according to the theme. - if (MainWebViewActivity.darkTheme) { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark)); - } else { - domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light)); - } + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light)); } } }); // Set the `formDataEnabledSwitch` `OnCheckedChangeListener()`. - formDataEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - // Update the icon. - if (isChecked) { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_enabled)); + formDataEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + // Update the icon. + if (isChecked) { + formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_enabled)); + } else { + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_dark)); } else { - // Set the icon according to the theme. - if (MainWebViewActivity.darkTheme) { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_dark)); - } else { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_light)); - } + formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_light)); } } }); @@ -962,7 +1059,7 @@ public class DomainSettingsFragment extends Fragment { // Update the icon and the visibility of `displayImagesTextView`. switch (position) { case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT: - if (MainWebViewActivity.displayWebpageImagesBoolean) { + if (defaultDisplayWebpageImagesBoolean) { // Set the icon according to the theme. if (MainWebViewActivity.darkTheme) { displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark)); @@ -1013,103 +1110,203 @@ public class DomainSettingsFragment extends Fragment { // Do nothing. } }); - - // Set the `pinnedSSLCertificateSwitch` `onCheckedChangeListener()`. - pinnedSslCertificateSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + + // Set the `nightModeSpinner` `onItemSelectedListener()`. + nightModeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - // Update the icon - if (isChecked) { // Pinned SSL certificate is enabled. - // Set the icon according to the theme. - if (MainWebViewActivity.darkTheme) { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_dark)); - } else { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_light)); - } + public void onItemSelected(AdapterView parent, View view, int position, long id) { + // Update the icon and the visibility of `nightModeTextView`. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons. + switch (position) { + case DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT: + if (defaultNightModeBoolean) { // Night mode enabled by default. + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark)); + } else { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light)); + } + } else { // Night mode disabled by default. + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark)); + } else { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light)); + } + } - // Update the visibility of the saved SSL certificate. - if (savedSslCertificateIssuedToCNameString == null) { - savedSslCertificateLinearLayout.setVisibility(View.GONE); - } else { - savedSslCertificateLinearLayout.setVisibility(View.VISIBLE); - } + // Show `nightModeTextView`. + nightModeTextView.setVisibility(View.VISIBLE); + break; - // Update the visibility of the current website SSL certificate. - if (currentWebsiteSslCertificate == null) { - // Hide the SSL certificate. - currentWebsiteCertificateLinearLayout.setVisibility(View.GONE); + case DomainsDatabaseHelper.NIGHT_MODE_ENABLED: + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark)); + } else { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light)); + } - // Show the instruction. - noCurrentWebsiteCertificateTextView.setVisibility(View.VISIBLE); - } else { - // Show the SSL certificate. - currentWebsiteCertificateLinearLayout.setVisibility(View.VISIBLE); + // Hide `nightModeTextView`. + nightModeTextView.setVisibility(View.GONE); + break; + + case DomainsDatabaseHelper.NIGHT_MODE_DISABLED: + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark)); + } else { + nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light)); + } + + // Hide `nightModeTextView`. + nightModeTextView.setVisibility(View.GONE); + break; + } - // Hide the instruction. - noCurrentWebsiteCertificateTextView.setVisibility(View.GONE); + // Create a `boolean` to store the current night mode setting. + boolean currentNightModeEnabled = (position == DomainsDatabaseHelper.NIGHT_MODE_ENABLED) || ((position == DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT) && defaultNightModeBoolean); + + // Disable the JavaScript `Switch` if night mode is enabled. + if (currentNightModeEnabled) { + javaScriptEnabledSwitch.setEnabled(false); + } else { + javaScriptEnabledSwitch.setEnabled(true); + } + + // Update the JavaScript icon. + if ((javaScriptEnabledInt == 1) || currentNightModeEnabled) { + javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.javascript_enabled)); + } else { + javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.privacy_mode)); + } + + // Update the DOM storage status. + if ((javaScriptEnabledInt == 1) || currentNightModeEnabled) { // JavaScript is enabled. + // Enable the DOM storage `Switch`. + domStorageEnabledSwitch.setEnabled(true); + + // Set the DOM storage status. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons. + if (domStorageEnabledInt == 1) { // Both JavaScript and DOM storage are enabled. + domStorageEnabledSwitch.setChecked(true); + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled)); + } else { // JavaScript is enabled but DOM storage is disabled. + // Set the DOM storage switch to off. + domStorageEnabledSwitch.setChecked(false); + + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark)); + } else { + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light)); + } } + } else { // JavaScript is disabled. + // Disable the DOM storage `Switch`. + domStorageEnabledSwitch.setEnabled(false); - // Set the status of the radio buttons. - if (savedSslCertificateLinearLayout.getVisibility() == View.VISIBLE) { // The saved SSL certificate is displayed. - savedSslCertificateRadioButton.setChecked(true); - currentWebsiteCertificateRadioButton.setChecked(false); - } else if (currentWebsiteCertificateLinearLayout.getVisibility() == View.VISIBLE) { // The saved SSL certificate is hidden but the current website SSL certificate is visible. - currentWebsiteCertificateRadioButton.setChecked(true); - savedSslCertificateRadioButton.setChecked(false); - } else { // Neither SSL certificate is visible. - savedSslCertificateRadioButton.setChecked(false); - currentWebsiteCertificateRadioButton.setChecked(false); + // Set the checked status of DOM storage. + if (domStorageEnabledInt == 1) { // DOM storage is enabled but JavaScript is disabled. + domStorageEnabledSwitch.setChecked(true); + } else { // Both JavaScript and DOM storage are disabled. + domStorageEnabledSwitch.setChecked(false); } - } else { // Pinned SSL certificate is disabled. + // Set the icon according to the theme. if (MainWebViewActivity.darkTheme) { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_dark)); + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_dark)); } else { - pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_light)); + domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_light)); } + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + // Do nothing. + } + }); + + // Set the `pinnedSSLCertificateSwitch` `onCheckedChangeListener()`. + pinnedSslCertificateSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + // Update the icon + if (isChecked) { // Pinned SSL certificate is enabled. + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_dark)); + } else { + pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_enabled_light)); + } - // Hide the SSl certificates and instructions. + // Update the visibility of the saved SSL certificate. + if (savedSslCertificateIssuedToCNameString == null) { savedSslCertificateLinearLayout.setVisibility(View.GONE); + } else { + savedSslCertificateLinearLayout.setVisibility(View.VISIBLE); + } + + // Update the visibility of the current website SSL certificate. + if (currentWebsiteSslCertificate == null) { + // Hide the SSL certificate. currentWebsiteCertificateLinearLayout.setVisibility(View.GONE); + + // Show the instruction. + noCurrentWebsiteCertificateTextView.setVisibility(View.VISIBLE); + } else { + // Show the SSL certificate. + currentWebsiteCertificateLinearLayout.setVisibility(View.VISIBLE); + + // Hide the instruction. noCurrentWebsiteCertificateTextView.setVisibility(View.GONE); + } - // Uncheck the radio buttons. + // Set the status of the radio buttons. + if (savedSslCertificateLinearLayout.getVisibility() == View.VISIBLE) { // The saved SSL certificate is displayed. + savedSslCertificateRadioButton.setChecked(true); + currentWebsiteCertificateRadioButton.setChecked(false); + } else if (currentWebsiteCertificateLinearLayout.getVisibility() == View.VISIBLE) { // The saved SSL certificate is hidden but the current website SSL certificate is visible. + currentWebsiteCertificateRadioButton.setChecked(true); + savedSslCertificateRadioButton.setChecked(false); + } else { // Neither SSL certificate is visible. savedSslCertificateRadioButton.setChecked(false); currentWebsiteCertificateRadioButton.setChecked(false); } - } - }); + } else { // Pinned SSL certificate is disabled. + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_dark)); + } else { + pinnedSslCertificateImageView.setImageDrawable(resources.getDrawable(R.drawable.ssl_certificate_disabled_light)); + } - savedSslCertificateLinearLayout.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - savedSslCertificateRadioButton.setChecked(true); + // Hide the SSl certificates and instructions. + savedSslCertificateLinearLayout.setVisibility(View.GONE); + currentWebsiteCertificateLinearLayout.setVisibility(View.GONE); + noCurrentWebsiteCertificateTextView.setVisibility(View.GONE); + + // Uncheck the radio buttons. + savedSslCertificateRadioButton.setChecked(false); currentWebsiteCertificateRadioButton.setChecked(false); } }); - savedSslCertificateRadioButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - savedSslCertificateRadioButton.setChecked(true); - currentWebsiteCertificateRadioButton.setChecked(false); - } + savedSslCertificateLinearLayout.setOnClickListener((View v) -> { + savedSslCertificateRadioButton.setChecked(true); + currentWebsiteCertificateRadioButton.setChecked(false); }); - currentWebsiteCertificateLinearLayout.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - currentWebsiteCertificateRadioButton.setChecked(true); - savedSslCertificateRadioButton.setChecked(false); - } + savedSslCertificateRadioButton.setOnClickListener((View v) -> { + savedSslCertificateRadioButton.setChecked(true); + currentWebsiteCertificateRadioButton.setChecked(false); }); - currentWebsiteCertificateRadioButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - currentWebsiteCertificateRadioButton.setChecked(true); - savedSslCertificateRadioButton.setChecked(false); - } + currentWebsiteCertificateLinearLayout.setOnClickListener((View v) -> { + currentWebsiteCertificateRadioButton.setChecked(true); + savedSslCertificateRadioButton.setChecked(false); + }); + + currentWebsiteCertificateRadioButton.setOnClickListener((View v) -> { + currentWebsiteCertificateRadioButton.setChecked(true); + savedSslCertificateRadioButton.setChecked(false); }); return domainSettingsView;