From a8669fa252bd4a278decc411912d6f8674ff483d Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Mon, 23 Oct 2017 14:53:40 -0700 Subject: [PATCH] Disable the delete bookmarks menu item if a delete process is pending. https://redmine.stoutner.com/issues/201 --- .../activities/BookmarksActivity.java | 19 ++++++++++++++++++- .../activities/DomainsActivity.java | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java index 97b4f3a6..42b1c0e1 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java @@ -185,7 +185,9 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma bookmarksListView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { // Instantiate the common variables. MenuItem editBookmarkMenuItem; + MenuItem deleteBookmarksMenuItem; MenuItem selectAllBookmarksMenuItem; + boolean deletingBookmarks; @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { @@ -204,8 +206,14 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma moveBookmarkUpMenuItem = menu.findItem(R.id.move_bookmark_up); moveBookmarkDownMenuItem = menu.findItem(R.id.move_bookmark_down); editBookmarkMenuItem = menu.findItem(R.id.edit_bookmark); + deleteBookmarksMenuItem = menu.findItem(R.id.delete_bookmark); selectAllBookmarksMenuItem = menu.findItem(R.id.context_menu_select_all_bookmarks); + // Disable the delete bookmarks menu item if a delete is pending. + if (deletingBookmarks) { + deleteBookmarksMenuItem.setEnabled(false); + } + // Store `contextualActionMode` so it can be closed programatically. contextualActionMode = mode; @@ -410,6 +418,9 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma break; case R.id.delete_bookmark: + // Set the deleting bookmarks flag, which prevents the delete menu item from being enabled until the current process finishes. + deletingBookmarks = true; + // Get an array of the selected row IDs. final long[] selectedBookmarksIdsLongArray = bookmarksListView.getCheckedItemIds(); @@ -456,6 +467,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma for (int i = 0; i < selectedBookmarksPositionsSparseBooleanArray.size(); i++) { bookmarksListView.setItemChecked(selectedBookmarksPositionsSparseBooleanArray.keyAt(i), true); } + break; // The `Snackbar` was dismissed without the `Undo` button being pushed. @@ -487,8 +499,13 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i); } } - break; } + + // Enable the delete bookmarks menu item. + deleteBookmarksMenuItem.setEnabled(true); + + // Reset the deleting bookmarks flag. + deletingBookmarks = false; } }) //Show the `SnackBar`. diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java index de68623e..9970c888 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java @@ -377,7 +377,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo domainsDatabaseHelper.deleteDomain(databaseIdToDelete); // enable `deleteMenuItem` if the system was waiting for a `Snackbar` to be dismissed. - if (DomainsActivity.dismissingSnackbar) { + if (dismissingSnackbar) { // Create a `Runnable` to enable the delete menu item. Runnable enableDeleteMenuItemRunnable = new Runnable() { @Override -- 2.45.2