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'
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
}
} 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.
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
}
}