]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java
Use a spinner to select folders in the bookmarks database view. https://redmine...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / BookmarksActivity.java
index 97b4f3a6e39f588be07a2bf71a5623c274615845..e640b792291e208736931a21637a5a4ea51639cc 100644 (file)
@@ -116,8 +116,12 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         // Get the intent that launched the activity.
         Intent launchingIntent = getIntent();
 
-        // Get the current folder from the `Intent`.
-        currentFolder = launchingIntent.getStringExtra("Current Folder");
+        // Set the current folder variable.
+        if (launchingIntent.getStringExtra("Current Folder") != null) {  // Set the current folder from the intent.
+            currentFolder = launchingIntent.getStringExtra("Current Folder");
+        } else {  // Set the current folder to be `""`, which is the home folder.
+            currentFolder = "";
+        }
 
         // Set the content view.
         setContentView(R.layout.bookmarks_coordinatorlayout);
@@ -185,7 +189,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 +210,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 +422,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 +471,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 +503,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`.