]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Add options menu item for adding/editing domain settings. https://redmine.stoutner...
authorSoren Stoutner <soren@stoutner.com>
Tue, 21 Nov 2017 05:11:14 +0000 (22:11 -0700)
committerSoren Stoutner <soren@stoutner.com>
Tue, 21 Nov 2017 05:11:14 +0000 (22:11 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/dialogs/AddDomainDialog.java
app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java
app/src/main/java/com/stoutner/privacybrowser/fragments/DomainsListFragment.java
app/src/main/res/menu/webview_options_menu.xml
app/src/main/res/values/strings.xml

index 9970c888f966e3d68e9a5bc4168a2ee035cad876..3090d8aaccde5e902478bc2f4034ea99460e74b3 100644 (file)
@@ -20,6 +20,7 @@
 package com.stoutner.privacybrowser.activities;
 
 import android.content.Context;
+import android.content.Intent;
 import android.database.Cursor;
 import android.net.http.SslCertificate;
 import android.os.Bundle;
@@ -30,6 +31,7 @@ import android.support.v4.app.FragmentManager;
 import android.support.v4.app.NavUtils;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
+// `AppCompatDialogFragment` is required instead of `DialogFragment` or an error is produced on API <=22.
 import android.support.v7.app.AppCompatDialogFragment;
 import android.support.v7.widget.Toolbar;
 import android.view.Menu;
@@ -60,7 +62,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
     // `deleteMenuItem` is public static so it can be accessed from `DomainsListFragment`.  It is also used in `onCreateOptionsMenu()`, `onOptionsItemSelected()`, and `onBackPressed()`.
     public static MenuItem deleteMenuItem;
 
-    // `undoDeleteSnackbar` is public static so it can be accessed from `DomainsListFragment`.  It is also used in `onOptionsItemSelected()`.
+    // `undoDeleteSnackbar` is public static so it can be accessed from `DomainsListFragment`.  It is also used in `onOptionsItemSelected()` and `onBackPressed()`.
     public static Snackbar undoDeleteSnackbar;
 
     // `dismissingSnackbar` is public static so it can be accessed from `DomainsListFragment`.  It is also used in `onOptionsItemSelected()`.
@@ -93,6 +95,9 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
     // `domainSettingsDatabaseIdBeforeRotate` is used in `onCreate()` and `onCreateOptionsMenu()`.
     private int domainSettingsDatabaseIdBeforeRotate;
 
+    // `goDirectlyToDatabaseId` is used in `onCreate()` and `onCreateOptionsMenu()`.
+    int goDirectlyToDatabaseId;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         // Set the activity theme.
@@ -112,6 +117,12 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
             domainSettingsDatabaseIdBeforeRotate = savedInstanceState.getInt("domainSettingsDatabaseId");
         }
 
+        // Get the launching intent
+        Intent intent = getIntent();
+
+        // Extract the domain to load if there is one.  `-1` is the default value.
+        goDirectlyToDatabaseId = intent.getIntExtra("LoadDomain", -1);
+
         // Set the content view.
         setContentView(R.layout.domains_coordinatorlayout);
 
@@ -121,8 +132,8 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
         // Get a handle for the fragment manager.
         supportFragmentManager = getSupportFragmentManager();
 
-        // We need to use the `SupportActionBar` from `android.support.v7.app.ActionBar` until the minimum API is >= 21.
-        final Toolbar domainsAppBar = (Toolbar) findViewById(R.id.domains_toolbar);
+        // `SupportActionBar` from `android.support.v7.app.ActionBar` must be used until the minimum API is >= 21.
+        final Toolbar domainsAppBar = findViewById(R.id.domains_toolbar);
         setSupportActionBar(domainsAppBar);
 
         // Display the home arrow on `SupportActionBar`.
@@ -137,14 +148,11 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
         twoPanedMode = (findViewById(R.id.domain_settings_fragment_container) != null);
 
         // Configure `addDomainFAB`.
-        addDomainFAB = (FloatingActionButton) findViewById(R.id.add_domain_fab);
-        addDomainFAB.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View view) {
-                // Show the `AddDomainDialog` `AlertDialog` and name the instance `@string/add_domain`.
-                AppCompatDialogFragment addDomainDialog = new AddDomainDialog();
-                addDomainDialog.show(supportFragmentManager, getResources().getString(R.string.add_domain));
-            }
+        addDomainFAB = findViewById(R.id.add_domain_fab);
+        addDomainFAB.setOnClickListener((View view) -> {
+            // Show the add domain `AlertDialog`.
+            AppCompatDialogFragment addDomainDialog = new AddDomainDialog();
+            addDomainDialog.show(supportFragmentManager, getResources().getString(R.string.add_domain));
         });
     }
 
@@ -160,48 +168,82 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
         deleteMenuItem.setVisible(twoPanedMode);
 
         // Display the fragments.  This must be done from `onCreateOptionsMenu()` instead of `onCreate()` because `populateDomainsListView()` needs `deleteMenuItem` to be inflated.
-        if (restartAfterRotate && !twoPanedMode && domainSettingsDisplayedBeforeRotate) {  // The device was rotated, the new configuration is in single-paned mode, and domain settings were displayed previously.
-            // Reset `restartAfterRotate`.
-            restartAfterRotate = false;
+        if (restartAfterRotate && domainSettingsDisplayedBeforeRotate) {  // The device was rotated and domain settings were displayed previously.
+            if (twoPanedMode) {  // The device is in two-paned mode.
+                // Reset `restartAfterRotate`.
+                restartAfterRotate = false;
 
-            // Store `currentDomainDatabaseId`.
-            currentDomainDatabaseId = domainSettingsDatabaseIdBeforeRotate;
+                // Display `DomainsListFragment`.
+                DomainsListFragment domainsListFragment = new DomainsListFragment();
+                supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit();
+                supportFragmentManager.executePendingTransactions();
 
-            // Add `currentDomainDatabaseId` to `argumentsBundle`.
-            Bundle argumentsBundle = new Bundle();
-            argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, currentDomainDatabaseId);
+                // Populate the list of domains.  `domainSettingsDatabaseId` highlights the domain that was highlighted before the rotation.
+                populateDomainsListView(domainSettingsDatabaseIdBeforeRotate);
+            } else {  // The device is in single-paned mode.
+                // Reset `restartAfterRotate`.
+                restartAfterRotate = false;
 
-            // Add `argumentsBundle` to `domainSettingsFragment`.
-            DomainSettingsFragment domainSettingsFragment = new DomainSettingsFragment();
-            domainSettingsFragment.setArguments(argumentsBundle);
+                // Store the current domain database ID.
+                currentDomainDatabaseId = domainSettingsDatabaseIdBeforeRotate;
 
-            // Show `deleteMenuItem`.
-            deleteMenuItem.setVisible(true);
+                // Add `currentDomainDatabaseId` to `argumentsBundle`.
+                Bundle argumentsBundle = new Bundle();
+                argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, currentDomainDatabaseId);
 
-            // Hide `add_domain_fab`.
-            addDomainFAB.setVisibility(View.GONE);
+                // Add `argumentsBundle` to `domainSettingsFragment`.
+                DomainSettingsFragment domainSettingsFragment = new DomainSettingsFragment();
+                domainSettingsFragment.setArguments(argumentsBundle);
 
-            // Display `domainSettingsFragment`.
-            supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit();
-        } else if (restartAfterRotate && twoPanedMode && domainSettingsDisplayedBeforeRotate) {  // The device was rotated, the new configuration is in two-paned mode, and domain settings were displayed previously.
-            // Reset `restartAfterRotate`.
-            restartAfterRotate = false;
+                // Show `deleteMenuItem`.
+                deleteMenuItem.setVisible(true);
 
-            // Display `DomainsListFragment`.
-            DomainsListFragment domainsListFragment = new DomainsListFragment();
-            supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit();
-            supportFragmentManager.executePendingTransactions();
+                // Hide `add_domain_fab`.
+                addDomainFAB.setVisibility(View.GONE);
 
-            // Populate the list of domains.  `domainSettingsDatabaseId` highlights the domain that was highlighted before the rotation.
-            populateDomainsListView(domainSettingsDatabaseIdBeforeRotate);
+                // Display `domainSettingsFragment`.
+                supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit();
+            }
         } else {  // The device was not rotated or, if it was, domain settings were not displayed previously.
-            // Display `DomainsListFragment`.
-            DomainsListFragment domainsListFragment = new DomainsListFragment();
-            supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit();
-            supportFragmentManager.executePendingTransactions();
+            if (goDirectlyToDatabaseId >=0) {  // Load the indicated domain settings.
+                // Store the current domain database ID.
+                currentDomainDatabaseId = goDirectlyToDatabaseId;
 
-            // Populate the list of domains.  `-1` highlights the first domain.
-            populateDomainsListView(-1);
+                if (twoPanedMode) {  // The device is in two-paned mode.
+                    // Display `DomainsListFragment`.
+                    DomainsListFragment domainsListFragment = new DomainsListFragment();
+                    supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit();
+                    supportFragmentManager.executePendingTransactions();
+
+                    // Populate the list of domains.  `domainSettingsDatabaseId` highlights the domain that was highlighted before the rotation.
+                    populateDomainsListView(goDirectlyToDatabaseId);
+                } else {  // The device is in single-paned mode.
+                    // Add the domain ID to be loaded to `argumentsBundle`.
+                    Bundle argumentsBundle = new Bundle();
+                    argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, goDirectlyToDatabaseId);
+
+                    // Add `argumentsBundle` to `domainSettingsFragment`.
+                    DomainSettingsFragment domainSettingsFragment = new DomainSettingsFragment();
+                    domainSettingsFragment.setArguments(argumentsBundle);
+
+                    // Show `deleteMenuItem`.
+                    deleteMenuItem.setVisible(true);
+
+                    // Hide `add_domain_fab`.
+                    addDomainFAB.setVisibility(View.GONE);
+
+                    // Display `domainSettingsFragment`.
+                    supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit();
+                }
+            } else {  // Highlight the first domain.
+                // Display `DomainsListFragment`.
+                DomainsListFragment domainsListFragment = new DomainsListFragment();
+                supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit();
+                supportFragmentManager.executePendingTransactions();
+
+                // Populate the list of domains.  `-1` highlights the first domain.
+                populateDomainsListView(-1);
+            }
         }
 
         // Success!
@@ -221,8 +263,23 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                         saveDomainSettings();
                     }
 
-                    // Go home.
-                    NavUtils.navigateUpFromSameTask(this);
+                    // Dismiss the undo delete `SnackBar` if it is shown.
+                    if (undoDeleteSnackbar != null && undoDeleteSnackbar.isShown()) {
+                        undoDeleteSnackbar.dismiss();
+
+                        // Create a `Runnable` to return to the main activity.
+                        Runnable navigateHomeRunnable = () -> {
+                            // Go home.
+                            NavUtils.navigateUpFromSameTask(this);
+                        };
+
+                        // Navigate home after 300 milliseconds to make sure that the previous domain has been deleted from the database.
+                        Handler handler = new Handler();
+                        handler.postDelayed(navigateHomeRunnable, 300);
+                    } else {
+                        // Go home.
+                        NavUtils.navigateUpFromSameTask(this);
+                    }
                 } else if (findViewById(R.id.domain_settings_scrollview) != null) {  // The device is in single-paned mode and `DomainSettingsFragment` is displayed.
                     // Save the current domain settings.
                     saveDomainSettings();
@@ -241,8 +298,23 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                     // Hide `deleteMenuItem`.
                     deleteMenuItem.setVisible(false);
                 } else {  // The device is in single-paned mode and `DomainsListFragment` is displayed.
-                    // Go home.
-                    NavUtils.navigateUpFromSameTask(this);
+                    // Dismiss the undo delete `SnackBar` if it is shown.
+                    if (undoDeleteSnackbar != null && undoDeleteSnackbar.isShown()) {
+                        undoDeleteSnackbar.dismiss();
+
+                        // Create a `Runnable` to return to the main activity.
+                        Runnable navigateHomeRunnable = () -> {
+                            // Go home.
+                            NavUtils.navigateUpFromSameTask(this);
+                        };
+
+                        // Navigate home after 300 milliseconds to make sure that the previous domain has been deleted from the database.
+                        Handler handler = new Handler();
+                        handler.postDelayed(navigateHomeRunnable, 300);
+                    } else {
+                        // Go home.
+                        NavUtils.navigateUpFromSameTask(this);
+                    }
                 }
                 break;
 
@@ -289,24 +361,21 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                     public void bindView(View view, Context context, Cursor cursor) {
                         // Set the domain name.
                         String domainNameString = cursor.getString(cursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME));
-                        TextView domainNameTextView = (TextView) view.findViewById(R.id.domain_name_textview);
+                        TextView domainNameTextView = view.findViewById(R.id.domain_name_textview);
                         domainNameTextView.setText(domainNameString);
                     }
                 };
 
                 // Update the handle for the current `domains_listview`.
-                domainsListView = (ListView) findViewById(R.id.domains_listview);
+                domainsListView = findViewById(R.id.domains_listview);
 
                 // Update the `ListView`.
                 domainsListView.setAdapter(domainsPendingDeleteCursorAdapter);
 
                 // Display a `Snackbar`.
                 undoDeleteSnackbar = Snackbar.make(domainsListView, R.string.domain_deleted, Snackbar.LENGTH_LONG)
-                        .setAction(R.string.undo, new View.OnClickListener() {
-                            @Override
-                            public void onClick(View v) {
-                                // Do nothing because everything will be handled by `onDismissed()` below.
-                            }
+                        .setAction(R.string.undo, (View v) -> {
+                            // Do nothing because everything will be handled by `onDismissed()` below.
                         })
                         .addCallback(new Snackbar.Callback() {
                             @Override
@@ -339,7 +408,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                                                 public void bindView(View view, Context context, Cursor cursor) {
                                                     // Set the domain name.
                                                     String domainNameString = cursor.getString(cursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME));
-                                                    TextView domainNameTextView = (TextView) view.findViewById(R.id.domain_name_textview);
+                                                    TextView domainNameTextView = view.findViewById(R.id.domain_name_textview);
                                                     domainNameTextView.setText(domainNameString);
                                                 }
                                             };
@@ -360,7 +429,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                                             supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit();
 
                                             // Hide `add_domain_fab`.
-                                            FloatingActionButton addDomainFAB = (FloatingActionButton) findViewById(R.id.add_domain_fab);
+                                            FloatingActionButton addDomainFAB = findViewById(R.id.add_domain_fab);
                                             addDomainFAB.setVisibility(View.GONE);
 
                                             // Show and enable `deleteMenuItem`.
@@ -379,28 +448,25 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                                         // enable `deleteMenuItem` if the system was waiting for a `Snackbar` to be dismissed.
                                         if (dismissingSnackbar) {
                                             // Create a `Runnable` to enable the delete menu item.
-                                            Runnable enableDeleteMenuItemRunnable = new Runnable() {
-                                                @Override
-                                                public void run() {
-                                                    // Enable `deleteMenuItem` according to the display mode.
-                                                    if (twoPanedMode) {  // Two-paned mode.
-                                                        // Enable `deleteMenuItem`.
-                                                        deleteMenuItem.setEnabled(true);
-
-                                                        // Set the delete icon according to the theme.
-                                                        if (MainWebViewActivity.darkTheme) {
-                                                            deleteMenuItem.setIcon(R.drawable.delete_dark);
-                                                        } else {
-                                                            deleteMenuItem.setIcon(R.drawable.delete_light);
-                                                        }
-                                                    } else {  // Single-paned mode.
-                                                        // Show `deleteMenuItem`.
-                                                        deleteMenuItem.setVisible(true);
+                                            Runnable enableDeleteMenuItemRunnable = () -> {
+                                                // Enable `deleteMenuItem` according to the display mode.
+                                                if (twoPanedMode) {  // Two-paned mode.
+                                                    // Enable `deleteMenuItem`.
+                                                    deleteMenuItem.setEnabled(true);
+
+                                                    // Set the delete icon according to the theme.
+                                                    if (MainWebViewActivity.darkTheme) {
+                                                        deleteMenuItem.setIcon(R.drawable.delete_dark);
+                                                    } else {
+                                                        deleteMenuItem.setIcon(R.drawable.delete_light);
                                                     }
-
-                                                    // Reset `dismissingSnackbar`.
-                                                    dismissingSnackbar = false;
+                                                } else {  // Single-paned mode.
+                                                    // Show `deleteMenuItem`.
+                                                    deleteMenuItem.setVisible(true);
                                                 }
+
+                                                // Reset `dismissingSnackbar`.
+                                                dismissingSnackbar = false;
                                             };
 
                                             // Run `enableDeleteMenuItemRunnable` after 100 milliseconds to make sure that the previous domain has been deleted from the database.
@@ -446,8 +512,23 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                 saveDomainSettings();
             }
 
-            // Go home.
-            NavUtils.navigateUpFromSameTask(this);
+            // Dismiss the undo delete `SnackBar` if it is shown.
+            if (undoDeleteSnackbar != null && undoDeleteSnackbar.isShown()) {
+                undoDeleteSnackbar.dismiss();
+
+                // Create a `Runnable` to return to the main activity.
+                Runnable navigateHomeRunnable = () -> {
+                    // Pass `onBackPressed()` to the system.
+                    super.onBackPressed();
+                };
+
+                // Navigate home after 300 milliseconds to make sure that the previous domain has been deleted from the database.
+                Handler handler = new Handler();
+                handler.postDelayed(navigateHomeRunnable, 300);
+            } else {
+                // Pass `onBackPressed()` to the system.
+                super.onBackPressed();
+            }
         } else if (findViewById(R.id.domain_settings_scrollview) != null) {  // The device is in single-paned mode and `DomainSettingsFragment` is displayed.
             // Save the current domain settings.
             saveDomainSettings();
@@ -466,8 +547,23 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
             // Hide `deleteMenuItem`.
             deleteMenuItem.setVisible(false);
         } else {  // The device is in single-paned mode and `DomainsListFragment` is displayed.
-            // Pass `onBackPressed()` to the system.
-            super.onBackPressed();
+            // Dismiss the undo delete `SnackBar` if it is shown.
+            if (undoDeleteSnackbar != null && undoDeleteSnackbar.isShown()) {
+                undoDeleteSnackbar.dismiss();
+
+                // Create a `Runnable` to return to the main activity.
+                Runnable navigateHomeRunnable = () -> {
+                    // Pass `onBackPressed()` to the system.
+                    super.onBackPressed();
+                };
+
+                // Navigate home after 300 milliseconds to make sure that the previous domain has been deleted from the database.
+                Handler handler = new Handler();
+                handler.postDelayed(navigateHomeRunnable, 300);
+            } else {
+                // Pass `onBackPressed()` to the system.
+                super.onBackPressed();
+            }
         }
     }
 
@@ -478,8 +574,8 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
             undoDeleteSnackbar.dismiss();
         }
 
-        // Get the `domainNameEditText` from `dialogFragment` and extract the string.
-        EditText domainNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.domain_name_edittext);
+        // Get the new domain name `String` from `dialogFragment`.
+        EditText domainNameEditText = dialogFragment.getDialog().findViewById(R.id.domain_name_edittext);
         String domainNameString = domainNameEditText.getText().toString();
 
         // Create the domain and store the database ID in `currentDomainDatabaseId`.
@@ -510,20 +606,20 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
 
     private void saveDomainSettings() {
         // Get handles for the domain settings.
-        EditText domainNameEditText = (EditText) findViewById(R.id.domain_settings_name_edittext);
-        Switch javaScriptEnabledSwitch = (Switch) findViewById(R.id.domain_settings_javascript_switch);
-        Switch firstPartyCookiesEnabledSwitch = (Switch) findViewById(R.id.domain_settings_first_party_cookies_switch);
-        Switch thirdPartyCookiesEnabledSwitch = (Switch) findViewById(R.id.domain_settings_third_party_cookies_switch);
-        Switch domStorageEnabledSwitch = (Switch) findViewById(R.id.domain_settings_dom_storage_switch);
-        Switch formDataEnabledSwitch = (Switch) findViewById(R.id.domain_settings_form_data_switch);
-        Spinner userAgentSpinner = (Spinner) findViewById(R.id.domain_settings_user_agent_spinner);
-        EditText customUserAgentEditText = (EditText) findViewById(R.id.domain_settings_custom_user_agent_edittext);
-        Spinner fontSizeSpinner = (Spinner) findViewById(R.id.domain_settings_font_size_spinner);
-        Spinner displayWebpageImagesSpinner = (Spinner) findViewById(R.id.domain_settings_display_webpage_images_spinner);
-        Spinner nightModeSpinner = (Spinner) findViewById(R.id.domain_settings_night_mode_spinner);
-        Switch pinnedSslCertificateSwitch = (Switch) findViewById(R.id.domain_settings_pinned_ssl_certificate_switch);
-        RadioButton savedSslCertificateRadioButton = (RadioButton) findViewById(R.id.saved_ssl_certificate_radiobutton);
-        RadioButton currentWebsiteCertificateRadioButton = (RadioButton) findViewById(R.id.current_website_certificate_radiobutton);
+        EditText domainNameEditText = findViewById(R.id.domain_settings_name_edittext);
+        Switch javaScriptEnabledSwitch = findViewById(R.id.domain_settings_javascript_switch);
+        Switch firstPartyCookiesEnabledSwitch = findViewById(R.id.domain_settings_first_party_cookies_switch);
+        Switch thirdPartyCookiesEnabledSwitch = findViewById(R.id.domain_settings_third_party_cookies_switch);
+        Switch domStorageEnabledSwitch = findViewById(R.id.domain_settings_dom_storage_switch);
+        Switch formDataEnabledSwitch = findViewById(R.id.domain_settings_form_data_switch);
+        Spinner userAgentSpinner = findViewById(R.id.domain_settings_user_agent_spinner);
+        EditText customUserAgentEditText = findViewById(R.id.domain_settings_custom_user_agent_edittext);
+        Spinner fontSizeSpinner = findViewById(R.id.domain_settings_font_size_spinner);
+        Spinner displayWebpageImagesSpinner = findViewById(R.id.domain_settings_display_webpage_images_spinner);
+        Spinner nightModeSpinner = findViewById(R.id.domain_settings_night_mode_spinner);
+        Switch pinnedSslCertificateSwitch = findViewById(R.id.domain_settings_pinned_ssl_certificate_switch);
+        RadioButton savedSslCertificateRadioButton = findViewById(R.id.saved_ssl_certificate_radiobutton);
+        RadioButton currentWebsiteCertificateRadioButton = findViewById(R.id.current_website_certificate_radiobutton);
 
         // Extract the data for the domain settings.
         String domainNameString = domainNameEditText.getText().toString();
@@ -580,7 +676,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
 
     private void populateDomainsListView(final int highlightedDomainDatabaseId) {
         // get a handle for the current `domains_listview`.
-        domainsListView = (ListView) findViewById(R.id.domains_listview);
+        domainsListView = findViewById(R.id.domains_listview);
 
         // Get a `Cursor` with the current contents of the domains database.
         Cursor domainsCursor = domainsDatabaseHelper.getDomainNameCursorOrderedByDomain();
@@ -597,7 +693,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
             public void bindView(View view, Context context, Cursor cursor) {
                 // Set the domain name.
                 String domainNameString = cursor.getString(cursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME));
-                TextView domainNameTextView = (TextView) view.findViewById(R.id.domain_name_textview);
+                TextView domainNameTextView = view.findViewById(R.id.domain_name_textview);
                 domainNameTextView.setText(domainNameString);
             }
         };
index 29332ebc599c6511fce76c686fd8c1c9af9c599a..8aad8721b596501867e0a30f4fa9c759fabfa3cd 100644 (file)
@@ -101,6 +101,7 @@ import android.widget.TextView;
 import com.stoutner.privacybrowser.BannerAd;
 import com.stoutner.privacybrowser.BuildConfig;
 import com.stoutner.privacybrowser.R;
+import com.stoutner.privacybrowser.dialogs.AddDomainDialog;
 import com.stoutner.privacybrowser.dialogs.CreateBookmarkDialog;
 import com.stoutner.privacybrowser.dialogs.CreateBookmarkFolderDialog;
 import com.stoutner.privacybrowser.dialogs.CreateHomeScreenShortcutDialog;
@@ -135,7 +136,7 @@ import java.util.Map;
 import java.util.Set;
 
 // We need to use AppCompatActivity from android.support.v7.app.AppCompatActivity to have access to the SupportActionBar until the minimum API is >= 21.
-public class MainWebViewActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener, CreateHomeScreenShortcutDialog.CreateHomeScreenSchortcutListener,
+public class MainWebViewActivity extends AppCompatActivity implements AddDomainDialog.AddDomainListener, CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener, CreateHomeScreenShortcutDialog.CreateHomeScreenSchortcutListener,
         DownloadFileDialog.DownloadFileListener, DownloadImageDialog.DownloadImageListener, EditBookmarkDialog.EditBookmarkListener, EditBookmarkFolderDialog.EditBookmarkFolderListener, HttpAuthenticationDialog.HttpAuthenticationListener,
         NavigationView.OnNavigationItemSelectedListener, PinnedSslCertificateMismatchDialog.PinnedSslCertificateMismatchListener, SslCertificateErrorDialog.SslCertificateErrorListener, UrlHistoryDialog.UrlHistoryListener {
 
@@ -178,8 +179,10 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
     // `loadBookmarksFolder()`.
     public static String currentBookmarksFolder;
 
-    // The pinned domain SSL Certificate variables are public static so they can be accessed from `PinnedSslCertificateMismatchDialog`.  They are also used in `onCreate()` and `applyDomainSettings()`.
+    // `domainSettingsDatabaseId` is public static so it can be accessed from `PinnedSslCertificateMismatchDialog`.  It is also used in `onCreate()`, `onOptionsItemSelected()`, and `applyDomainSettings()`.
     public static int domainSettingsDatabaseId;
+
+    // The pinned domain SSL Certificate variables are public static so they can be accessed from `PinnedSslCertificateMismatchDialog`.  They are also used in `onCreate()` and `applyDomainSettings()`.
     public static String pinnedDomainSslIssuedToCNameString;
     public static String pinnedDomainSslIssuedToONameString;
     public static String pinnedDomainSslIssuedToUNameString;
@@ -275,7 +278,10 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
     // `translucentNavigationBarOnFullscreen` is used in `onCreate()` and `applyAppSettings()`.
     private boolean translucentNavigationBarOnFullscreen;
 
-    // `currentDomainName` is used in `onCreate()`, `onNavigationItemSelected()`, `onSslMismatchProceed()`, and `applyDomainSettings()`.
+    // `reapplyDomainSettingsOnRestart` is used in `onCreate()`, `onOptionsItemSelected()`, `onNavigationItemSelected()`, `onRestart()`, and `onAddDomain()`, .
+    private boolean reapplyDomainSettingsOnRestart;
+
+    // `currentDomainName` is used in `onCreate()`, `onOptionsItemSelected()`, `onNavigationItemSelected()`, `onAddDomain()`, and `applyDomainSettings()`.
     private String currentDomainName;
 
     // `ignorePinnedSslCertificateForDomain` is used in `onCreate()`, `onSslMismatchProceed()`, and `applyDomainSettings()`.
@@ -284,7 +290,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
     // `waitingForOrbot` is used in `onCreate()` and `applyAppSettings()`.
     private boolean waitingForOrbot;
 
-    // `domainSettingsApplied` is used in `applyDomainSettings()` and `setDisplayWebpageImages()`.
+    // `domainSettingsApplied` is used in `prepareOptionsMenu()`, `applyDomainSettings()`, and `setDisplayWebpageImages()`.
     private boolean domainSettingsApplied;
 
     // `displayWebpageImagesInt` is used in `applyDomainSettings()` and `setDisplayWebpageImages()`.
@@ -1319,11 +1325,21 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
 
     @Override
     public void onRestart() {
+        // Run the default commands.
         super.onRestart();
 
         // Apply the app settings, which may have been changed in `SettingsActivity`.
         applyAppSettings();
 
+        // Apply the domain settings if returning from the Domains Activity.
+        if (reapplyDomainSettingsOnRestart) {
+            // Reset `reapplyDomainSettingsOnRestart`.
+            reapplyDomainSettingsOnRestart = false;
+
+            // Reapply the domain settings.
+            applyDomainSettings(formattedUrlString);
+        }
+
         // Update the privacy icon.  `true` runs `invalidateOptionsMenu` as the last step.
         updatePrivacyIcons(true);
 
@@ -1364,6 +1380,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
     // `onResume()` runs after `onStart()`, which runs after `onCreate()` and `onRestart()`.
     @Override
     public void onResume() {
+        // Run the default commands.
         super.onResume();
 
         // Resume JavaScript (if enabled).
@@ -1434,6 +1451,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
     @Override
     public boolean onPrepareOptionsMenu(Menu menu) {
         // Get handles for the menu items.
+        MenuItem addOrEditDomain = menu.findItem(R.id.add_or_edit_domain);
         MenuItem toggleFirstPartyCookiesMenuItem = menu.findItem(R.id.toggle_first_party_cookies);
         MenuItem toggleThirdPartyCookiesMenuItem = menu.findItem(R.id.toggle_third_party_cookies);
         MenuItem toggleDomStorageMenuItem = menu.findItem(R.id.toggle_dom_storage);
@@ -1445,6 +1463,13 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         MenuItem displayImagesMenuItem = menu.findItem(R.id.display_images);
         MenuItem refreshMenuItem = menu.findItem(R.id.refresh);
 
+        // Set the text for the domain menu item.
+        if (domainSettingsApplied) {
+            addOrEditDomain.setTitle(R.string.edit_domain_settings);
+        } else {
+            addOrEditDomain.setTitle(R.string.add_domain_settings);
+        }
+
         // Set the status of the menu item checkboxes.
         toggleFirstPartyCookiesMenuItem.setChecked(firstPartyCookiesEnabled);
         toggleThirdPartyCookiesMenuItem.setChecked(thirdPartyCookiesEnabled);
@@ -1559,6 +1584,27 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
 
         // Set the commands that relate to the menu entries.
         switch (menuItemId) {
+            case R.id.add_or_edit_domain:
+                if (domainSettingsApplied) {  // Edit the current domain settings.
+                    // Reapply the domain settings on returning to `MainWebViewActivity`.
+                    reapplyDomainSettingsOnRestart = true;
+                    currentDomainName = "";
+
+                    // Create an intent to launch the domains activity.
+                    Intent domainsIntent = new Intent(this, DomainsActivity.class);
+
+                    // Put extra information instructing the domains activity to directly load the current domain.
+                    domainsIntent.putExtra("LoadDomain", domainSettingsDatabaseId);
+
+                    // Make it so.
+                    startActivity(domainsIntent);
+                } else {  // Add a new domain.
+                    // Show the add domain `AlertDialog`.
+                    AppCompatDialogFragment addDomainDialog = new AddDomainDialog();
+                    addDomainDialog.show(getSupportFragmentManager(), getResources().getString(R.string.add_domain));
+                }
+                return true;
+
             case R.id.toggle_javascript:
                 // Switch the status of javaScriptEnabled.
                 javaScriptEnabled = !javaScriptEnabled;
@@ -1923,7 +1969,8 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                 break;
 
             case R.id.domains:
-                // Reset `currentDomainName` so that domain settings are reapplied after returning to `MainWebViewActivity`.
+                // Reapply the domain settings on returning to `MainWebViewActivity`.
+                reapplyDomainSettingsOnRestart = true;
                 currentDomainName = "";
 
                 // Launch `DomainsActivity`.
@@ -1932,7 +1979,8 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                 break;
 
             case R.id.settings:
-                // Reset `currentDomainName` so that domain settings are reapplied after returning to `MainWebViewActivity`.
+                // Reapply the domain settings on returning to `MainWebViewActivity`.
+                reapplyDomainSettingsOnRestart = true;
                 currentDomainName = "";
 
                 // Launch `SettingsActivity`.
@@ -2256,6 +2304,33 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         }
     }
 
+    @Override
+    public void onAddDomain(AppCompatDialogFragment dialogFragment) {
+        // Reapply the domain settings on returning to `MainWebViewActivity`.
+        reapplyDomainSettingsOnRestart = true;
+        currentDomainName = "";
+
+        // Get the new domain name `String` from `dialogFragment`.
+        EditText domainNameEditText = dialogFragment.getDialog().findViewById(R.id.domain_name_edittext);
+        String domainNameString = domainNameEditText.getText().toString();
+
+        // Initialize the database handler.  `this` specifies the context.  The two `nulls` do not specify the database name or a `CursorFactory`.
+        // The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.
+        DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(this, null, null, 0);
+
+        // Create the domain and store the database ID in `currentDomainDatabaseId`.
+        int newDomainDatabaseId = domainsDatabaseHelper.addDomain(domainNameString);
+
+        // Create an intent to launch the domains activity.
+        Intent domainsIntent = new Intent(this, DomainsActivity.class);
+
+        // Put extra information instructing the domains activity to directly load the current domain.
+        domainsIntent.putExtra("LoadDomain", newDomainDatabaseId);
+
+        // Make it so.
+        startActivity(domainsIntent);
+    }
+
     @Override
     public void onCreateBookmark(AppCompatDialogFragment dialogFragment) {
         // Get the `EditTexts` from the `dialogFragment`.
index 396e920d378639a636ee02ba42828f0a143ef01e..9c15026ce72e8eaeb555dd3346db23214a41fd0e 100644 (file)
@@ -85,26 +85,20 @@ public class AddDomainDialog extends AppCompatDialogFragment {
         dialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.add_domain_dialog, null));
 
         // Set an `onClick()` listener for the negative button.
-        dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
-            @Override
-            public void onClick(DialogInterface dialog, int which) {
-                // Do nothing.  The `AlertDialog` will close automatically.
-            }
+        dialogBuilder.setNegativeButton(R.string.cancel, (DialogInterface dialog, int which) -> {
+            // Do nothing.  The `AlertDialog` will close automatically.
         });
 
         // Set an `onClick()` listener for the positive button.
-        dialogBuilder.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
-            @Override
-            public void onClick(DialogInterface dialog, int which) {
-                // Return the `DialogFragment` to the parent activity on add.
-                addDomainListener.onAddDomain(AddDomainDialog.this);
-            }
+        dialogBuilder.setPositiveButton(R.string.add, (DialogInterface dialog, int which) -> {
+            // Return the `DialogFragment` to the parent activity on add.
+            addDomainListener.onAddDomain(AddDomainDialog.this);
         });
 
         // Create an `AlertDialog` from the `AlertDialog.Builder`.
         final AlertDialog alertDialog = dialogBuilder.create();
 
-        // Remove the warning below the `setSoftInputMode` might produce `java.lang.NullPointerException`.
+        // Remove the warning below that `setSoftInputMode` might produce `java.lang.NullPointerException`.
         assert alertDialog.getWindow() != null;
 
         // Show the keyboard when the `AlertDialog` is displayed on the screen.
@@ -117,8 +111,8 @@ public class AddDomainDialog extends AppCompatDialogFragment {
         final DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(getContext(), null, null, 0);
 
         // Get handles for the views in `alertDialog`.
-        final EditText addDomainEditText = (EditText) alertDialog.findViewById(R.id.domain_name_edittext);
-        final TextView domainNameAlreadyExistsTextView = (TextView) alertDialog.findViewById(R.id.domain_name_already_exists_textview);
+        final EditText addDomainEditText = alertDialog.findViewById(R.id.domain_name_edittext);
+        final TextView domainNameAlreadyExistsTextView = alertDialog.findViewById(R.id.domain_name_already_exists_textview);
         final Button addButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
 
         //  Update the status of the warning text and the `add` button.
@@ -156,19 +150,17 @@ public class AddDomainDialog extends AppCompatDialogFragment {
         addDomainEditText.setText(currentUri.getHost());
 
         // Allow the `enter` key on the keyboard to create the domain from `add_domain_edittext`.
-        addDomainEditText.setOnKeyListener(new View.OnKeyListener() {
-            public boolean onKey(View view, int keyCode, KeyEvent event) {
-                // If the event is a key-down on the `enter` key, select the `PositiveButton` `Add`.
-                if ((keyCode == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN)) {
-                    // Trigger `addDomainListener` and return the `DialogFragment` to the parent activity.
-                    addDomainListener.onAddDomain(AddDomainDialog.this);
-                    // Manually dismiss the `AlertDialog`.
-                    alertDialog.dismiss();
-                    // Consume the event.
-                    return true;
-                } else { // If any other key was pressed, do not consume the event.
-                    return false;
-                }
+        addDomainEditText.setOnKeyListener((View view, int keyCode, KeyEvent event) -> {
+            // If the event is a key-down on the `enter` key, select the `PositiveButton` `Add`.
+            if ((keyCode == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN)) {
+                // Trigger `addDomainListener` and return the `DialogFragment` to the parent activity.
+                addDomainListener.onAddDomain(AddDomainDialog.this);
+                // Manually dismiss the `AlertDialog`.
+                alertDialog.dismiss();
+                // Consume the event.
+                return true;
+            } else { // If any other key was pressed, do not consume the event.
+                return false;
             }
         });
 
index 0fd7a692d70c0e568ad80f9e1a5b06b020937045..bff624d3bb70182ef5dabf1178683adaac492bd0 100644 (file)
@@ -95,52 +95,52 @@ public class DomainSettingsFragment extends Fragment {
         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);
-        final 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);
-        final 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);
-        final 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);
-        final 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 nightModeImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_night_mode_imageview);
-        final Spinner nightModeSpinner = (Spinner) domainSettingsView.findViewById(R.id.domain_settings_night_mode_spinner);
-        final TextView nightModeTextView = (TextView) domainSettingsView.findViewById(R.id.domain_settings_night_mode_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) + "  ";
@@ -449,7 +449,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`.
@@ -509,12 +509,9 @@ public class DomainSettingsFragment extends Fragment {
         }
 
         // Open the user agent spinner when the `TextView` is clicked.
-        userAgentTextView.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                // Open the user agent spinner.
-                userAgentSpinner.performClick();
-            }
+        userAgentTextView.setOnClickListener((View v) -> {
+            // Open the user agent spinner.
+            userAgentSpinner.performClick();
         });
 
         // Set the selected font size.
@@ -533,12 +530,9 @@ public class DomainSettingsFragment extends Fragment {
         }
 
         // Open the font size spinner when the `TextView` is clicked.
-        fontSizeTextView.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                // Open the user agent spinner.
-                fontSizeSpinner.performClick();
-            }
+        fontSizeTextView.setOnClickListener((View v) -> {
+            // Open the user agent spinner.
+            fontSizeSpinner.performClick();
         });
 
         // Display the website images mode in the spinner.
@@ -600,12 +594,9 @@ public class DomainSettingsFragment extends Fragment {
         }
 
         // Open the display images spinner when the `TextView` is clicked.
-        displayImagesTextView.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                // Open the user agent spinner.
-                displayWebpageImagesSpinner.performClick();
-            }
+        displayImagesTextView.setOnClickListener((View v) -> {
+            // Open the user agent spinner.
+            displayWebpageImagesSpinner.performClick();
         });
 
         // Display the night mode in the spinner.
@@ -667,12 +658,9 @@ public class DomainSettingsFragment extends Fragment {
         }
 
         // Open the night mode spinner when the `TextView` is clicked.
-        nightModeTextView.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                // Open the user agent spinner.
-                nightModeSpinner.performClick();
-            }
+        nightModeTextView.setOnClickListener((View v) -> {
+            // Open the user agent spinner.
+            nightModeSpinner.performClick();
         });
         
         // Set the pinned SSL certificate icon.
@@ -854,137 +842,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));
-
-                    // 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));
+        javaScriptEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+            if (isChecked) {  // JavaScript is enabled.
+                // Update the JavaScript icon.
+                javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.javascript_enabled));
 
-                    // Disable the DOM storage `Switch`.
-                    domStorageEnabledSwitch.setEnabled(false);
+                // Enable the DOM storage `Switch`.
+                domStorageEnabledSwitch.setEnabled(true);
 
-                    // 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));
                 }
             }
         });
@@ -1250,101 +1223,86 @@ public class DomainSettingsFragment extends Fragment {
         });
         
         // Set the `pinnedSSLCertificateSwitch` `onCheckedChangeListener()`.
-        pinnedSslCertificateSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
-            @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));
-                    }
-
-                    // 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);
+        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));
+                }
 
-                        // Show the instruction.
-                        noCurrentWebsiteCertificateTextView.setVisibility(View.VISIBLE);
-                    } else {
-                        // Show the SSL certificate.
-                        currentWebsiteCertificateLinearLayout.setVisibility(View.VISIBLE);
+                // Update the visibility of the saved SSL certificate.
+                if (savedSslCertificateIssuedToCNameString == null) {
+                    savedSslCertificateLinearLayout.setVisibility(View.GONE);
+                } else {
+                    savedSslCertificateLinearLayout.setVisibility(View.VISIBLE);
+                }
 
-                        // Hide the instruction.
-                        noCurrentWebsiteCertificateTextView.setVisibility(View.GONE);
-                    }
+                // Update the visibility of the current website SSL certificate.
+                if (currentWebsiteSslCertificate == null) {
+                    // Hide the SSL certificate.
+                    currentWebsiteCertificateLinearLayout.setVisibility(View.GONE);
 
-                    // 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));
-                    }
+                    // Show the instruction.
+                    noCurrentWebsiteCertificateTextView.setVisibility(View.VISIBLE);
+                } else {
+                    // Show the SSL certificate.
+                    currentWebsiteCertificateLinearLayout.setVisibility(View.VISIBLE);
 
-                    // Hide the SSl certificates and instructions.
-                    savedSslCertificateLinearLayout.setVisibility(View.GONE);
-                    currentWebsiteCertificateLinearLayout.setVisibility(View.GONE);
+                    // 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;
index 172a6438279ce315366bde0b774ec762988845af..26a2bf30474a6eae272eea68c113c03197662d8d 100644 (file)
@@ -46,7 +46,7 @@ public class DomainsListFragment extends Fragment {
         View domainsListFragmentView = inflater.inflate(R.layout.domains_list_fragment, container, false);
 
         // Initialize `domainsListView`.
-        ListView domainsListView = (ListView) domainsListFragmentView.findViewById(R.id.domains_listview);
+        ListView domainsListView = domainsListFragmentView.findViewById(R.id.domains_listview);
 
         // Initialize the database handler.  The two `nulls` do not specify the database name or a `CursorFactory`.  The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.
         final DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(getContext(), null, null, 0);
@@ -54,131 +54,128 @@ public class DomainsListFragment extends Fragment {
         // Get a handle for `supportFragmentManager`.
         final FragmentManager supportFragmentManager = getActivity().getSupportFragmentManager();
 
-        domainsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
-            @Override
-            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-                // Dismiss `undoDeleteSnackbar` if it is currently displayed (because a domain has just been deleted).
-                if ((DomainsActivity.undoDeleteSnackbar != null) && (DomainsActivity.undoDeleteSnackbar.isShown())) {
-                    DomainsActivity.dismissingSnackbar = true;
+        domainsListView.setOnItemClickListener((AdapterView<?> parent, View view, int position, long id) -> {
+            // Dismiss `undoDeleteSnackbar` if it is currently displayed (because a domain has just been deleted).
+            if ((DomainsActivity.undoDeleteSnackbar != null) && (DomainsActivity.undoDeleteSnackbar.isShown())) {
+                DomainsActivity.dismissingSnackbar = true;
 
-                    DomainsActivity.undoDeleteSnackbar.dismiss();
-                }
+                DomainsActivity.undoDeleteSnackbar.dismiss();
+            }
 
-                // Save the current domain settings if operating in two-paned mode and a domain is currently selected.
-                if (DomainsActivity.twoPanedMode && DomainsActivity.deleteMenuItem.isEnabled()) {
-                    View domainSettingsFragmentView = supportFragmentManager.findFragmentById(R.id.domain_settings_fragment_container).getView();
-                    assert domainSettingsFragmentView != null;
-
-                    // Get handles for the domain settings.
-                    EditText domainNameEditText = (EditText) domainSettingsFragmentView.findViewById(R.id.domain_settings_name_edittext);
-                    Switch javaScriptEnabledSwitch = (Switch) domainSettingsFragmentView.findViewById(R.id.domain_settings_javascript_switch);
-                    Switch firstPartyCookiesEnabledSwitch = (Switch) domainSettingsFragmentView.findViewById(R.id.domain_settings_first_party_cookies_switch);
-                    Switch thirdPartyCookiesEnabledSwitch = (Switch) domainSettingsFragmentView.findViewById(R.id.domain_settings_third_party_cookies_switch);
-                    Switch domStorageEnabledSwitch = (Switch) domainSettingsFragmentView.findViewById(R.id.domain_settings_dom_storage_switch);
-                    Switch formDataEnabledSwitch = (Switch) domainSettingsFragmentView.findViewById(R.id.domain_settings_form_data_switch);
-                    Spinner userAgentSpinner = (Spinner) domainSettingsFragmentView.findViewById(R.id.domain_settings_user_agent_spinner);
-                    EditText customUserAgentEditText = (EditText) domainSettingsFragmentView.findViewById(R.id.domain_settings_custom_user_agent_edittext);
-                    Spinner fontSizeSpinner = (Spinner) domainSettingsFragmentView.findViewById(R.id.domain_settings_font_size_spinner);
-                    Spinner displayWebpageImagesSpinner = (Spinner) domainSettingsFragmentView.findViewById(R.id.domain_settings_display_webpage_images_spinner);
-                    Spinner nightModeSpinner = (Spinner) domainSettingsFragmentView.findViewById(R.id.domain_settings_night_mode_spinner);
-                    Switch pinnedSslCertificateSwitch = (Switch) domainSettingsFragmentView.findViewById(R.id.domain_settings_pinned_ssl_certificate_switch);
-                    RadioButton savedSslCertificateRadioButton = (RadioButton) domainSettingsFragmentView.findViewById(R.id.saved_ssl_certificate_radiobutton);
-                    RadioButton currentWebsiteCertificateRadioButton = (RadioButton) domainSettingsFragmentView.findViewById(R.id.current_website_certificate_radiobutton);
-
-                    // Extract the data for the domain settings.
-                    String domainNameString = domainNameEditText.getText().toString();
-                    boolean javaScriptEnabledBoolean = javaScriptEnabledSwitch.isChecked();
-                    boolean firstPartyCookiesEnabledBoolean = firstPartyCookiesEnabledSwitch.isChecked();
-                    boolean thirdPartyCookiesEnabledBoolean = thirdPartyCookiesEnabledSwitch.isChecked();
-                    boolean domStorageEnabledEnabledBoolean  = domStorageEnabledSwitch.isChecked();
-                    boolean formDataEnabledBoolean = formDataEnabledSwitch.isChecked();
-                    int userAgentPositionInt = userAgentSpinner.getSelectedItemPosition();
-                    int fontSizePositionInt = fontSizeSpinner.getSelectedItemPosition();
-                    int displayWebpageImagesInt = displayWebpageImagesSpinner.getSelectedItemPosition();
-                    int nightModeInt = nightModeSpinner.getSelectedItemPosition();
-                    boolean pinnedSslCertificate = pinnedSslCertificateSwitch.isChecked();
-
-                    // Get the data for the `Spinners` from the entry values string arrays.
-                    String userAgentString = getResources().getStringArray(R.array.domain_settings_user_agent_entry_values)[userAgentPositionInt];
-                    int fontSizeInt = Integer.parseInt(getResources().getStringArray(R.array.domain_settings_font_size_entry_values)[fontSizePositionInt]);
-
-                    // Check to see if we are using a custom user agent.
-                    if (userAgentString.equals("Custom user agent")) {
-                        // Set `userAgentString` to the custom user agent string.
-                        userAgentString = customUserAgentEditText.getText().toString();
-                    }
+            // Save the current domain settings if operating in two-paned mode and a domain is currently selected.
+            if (DomainsActivity.twoPanedMode && DomainsActivity.deleteMenuItem.isEnabled()) {
+                View domainSettingsFragmentView = supportFragmentManager.findFragmentById(R.id.domain_settings_fragment_container).getView();
+                assert domainSettingsFragmentView != null;
+
+                // Get handles for the domain settings.
+                EditText domainNameEditText = domainSettingsFragmentView.findViewById(R.id.domain_settings_name_edittext);
+                Switch javaScriptEnabledSwitch = domainSettingsFragmentView.findViewById(R.id.domain_settings_javascript_switch);
+                Switch firstPartyCookiesEnabledSwitch = domainSettingsFragmentView.findViewById(R.id.domain_settings_first_party_cookies_switch);
+                Switch thirdPartyCookiesEnabledSwitch = domainSettingsFragmentView.findViewById(R.id.domain_settings_third_party_cookies_switch);
+                Switch domStorageEnabledSwitch = domainSettingsFragmentView.findViewById(R.id.domain_settings_dom_storage_switch);
+                Switch formDataEnabledSwitch = domainSettingsFragmentView.findViewById(R.id.domain_settings_form_data_switch);
+                Spinner userAgentSpinner = domainSettingsFragmentView.findViewById(R.id.domain_settings_user_agent_spinner);
+                EditText customUserAgentEditText = domainSettingsFragmentView.findViewById(R.id.domain_settings_custom_user_agent_edittext);
+                Spinner fontSizeSpinner = domainSettingsFragmentView.findViewById(R.id.domain_settings_font_size_spinner);
+                Spinner displayWebpageImagesSpinner = domainSettingsFragmentView.findViewById(R.id.domain_settings_display_webpage_images_spinner);
+                Spinner nightModeSpinner = domainSettingsFragmentView.findViewById(R.id.domain_settings_night_mode_spinner);
+                Switch pinnedSslCertificateSwitch = domainSettingsFragmentView.findViewById(R.id.domain_settings_pinned_ssl_certificate_switch);
+                RadioButton savedSslCertificateRadioButton = domainSettingsFragmentView.findViewById(R.id.saved_ssl_certificate_radiobutton);
+                RadioButton currentWebsiteCertificateRadioButton = domainSettingsFragmentView.findViewById(R.id.current_website_certificate_radiobutton);
+
+                // Extract the data for the domain settings.
+                String domainNameString = domainNameEditText.getText().toString();
+                boolean javaScriptEnabledBoolean = javaScriptEnabledSwitch.isChecked();
+                boolean firstPartyCookiesEnabledBoolean = firstPartyCookiesEnabledSwitch.isChecked();
+                boolean thirdPartyCookiesEnabledBoolean = thirdPartyCookiesEnabledSwitch.isChecked();
+                boolean domStorageEnabledEnabledBoolean  = domStorageEnabledSwitch.isChecked();
+                boolean formDataEnabledBoolean = formDataEnabledSwitch.isChecked();
+                int userAgentPositionInt = userAgentSpinner.getSelectedItemPosition();
+                int fontSizePositionInt = fontSizeSpinner.getSelectedItemPosition();
+                int displayWebpageImagesInt = displayWebpageImagesSpinner.getSelectedItemPosition();
+                int nightModeInt = nightModeSpinner.getSelectedItemPosition();
+                boolean pinnedSslCertificate = pinnedSslCertificateSwitch.isChecked();
+
+                // Get the data for the `Spinners` from the entry values string arrays.
+                String userAgentString = getResources().getStringArray(R.array.domain_settings_user_agent_entry_values)[userAgentPositionInt];
+                int fontSizeInt = Integer.parseInt(getResources().getStringArray(R.array.domain_settings_font_size_entry_values)[fontSizePositionInt]);
+
+                // Check to see if we are using a custom user agent.
+                if (userAgentString.equals("Custom user agent")) {
+                    // Set `userAgentString` to the custom user agent string.
+                    userAgentString = customUserAgentEditText.getText().toString();
+                }
 
-                    // Save the domain settings.
-                    if (savedSslCertificateRadioButton.isChecked()) {  // The current certificate is being used.
-                        // Update the database except for the certificate.
-                        domainsDatabaseHelper.updateDomainExceptCertificate(DomainsActivity.currentDomainDatabaseId, domainNameString, javaScriptEnabledBoolean, firstPartyCookiesEnabledBoolean, thirdPartyCookiesEnabledBoolean, domStorageEnabledEnabledBoolean,
-                                formDataEnabledBoolean, userAgentString, fontSizeInt, displayWebpageImagesInt, nightModeInt, pinnedSslCertificate);
-                    } else if (currentWebsiteCertificateRadioButton.isChecked()) {  // The certificate is being updated with the current website certificate.
-                        // Get the current website SSL certificate.
-                        SslCertificate currentWebsiteSslCertificate = MainWebViewActivity.sslCertificate;
-
-                        // Store the values from the SSL certificate.
-                        String issuedToCommonName = currentWebsiteSslCertificate.getIssuedTo().getCName();
-                        String issuedToOrganization = currentWebsiteSslCertificate.getIssuedTo().getOName();
-                        String issuedToOrganizationalUnit = currentWebsiteSslCertificate.getIssuedTo().getUName();
-                        String issuedByCommonName = currentWebsiteSslCertificate.getIssuedBy().getCName();
-                        String issuedByOrganization = currentWebsiteSslCertificate.getIssuedBy().getOName();
-                        String issuedByOrganizationalUnit = currentWebsiteSslCertificate.getIssuedBy().getUName();
-                        long startDateLong = currentWebsiteSslCertificate.getValidNotBeforeDate().getTime();
-                        long endDateLong = currentWebsiteSslCertificate.getValidNotAfterDate().getTime();
-
-                        // Update the database.
-                        domainsDatabaseHelper.updateDomainWithCertificate(DomainsActivity.currentDomainDatabaseId, domainNameString, javaScriptEnabledBoolean, firstPartyCookiesEnabledBoolean, thirdPartyCookiesEnabledBoolean, domStorageEnabledEnabledBoolean,
-                                formDataEnabledBoolean, userAgentString, fontSizeInt, displayWebpageImagesInt, nightModeInt, pinnedSslCertificate, issuedToCommonName, issuedToOrganization, issuedToOrganizationalUnit, issuedByCommonName, issuedByOrganization,
-                                issuedByOrganizationalUnit, startDateLong, endDateLong);
-                    } else {  // No certificate is selected.
-                        // Update the database, with PINNED_SSL_CERTIFICATE set to false.
-                        domainsDatabaseHelper.updateDomainExceptCertificate(DomainsActivity.currentDomainDatabaseId, domainNameString, javaScriptEnabledBoolean, firstPartyCookiesEnabledBoolean, thirdPartyCookiesEnabledBoolean, domStorageEnabledEnabledBoolean,
-                                formDataEnabledBoolean, userAgentString, fontSizeInt, displayWebpageImagesInt, nightModeInt, false);
-                    }
+                // Save the domain settings.
+                if (savedSslCertificateRadioButton.isChecked()) {  // The current certificate is being used.
+                    // Update the database except for the certificate.
+                    domainsDatabaseHelper.updateDomainExceptCertificate(DomainsActivity.currentDomainDatabaseId, domainNameString, javaScriptEnabledBoolean, firstPartyCookiesEnabledBoolean, thirdPartyCookiesEnabledBoolean, domStorageEnabledEnabledBoolean,
+                            formDataEnabledBoolean, userAgentString, fontSizeInt, displayWebpageImagesInt, nightModeInt, pinnedSslCertificate);
+                } else if (currentWebsiteCertificateRadioButton.isChecked()) {  // The certificate is being updated with the current website certificate.
+                    // Get the current website SSL certificate.
+                    SslCertificate currentWebsiteSslCertificate = MainWebViewActivity.sslCertificate;
+
+                    // Store the values from the SSL certificate.
+                    String issuedToCommonName = currentWebsiteSslCertificate.getIssuedTo().getCName();
+                    String issuedToOrganization = currentWebsiteSslCertificate.getIssuedTo().getOName();
+                    String issuedToOrganizationalUnit = currentWebsiteSslCertificate.getIssuedTo().getUName();
+                    String issuedByCommonName = currentWebsiteSslCertificate.getIssuedBy().getCName();
+                    String issuedByOrganization = currentWebsiteSslCertificate.getIssuedBy().getOName();
+                    String issuedByOrganizationalUnit = currentWebsiteSslCertificate.getIssuedBy().getUName();
+                    long startDateLong = currentWebsiteSslCertificate.getValidNotBeforeDate().getTime();
+                    long endDateLong = currentWebsiteSslCertificate.getValidNotAfterDate().getTime();
+
+                    // Update the database.
+                    domainsDatabaseHelper.updateDomainWithCertificate(DomainsActivity.currentDomainDatabaseId, domainNameString, javaScriptEnabledBoolean, firstPartyCookiesEnabledBoolean, thirdPartyCookiesEnabledBoolean, domStorageEnabledEnabledBoolean,
+                            formDataEnabledBoolean, userAgentString, fontSizeInt, displayWebpageImagesInt, nightModeInt, pinnedSslCertificate, issuedToCommonName, issuedToOrganization, issuedToOrganizationalUnit, issuedByCommonName, issuedByOrganization,
+                            issuedByOrganizationalUnit, startDateLong, endDateLong);
+                } else {  // No certificate is selected.
+                    // Update the database, with PINNED_SSL_CERTIFICATE set to false.
+                    domainsDatabaseHelper.updateDomainExceptCertificate(DomainsActivity.currentDomainDatabaseId, domainNameString, javaScriptEnabledBoolean, firstPartyCookiesEnabledBoolean, thirdPartyCookiesEnabledBoolean, domStorageEnabledEnabledBoolean,
+                            formDataEnabledBoolean, userAgentString, fontSizeInt, displayWebpageImagesInt, nightModeInt, false);
                 }
+            }
 
-                // Store the new `currentDomainDatabaseId`, converting it from `long` to `int` to match the format of the domains database.
-                DomainsActivity.currentDomainDatabaseId = (int) id;
-
-                // Add `currentDomainDatabaseId` to `argumentsBundle`.
-                Bundle argumentsBundle = new Bundle();
-                argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, DomainsActivity.currentDomainDatabaseId);
-
-                // Add `argumentsBundle` to `domainSettingsFragment`.
-                DomainSettingsFragment domainSettingsFragment = new DomainSettingsFragment();
-                domainSettingsFragment.setArguments(argumentsBundle);
-
-                // Display the domain settings fragment.
-                if (DomainsActivity.twoPanedMode) {  // The device in in two-paned mode.
-                    // enable `deleteMenuItem` if the system is not waiting for a `Snackbar` to be dismissed.
-                    if (!DomainsActivity.dismissingSnackbar) {
-                        // Enable `deleteMenuItem`.
-                        DomainsActivity.deleteMenuItem.setEnabled(true);
-
-                        // Set the delete icon according to the theme.
-                        if (MainWebViewActivity.darkTheme) {
-                            DomainsActivity.deleteMenuItem.setIcon(R.drawable.delete_dark);
-                        } else {
-                            DomainsActivity.deleteMenuItem.setIcon(R.drawable.delete_light);
-                        }
+            // Store the new `currentDomainDatabaseId`, converting it from `long` to `int` to match the format of the domains database.
+            DomainsActivity.currentDomainDatabaseId = (int) id;
+
+            // Add `currentDomainDatabaseId` to `argumentsBundle`.
+            Bundle argumentsBundle = new Bundle();
+            argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, DomainsActivity.currentDomainDatabaseId);
+
+            // Add `argumentsBundle` to `domainSettingsFragment`.
+            DomainSettingsFragment domainSettingsFragment = new DomainSettingsFragment();
+            domainSettingsFragment.setArguments(argumentsBundle);
+
+            // Display the domain settings fragment.
+            if (DomainsActivity.twoPanedMode) {  // The device in in two-paned mode.
+                // enable `deleteMenuItem` if the system is not waiting for a `Snackbar` to be dismissed.
+                if (!DomainsActivity.dismissingSnackbar) {
+                    // Enable `deleteMenuItem`.
+                    DomainsActivity.deleteMenuItem.setEnabled(true);
+
+                    // Set the delete icon according to the theme.
+                    if (MainWebViewActivity.darkTheme) {
+                        DomainsActivity.deleteMenuItem.setIcon(R.drawable.delete_dark);
+                    } else {
+                        DomainsActivity.deleteMenuItem.setIcon(R.drawable.delete_light);
                     }
+                }
 
-                    // Display `domainSettingsFragment`.
-                    supportFragmentManager.beginTransaction().replace(R.id.domain_settings_fragment_container, domainSettingsFragment).commit();
-                } else { // The device in in single-paned mode
-                    // Show `deleteMenuItem` if the system is not waiting for a `Snackbar` to be dismissed.
-                    if (!DomainsActivity.dismissingSnackbar) {
-                        DomainsActivity.deleteMenuItem.setVisible(true);
-                    }
+                // Display `domainSettingsFragment`.
+                supportFragmentManager.beginTransaction().replace(R.id.domain_settings_fragment_container, domainSettingsFragment).commit();
+            } else { // The device in in single-paned mode
+                // Show `deleteMenuItem` if the system is not waiting for a `Snackbar` to be dismissed.
+                if (!DomainsActivity.dismissingSnackbar) {
+                    DomainsActivity.deleteMenuItem.setVisible(true);
+                }
 
-                    // Hide `add_domain_fab`.
-                    FloatingActionButton addDomainFAB = (FloatingActionButton) getActivity().findViewById(R.id.add_domain_fab);
-                    addDomainFAB.setVisibility(View.GONE);
+                // Hide `add_domain_fab`.
+                FloatingActionButton addDomainFAB = getActivity().findViewById(R.id.add_domain_fab);
+                addDomainFAB.setVisibility(View.GONE);
 
-                    // Display `domainSettingsFragment`.
-                    supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit();
-                }
+                // Display `domainSettingsFragment`.
+                supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit();
             }
         });
 
index df62da64ddb4361d5d110c177adbc03fad5fe9fd..b6af5e02181dda8266a8475f25748d4a1234e978 100644 (file)
@@ -22,7 +22,7 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
-    tools:context=".activities.MainWebViewActivity">
+    tools:context=".activities.MainWebViewActivity" >
 
     <item
         android:id="@+id/toggle_javascript"
         android:orderInCategory="10"
         app:showAsAction="ifRoom" />
 
+    <item
+        android:id="@+id/add_or_edit_domain"
+        android:title="@string/add_domain_settings"
+        android:orderInCategory="20"
+        app:showAsAction="never" />
+
     <item
         android:id="@+id/toggle_first_party_cookies"
         android:title="@string/first_party_cookies"
-        android:orderInCategory="20"
+        android:orderInCategory="30"
         android:checkable="true"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/toggle_third_party_cookies"
         android:title="@string/third_party_cookies"
-        android:orderInCategory="30"
+        android:orderInCategory="40"
         android:checkable="true"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/toggle_dom_storage"
         android:title="@string/dom_storage"
-        android:orderInCategory="40"
+        android:orderInCategory="50"
         android:checkable="true"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/toggle_save_form_data"
         android:title="@string/form_data"
-        android:orderInCategory="50"
+        android:orderInCategory="60"
         android:checkable="true"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/clear_cookies"
         android:title="@string/clear_cookies"
-        android:orderInCategory="60"
+        android:orderInCategory="70"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/clear_dom_storage"
         android:title="@string/clear_dom_storage"
-        android:orderInCategory="70"
+        android:orderInCategory="80"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/clear_form_data"
         android:title="@string/clear_form_data"
-        android:orderInCategory="80"
+        android:orderInCategory="90"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/font_size"
         android:title="@string/font_size"
-        android:orderInCategory="90"
+        android:orderInCategory="100"
         app:showAsAction="never" >
 
         <menu>
                 <item
                     android:id="@+id/font_size_twenty_five_percent"
                     android:title="@string/twenty_five_percent"
-                    android:orderInCategory="91"
+                    android:orderInCategory="101"
                     app:showAsAction="never" />
 
                 <item
                     android:id="@+id/font_size_fifty_percent"
                     android:title="@string/fifty_percent"
-                    android:orderInCategory="92"
+                    android:orderInCategory="102"
                     app:showAsAction="never" />
 
                 <item
                     android:id="@+id/font_size_seventy_five_percent"
                     android:title="@string/seventy_five_percent"
-                    android:orderInCategory="93"
+                    android:orderInCategory="103"
                     app:showAsAction="never" />
 
                 <item
                     android:id="@+id/font_size_one_hundred_percent"
                     android:title="@string/one_hundred_percent"
-                    android:orderInCategory="94"
+                    android:orderInCategory="104"
                     app:showAsAction="never" />
 
                 <item
                     android:id="@+id/font_size_one_hundred_twenty_five_percent"
                     android:title="@string/one_hundred_twenty_five_percent"
-                    android:orderInCategory="95"
+                    android:orderInCategory="105"
                     app:showAsAction="never" />
 
                 <item
                     android:id="@+id/font_size_one_hundred_fifty_percent"
                     android:title="@string/one_hundred_fifty_percent"
-                    android:orderInCategory="96"
+                    android:orderInCategory="106"
                     app:showAsAction="never" />
 
                 <item
                     android:id="@+id/font_size_one_hundred_seventy_five_percent"
                     android:title="@string/one_hundred_seventy_five_percent"
-                    android:orderInCategory="97"
+                    android:orderInCategory="107"
                     app:showAsAction="never" />
 
                 <item
                     android:id="@+id/font_size_two_hundred_percent"
                     android:title="@string/two_hundred_percent"
-                    android:orderInCategory="98"
+                    android:orderInCategory="108"
                     app:showAsAction="never" />
             </group>
         </menu>
     <item
         android:id="@+id/display_images"
         android:title="@string/display_images"
-        android:orderInCategory="100"
+        android:orderInCategory="110"
         android:checkable="true"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/share"
         android:title="@string/share"
-        android:orderInCategory="110"
+        android:orderInCategory="120"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/find_on_page"
         android:title="@string/find_on_page"
-        android:orderInCategory="120"
+        android:orderInCategory="130"
         app:showAsAction="never|collapseActionView" />
     <item
         android:id="@+id/print"
         android:title="@string/print"
-        android:orderInCategory="130"
+        android:orderInCategory="140"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/add_to_homescreen"
         android:title="@string/add_to_home_screen"
-        android:orderInCategory="140"
+        android:orderInCategory="150"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/refresh"
         android:title="@string/refresh"
-        android:orderInCategory="150"
+        android:orderInCategory="160"
         app:showAsAction="never" />
-
 </menu>
\ No newline at end of file
index 63c00d41e92173be4145c0bc65604ad4604c3fcf..12e64237a053cf269dff11f3adfbe9a46d4df675 100644 (file)
     <string name="clear_and_exit">Clear and Exit</string>
 
     <!-- MainWebViewActivity Options Menu. -->
+    <string name="edit_domain_settings">Edit Domain Settings</string>
+    <string name="add_domain_settings">Add Domain Settings</string>
     <string name="javascript">JavaScript</string>
     <string name="first_party_cookies">First-Party Cookies</string>
     <string name="third_party_cookies">Third-Party Cookies</string>