Disable the delete bookmarks menu item if a delete process is pending. https://redmi...
authorSoren Stoutner <soren@stoutner.com>
Mon, 23 Oct 2017 21:53:40 +0000 (14:53 -0700)
committerSoren Stoutner <soren@stoutner.com>
Mon, 23 Oct 2017 21:53:40 +0000 (14:53 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java
app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java

index 97b4f3a6e39f588be07a2bf71a5623c274615845..42b1c0e1f0b06447c5334f251771c4b00f98cb6d 100644 (file)
@@ -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`.
index de68623e5eaa5974253a8ba78fd5dc146c101a4d..9970c888f966e3d68e9a5bc4168a2ee035cad876 100644 (file)
@@ -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