]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Improve domain settings delete icon reenablement. https://redmine.stoutner.com/issue...
authorSoren Stoutner <soren@stoutner.com>
Mon, 11 Mar 2024 23:29:14 +0000 (16:29 -0700)
committerSoren Stoutner <soren@stoutner.com>
Mon, 11 Mar 2024 23:29:14 +0000 (16:29 -0700)
app/build.gradle
app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt
app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.kt
build.gradle

index 0a8c3a725417a70b742a2226788608b479a9671c..861e916570756a33453f03e52749e526ea041033 100644 (file)
@@ -97,7 +97,7 @@ dependencies {
     implementation 'androidx.webkit:webkit:1.10.0'
 
     // Include the Kotlin standard library.  This should be the same version number listed in project build.gradle.
-    implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.9.0'
+    implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.9.20'
 
     // Include the Google material library.
     implementation 'com.google.android.material:material:1.11.0'
index a4e3505aa19f18b80c710f0a8526770fee77cdde..4996568e1e79084b865a75b4098f670a89a2a53a 100644 (file)
@@ -23,7 +23,6 @@ import android.app.Activity
 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
@@ -570,27 +569,21 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
                                     }
                                 } 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.
index 22ee1a25afe4a79fac0e148bf7b9a1d00c82d5c1..38ce8992fcac52ee2a35d680aaacf69ac7525383 100644 (file)
@@ -532,14 +532,17 @@ class DomainsDatabaseHelper(private val appContext: Context) : SQLiteOpenHelper(
         domainsDatabase.close()
     }
 
-    fun deleteDomain(databaseId: Int) {
+    fun deleteDomain(databaseId: Int) : Int {
         // Get a writable database handle.
         val domainsDatabase = this.writableDatabase
 
         // Delete the row for the specified database ID.
-        domainsDatabase.delete(DOMAINS_TABLE, "$ID = $databaseId", null)
+        val rowsDeleted = domainsDatabase.delete(DOMAINS_TABLE, "$ID = $databaseId", null)
 
         // Close the database handle.
         domainsDatabase.close()
+
+        // Return the delete status.
+        return rowsDeleted
     }
 }
index 9ab250620ecbf9522026791337ce461e98de963e..0ba31c86d51a95cb7895a6d9b7330abd59fce0a5 100644 (file)
@@ -27,7 +27,7 @@ buildscript {
 
     dependencies {
         classpath 'com.android.tools.build:gradle:8.3.0'
-        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0"
+        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20"
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files