]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java
Make first-party cookies tab aware.
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / DomainsActivity.java
index 3f3b942889bb51267bc19a009798e5405fc37eee..11a73078cecbf83979a45c0a25e90c462a6f056e 100644 (file)
@@ -23,11 +23,13 @@ import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
+import android.content.SharedPreferences;
 import android.content.res.Resources;
 import android.database.Cursor;
 import android.net.http.SslCertificate;
 import android.os.Bundle;
 import android.os.Handler;
+import android.preference.PreferenceManager;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
@@ -118,13 +120,20 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
+        // Get a handle for the shared preferences.
+        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+        // Get the theme and screenshot preferences.
+        boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+        boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
         // Disable screenshots if not allowed.
-        if (!MainWebViewActivity.allowScreenshots) {
+        if (!allowScreenshots) {
             getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
         }
 
         // Set the activity theme.
-        if (MainWebViewActivity.darkTheme) {
+        if (darkTheme) {
             setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
         } else {
             setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
@@ -136,18 +145,21 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
         // Extract the values from `savedInstanceState` if it is not `null`.
         if (savedInstanceState != null) {
             restartAfterRotate = true;
-            domainSettingsDisplayedBeforeRotate = savedInstanceState.getBoolean("domainSettingsDisplayed");
-            domainSettingsDatabaseIdBeforeRotate = savedInstanceState.getInt("domainSettingsDatabaseId");
+            domainSettingsDisplayedBeforeRotate = savedInstanceState.getBoolean("domain_settings_displayed");
+            domainSettingsDatabaseIdBeforeRotate = savedInstanceState.getInt("domain_settings_database_id");
         }
 
         // 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);
+        goDirectlyToDatabaseId = intent.getIntExtra("load_domain", -1);
 
         // Get the status of close-on-back, which is true when the domains activity is called from the options menu.
-        closeOnBack = intent.getBooleanExtra("closeOnBack", false);
+        closeOnBack = intent.getBooleanExtra("close_on_back", false);
+
+        // Get the current URL.
+        String currentUrl = intent.getStringExtra("current_url");
 
         // Set the content view.
         setContentView(R.layout.domains_coordinatorlayout);
@@ -175,11 +187,15 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
         // Determine if we are in two pane mode.  `domain_settings_fragment_container` does not exist on devices with a width less than 900dp.
         twoPanedMode = (findViewById(R.id.domain_settings_fragment_container) != null);
 
-        // Configure `addDomainFAB`.
+        // Get a handle for the add domain floating action button.
         addDomainFAB = findViewById(R.id.add_domain_fab);
+
+        // Configure the add domain floating action button.
         addDomainFAB.setOnClickListener((View view) -> {
-            // Show the add domain `AlertDialog`.
-            DialogFragment addDomainDialog = new AddDomainDialog();
+            // Create an add domain dialog.
+            DialogFragment addDomainDialog = AddDomainDialog.addDomain(currentUrl);
+
+            // Show the add domain dialog.
             addDomainDialog.show(getSupportFragmentManager(), resources.getString(R.string.add_domain));
         });
     }
@@ -229,7 +245,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                 // Show `deleteMenuItem`.
                 deleteMenuItem.setVisible(true);
 
-                // Hide `add_domain_fab`.
+                // Hide the add domain floating action button.
                 addDomainFAB.hide();
 
                 // Display `domainSettingsFragment`.
@@ -260,7 +276,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                     // Show `deleteMenuItem`.
                     deleteMenuItem.setVisible(true);
 
-                    // Hide `add_domain_fab`.
+                    // Hide the add domain floating action button.
                     addDomainFAB.hide();
 
                     // Display `domainSettingsFragment`.
@@ -326,7 +342,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                     // Populate the list of domains.  `-1` highlights the first domain if in two-paned mode.  It has no effect in single-paned mode.
                     populateDomainsListView(-1);
 
-                    // Show the add domain FAB.
+                    // Show the add domain floating action button.
                     addDomainFAB.show();
 
                     // Hide the delete menu item.
@@ -370,7 +386,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                     fragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit();
                     fragmentManager.executePendingTransactions();
 
-                    // Show the add domain FAB.
+                    // Show the add domain floating action button.
                     addDomainFAB.show();
 
                     // Hide `deleteMenuItem`.
@@ -463,7 +479,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                                             // Display `domainSettingsFragment`.
                                             fragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit();
 
-                                            // Hide the add domain FAB.
+                                            // Hide the add domain floating action button.
                                             addDomainFAB.hide();
 
                                             // Show and enable `deleteMenuItem`.
@@ -485,11 +501,17 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
                                             Runnable enableDeleteMenuItemRunnable = () -> {
                                                 // Enable `deleteMenuItem` according to the display mode.
                                                 if (twoPanedMode) {  // Two-paned mode.
-                                                    // Enable `deleteMenuItem`.
+                                                    // Enable the delete menu item.
                                                     deleteMenuItem.setEnabled(true);
 
+                                                    // Get a handle for the shared preferences.
+                                                    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+
+                                                    // Get the theme preferences.
+                                                    boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
                                                     // Set the delete icon according to the theme.
-                                                    if (MainWebViewActivity.darkTheme) {
+                                                    if (darkTheme) {
                                                         deleteMenuItem.setIcon(R.drawable.delete_dark);
                                                     } else {
                                                         deleteMenuItem.setIcon(R.drawable.delete_light);
@@ -536,11 +558,11 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
             saveDomainSettings(coordinatorLayout, resources);
 
             // Store `DomainSettingsDisplayed`.
-            outState.putBoolean("domainSettingsDisplayed", true);
-            outState.putInt("domainSettingsDatabaseId", DomainSettingsFragment.databaseId);
+            outState.putBoolean("domain_settings_displayed", true);
+            outState.putInt("domain_settings_database_id", DomainSettingsFragment.databaseId);
         } else {  // `DomainSettingsFragment` is not displayed.
-            outState.putBoolean("domainSettingsDisplayed", false);
-            outState.putInt("domainSettingsDatabaseId", -1);
+            outState.putBoolean("domain_settings_displayed", false);
+            outState.putInt("domain_settings_database_id", -1);
         }
 
         super.onSaveInstanceState(outState);
@@ -587,7 +609,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
             // Populate the list of domains.  `-1` highlights the first domain if in two-paned mode.  It has no effect in single-paned mode.
             populateDomainsListView(-1);
 
-            // Show the add domain FAB.
+            // Show the add domain floating action button.
             addDomainFAB.show();
 
             // Hide the delete menu item.
@@ -625,7 +647,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
         if (twoPanedMode) {  // The device in in two-paned mode.
             populateDomainsListView(currentDomainDatabaseId);
         } else {  // The device is in single-paned mode.
-            // Hide the add domain FAB.
+            // Hide the add domain floating action button.
             addDomainFAB.hide();
 
             // Show and enable `deleteMenuItem`.
@@ -816,8 +838,14 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo
             // Enable the delete options menu items.
             deleteMenuItem.setEnabled(true);
 
+            // Get a handle for the shared preferences.
+            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+            // Get the theme and screenshot preferences.
+            boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+
             // Set the delete icon according to the theme.
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 deleteMenuItem.setIcon(R.drawable.delete_dark);
             } else {
                 deleteMenuItem.setIcon(R.drawable.delete_light);