+ // Create the domain and store the database ID in `currentDomainDatabaseId`.
+ currentDomainDatabaseId = domainsDatabaseHelper.addDomain(domainNameString);
+
+ // Display the newly created domain.
+ if (twoPanedMode) { // The device in in two-paned mode.
+ populateDomainsListView(currentDomainDatabaseId);
+ } else { // The device is in single-paned mode.
+ // Hide the add domain floating action button.
+ addDomainFAB.hide();
+
+ // Show and enable `deleteMenuItem`.
+ DomainsActivity.deleteMenuItem.setVisible(true);
+
+ // Add the current domain database ID to the arguments bundle.
+ Bundle argumentsBundle = new Bundle();
+ argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, currentDomainDatabaseId);
+
+ // Add and arguments bundle to the domain setting fragment.
+ DomainSettingsFragment domainSettingsFragment = new DomainSettingsFragment();
+ domainSettingsFragment.setArguments(argumentsBundle);
+
+ // Display the domain settings fragment.
+ getSupportFragmentManager().beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit();
+ }
+ }
+
+ public void saveDomainSettings(View view, Resources resources) {
+ // Get handles for the domain settings.
+ EditText domainNameEditText = view.findViewById(R.id.domain_settings_name_edittext);
+ Switch javaScriptSwitch = view.findViewById(R.id.javascript_switch);
+ Switch firstPartyCookiesSwitch = view.findViewById(R.id.first_party_cookies_switch);
+ Switch thirdPartyCookiesSwitch = view.findViewById(R.id.third_party_cookies_switch);
+ Switch domStorageSwitch = view.findViewById(R.id.dom_storage_switch);
+ Switch formDataSwitch = view.findViewById(R.id.form_data_switch); // Form data can be removed once the minimum API >= 26.
+ Switch easyListSwitch = view.findViewById(R.id.easylist_switch);
+ Switch easyPrivacySwitch = view.findViewById(R.id.easyprivacy_switch);
+ Switch fanboysAnnoyanceSwitch = view.findViewById(R.id.fanboys_annoyance_list_switch);
+ Switch fanboysSocialBlockingSwitch = view.findViewById(R.id.fanboys_social_blocking_list_switch);
+ Switch ultraListSwitch = view.findViewById(R.id.ultralist_switch);
+ Switch ultraPrivacySwitch = view.findViewById(R.id.ultraprivacy_switch);
+ Switch blockAllThirdPartyRequestsSwitch = view.findViewById(R.id.block_all_third_party_requests_switch);
+ Spinner userAgentSpinner = view.findViewById(R.id.user_agent_spinner);
+ EditText customUserAgentEditText = view.findViewById(R.id.custom_user_agent_edittext);
+ Spinner fontSizeSpinner = view.findViewById(R.id.font_size_spinner);
+ EditText customFontSizeEditText = view.findViewById(R.id.custom_font_size_edittext);
+ Spinner swipeToRefreshSpinner = view.findViewById(R.id.swipe_to_refresh_spinner);
+ Spinner nightModeSpinner = view.findViewById(R.id.night_mode_spinner);
+ Spinner wideViewportSpinner = view.findViewById(R.id.wide_viewport_spinner);
+ Spinner displayWebpageImagesSpinner = view.findViewById(R.id.display_webpage_images_spinner);
+ Switch pinnedSslCertificateSwitch = view.findViewById(R.id.pinned_ssl_certificate_switch);
+ RadioButton currentWebsiteCertificateRadioButton = view.findViewById(R.id.current_website_certificate_radiobutton);
+ Switch pinnedIpAddressesSwitch = view.findViewById(R.id.pinned_ip_addresses_switch);
+ RadioButton currentIpAddressesRadioButton = view.findViewById(R.id.current_ip_addresses_radiobutton);
+
+ // Extract the data for the domain settings.
+ String domainNameString = domainNameEditText.getText().toString();
+ boolean javaScript = javaScriptSwitch.isChecked();
+ boolean firstPartyCookies = firstPartyCookiesSwitch.isChecked();
+ boolean thirdPartyCookies = thirdPartyCookiesSwitch.isChecked();
+ boolean domStorage = domStorageSwitch.isChecked();
+ boolean formData = formDataSwitch.isChecked(); // Form data can be removed once the minimum API >= 26.
+ boolean easyList = easyListSwitch.isChecked();
+ boolean easyPrivacy = easyPrivacySwitch.isChecked();
+ boolean fanboysAnnoyance = fanboysAnnoyanceSwitch.isChecked();
+ boolean fanboysSocialBlocking = fanboysSocialBlockingSwitch.isChecked();
+ boolean ultraList = ultraListSwitch.isChecked();
+ boolean ultraPrivacy = ultraPrivacySwitch.isChecked();
+ boolean blockAllThirdPartyRequests = blockAllThirdPartyRequestsSwitch.isChecked();
+ int userAgentSwitchPosition = userAgentSpinner.getSelectedItemPosition();
+ int fontSizeSwitchPosition = fontSizeSpinner.getSelectedItemPosition();
+ int swipeToRefreshInt = swipeToRefreshSpinner.getSelectedItemPosition();
+ int nightModeInt = nightModeSpinner.getSelectedItemPosition();
+ int wideViewportInt = wideViewportSpinner.getSelectedItemPosition();
+ int displayWebpageImagesInt = displayWebpageImagesSpinner.getSelectedItemPosition();
+ boolean pinnedSslCertificate = pinnedSslCertificateSwitch.isChecked();
+ boolean pinnedIpAddress = pinnedIpAddressesSwitch.isChecked();
+
+ // Initialize the user agent name string.
+ String userAgentName;
+
+ // Set the user agent name.
+ switch (userAgentSwitchPosition) {
+ case MainWebViewActivity.DOMAINS_SYSTEM_DEFAULT_USER_AGENT:
+ // Set the user agent name to be `System default user agent`.
+ userAgentName = resources.getString(R.string.system_default_user_agent);
+ break;
+
+ case MainWebViewActivity.DOMAINS_CUSTOM_USER_AGENT:
+ // Set the user agent name to be the custom user agent.
+ userAgentName = customUserAgentEditText.getText().toString();
+ break;
+
+ default:
+ // Get the array of user agent names.
+ String[] userAgentNameArray = resources.getStringArray(R.array.user_agent_names);
+
+ // Set the user agent name from the array. The domain spinner has one more entry than the name array, so the position must be decremented.
+ userAgentName = userAgentNameArray[userAgentSwitchPosition - 1];
+ }
+
+ // Initialize the font size integer. `0` indicates the system default font size.
+ int fontSizeInt = 0;
+
+ // Use a custom font size if it is selected.
+ if (fontSizeSwitchPosition == 1) { // A custom font size is specified.
+ // Get the custom font size from the edit text.
+ fontSizeInt = Integer.parseInt(customFontSizeEditText.getText().toString());
+ }
+
+ // Save the domain settings.
+ domainsDatabaseHelper.updateDomain(DomainsActivity.currentDomainDatabaseId, domainNameString, javaScript, firstPartyCookies, thirdPartyCookies, domStorage, formData, easyList, easyPrivacy,
+ fanboysAnnoyance, fanboysSocialBlocking, ultraList, ultraPrivacy, blockAllThirdPartyRequests, userAgentName, fontSizeInt, swipeToRefreshInt, nightModeInt, wideViewportInt,
+ displayWebpageImagesInt, pinnedSslCertificate, pinnedIpAddress);
+
+ // Update the pinned SSL certificate if a new one is checked.
+ if (currentWebsiteCertificateRadioButton.isChecked()) {
+ // Update the database.
+ domainsDatabaseHelper.updatePinnedSslCertificate(currentDomainDatabaseId, sslIssuedToCName, sslIssuedToOName, sslIssuedToUName, sslIssuedByCName, sslIssuedByOName, sslIssuedByUName,
+ sslStartDateLong, sslEndDateLong);
+ }