]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt
Release 3.18.
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / DomainsActivity.kt
index a4e3505aa19f18b80c710f0a8526770fee77cdde..e0e068769ea1ed8888aee4ab4e7d7169c3858606 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2017-2024 Soren Stoutner <soren@stoutner.com>.
  *
 /*
  * Copyright 2017-2024 Soren Stoutner <soren@stoutner.com>.
  *
- * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
+ * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android/>.
  *
  * Privacy Browser Android is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * Privacy Browser Android is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -23,7 +23,6 @@ import android.app.Activity
 import android.content.Context
 import android.database.Cursor
 import android.os.Bundle
 import android.content.Context
 import android.database.Cursor
 import android.os.Bundle
-import android.os.Handler
 import android.view.Menu
 import android.view.MenuItem
 import android.view.View
 import android.view.Menu
 import android.view.MenuItem
 import android.view.View
@@ -570,27 +569,21 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
                                     }
                                 } else {  // The snackbar was dismissed without the undo button being pushed.
                                     // Delete the selected domain.
                                     }
                                 } else {  // The snackbar was dismissed without the undo button being pushed.
                                     // Delete the selected domain.
-                                    domainsDatabaseHelper.deleteDomain(databaseIdToDelete)
-
-                                    // Enable the delete menu item if the system was waiting for a snackbar to be dismissed.
-                                    if (dismissingSnackbar) {
-                                        // Create a runnable to enable the delete menu item.
-                                        val enableDeleteMenuItemRunnable = Runnable {
-                                            // Enable or show the delete menu item according to the display mode.
-                                            if (twoPanedMode)
-                                                deleteMenuItem.isEnabled = true
-                                            else
-                                                deleteMenuItem.isVisible = true
-
-                                            // Reset the dismissing snackbar tracker.
-                                            dismissingSnackbar = false
-                                        }
-
-                                        // Instantiate a handler running the main looper.
-                                        val handler = Handler(mainLooper)
-
-                                        // Enable or show the delete menu icon after 100 milliseconds to make sure that the previous domain has been deleted from the database.
-                                        handler.postDelayed(enableDeleteMenuItemRunnable, 100)
+                                    val rowsDeleted = domainsDatabaseHelper.deleteDomain(databaseIdToDelete)
+
+                                    // Enable the delete menu item.
+                                    // The rows deleted should always be greater than 0, but in all cases they should be greater than -1.
+                                    // This has the effect of tricking the compiler into waiting until after the delete finishes to reenable the delete menu item,
+                                    // because the compiler (probably) can't tell that the response will never be less than -1, so it doesn't compile out the delay.
+                                    if (rowsDeleted > -1) {
+                                        // Enable or show the delete menu item according to the display mode.
+                                        if (twoPanedMode)
+                                            deleteMenuItem.isEnabled = true
+                                        else
+                                            deleteMenuItem.isVisible = true
+
+                                        // Reset the dismissing snackbar tracker.
+                                        dismissingSnackbar = false
                                     }
 
                                     // Close the activity if back was pressed.
                                     }
 
                                     // Close the activity if back was pressed.
@@ -610,9 +603,9 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
         return true
     }
 
         return true
     }
 
-    override fun onSaveInstanceState(savedInstanceState: Bundle) {
+    override fun onSaveInstanceState(outState: Bundle) {
         // Run the default commands.
         // Run the default commands.
-        super.onSaveInstanceState(savedInstanceState)
+        super.onSaveInstanceState(outState)
 
         // Get a handle for the domain settings scrollview.
         val domainSettingsScrollView = findViewById<ScrollView>(R.id.domain_settings_scrollview)
 
         // Get a handle for the domain settings scrollview.
         val domainSettingsScrollView = findViewById<ScrollView>(R.id.domain_settings_scrollview)
@@ -620,9 +613,9 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
         // Check to see if the domain settings scrollview exists.
         if (domainSettingsScrollView == null) {  // The domain settings are not displayed.
             // Store the domain settings status in the bundle.
         // Check to see if the domain settings scrollview exists.
         if (domainSettingsScrollView == null) {  // The domain settings are not displayed.
             // Store the domain settings status in the bundle.
-            savedInstanceState.putBoolean(DOMAIN_SETTINGS_DISPLAYED, false)
-            savedInstanceState.putInt(DOMAIN_SETTINGS_DATABASE_ID, -1)
-            savedInstanceState.putInt(DOMAIN_SETTINGS_SCROLL_Y, 0)
+            outState.putBoolean(DOMAIN_SETTINGS_DISPLAYED, false)
+            outState.putInt(DOMAIN_SETTINGS_DATABASE_ID, -1)
+            outState.putInt(DOMAIN_SETTINGS_SCROLL_Y, 0)
         } else {  // The domain settings are displayed.
             // Save any changes that have been made to the domain settings.
             saveDomainSettings(coordinatorLayout)
         } else {  // The domain settings are displayed.
             // Save any changes that have been made to the domain settings.
             saveDomainSettings(coordinatorLayout)
@@ -631,9 +624,9 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
             val domainSettingsScrollY = domainSettingsScrollView.scrollY
 
             // Store the domain settings status in the bundle.
             val domainSettingsScrollY = domainSettingsScrollView.scrollY
 
             // Store the domain settings status in the bundle.
-            savedInstanceState.putBoolean(DOMAIN_SETTINGS_DISPLAYED, true)
-            savedInstanceState.putInt(DOMAIN_SETTINGS_DATABASE_ID, DomainSettingsFragment.databaseId)
-            savedInstanceState.putInt(DOMAIN_SETTINGS_SCROLL_Y, domainSettingsScrollY)
+            outState.putBoolean(DOMAIN_SETTINGS_DISPLAYED, true)
+            outState.putInt(DOMAIN_SETTINGS_DATABASE_ID, DomainSettingsFragment.databaseId)
+            outState.putInt(DOMAIN_SETTINGS_SCROLL_Y, domainSettingsScrollY)
         }
 
         // Check to see if the domains listview exists.
         }
 
         // Check to see if the domains listview exists.
@@ -642,7 +635,7 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
             val domainsListViewPosition = domainsListView!!.firstVisiblePosition
 
             // Store the listview position in the bundle.
             val domainsListViewPosition = domainsListView!!.firstVisiblePosition
 
             // Store the listview position in the bundle.
-            savedInstanceState.putInt(LISTVIEW_POSITION, domainsListViewPosition)
+            outState.putInt(LISTVIEW_POSITION, domainsListViewPosition)
         }
     }
 
         }
     }