From: Soren Stoutner Date: Mon, 11 Mar 2024 23:29:14 +0000 (-0700) Subject: Improve domain settings delete icon reenablement. https://redmine.stoutner.com/issue... X-Git-Tag: v3.18~9 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=35dd941d73d9d72a1ae8c16add68f20615affada;p=PrivacyBrowserAndroid.git Improve domain settings delete icon reenablement. https://redmine.stoutner.com/issues/174 --- diff --git a/app/build.gradle b/app/build.gradle index 0a8c3a72..861e9165 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt index a4e3505a..4996568e 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt @@ -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. diff --git a/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.kt b/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.kt index 22ee1a25..38ce8992 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.kt @@ -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 } } diff --git a/build.gradle b/build.gradle index 9ab25062..0ba31c86 100644 --- a/build.gradle +++ b/build.gradle @@ -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