- // Update the enabled status of the move icons.
- updateMoveIcons();
- break;
-
- case R.id.move_to_folder:
- // Store `checkedItemIds` for use by the `AlertDialog`.
- checkedItemIds = bookmarksListView.getCheckedItemIds();
-
- // Show the `MoveToFolderDialog` `AlertDialog` and name the instance `@string/move_to_folder
- AppCompatDialogFragment moveToFolderDialog = new MoveToFolderDialog();
- moveToFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.move_to_folder));
- break;
-
- case R.id.edit_bookmark:
- // Get the array of checked bookmark positions.
- selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
-
- // Get the position of the selected bookmark. Only one bookmark is selected when `edit_bookmark_down` is enabled.
- selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(0);
-
- // Move the `Cursor` to the selected position and find out if it is a folder.
- bookmarksCursor.moveToPosition(selectedBookmarkPosition);
- boolean isFolder = (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1);
-
- // Get the selected bookmark database ID.
- int databaseId = bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper._ID));
-
- // Show the edit bookmark or edit bookmark folder dialog.
- if (isFolder) {
- // Save the current folder name, which is used in `onSaveBookmarkFolder()`.
- oldFolderNameString = bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
-
- // Show the edit bookmark folder dialog.
- AppCompatDialogFragment editFolderDialog = EditBookmarkFolderDialog.folderDatabaseId(databaseId);
- editFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.edit_folder));
- } else {
- // Show the edit bookmark dialog.
- AppCompatDialogFragment editBookmarkDialog = EditBookmarkDialog.bookmarkDatabaseId(databaseId);
- editBookmarkDialog.show(getSupportFragmentManager(), getResources().getString(R.string.edit_bookmark));
+ // Update the enabled status of the move icons.
+ updateMoveIcons();
+ } else if (menuItemId == R.id.move_to_folder) { // Move to folder.
+ // Instantiate the move to folder alert dialog.
+ DialogFragment moveToFolderDialog = MoveToFolderDialog.moveBookmarks(currentFolder, bookmarksListView.getCheckedItemIds());
+
+ // Show the move to folder alert dialog.
+ moveToFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.move_to_folder));
+ } else if (menuItemId == R.id.edit_bookmark) {
+ // Get the array of checked bookmark positions.
+ selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
+
+ // Get the position of the bookmark that is selected. If other bookmarks have previously been selected they will be included in the sparse boolean array with a value of `false`.
+ for (int i = 0; i < selectedBookmarksPositionsSparseBooleanArray.size(); i++) {
+ // Check to see if the value for the bookmark is true, meaning it is currently selected.
+ if (selectedBookmarksPositionsSparseBooleanArray.valueAt(i)) {
+ // Only one bookmark should have a value of `true` when move edit bookmark is enabled.
+ selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(i);
+ }
+ }
+
+ // Move the cursor to the selected position.
+ bookmarksCursor.moveToPosition(selectedBookmarkPosition);
+
+ // Find out if this bookmark is a folder.
+ boolean isFolder = (bookmarksCursor.getInt(bookmarksCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.IS_FOLDER)) == 1);
+
+ // Get the selected bookmark database ID.
+ int databaseId = bookmarksCursor.getInt(bookmarksCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.ID));
+
+ // Show the edit bookmark or edit bookmark folder dialog.
+ if (isFolder) {
+ // Save the current folder name, which is used in `onSaveBookmarkFolder()`.
+ oldFolderNameString = bookmarksCursor.getString(bookmarksCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.BOOKMARK_NAME));
+
+ // Instantiate the edit bookmark folder dialog.
+ DialogFragment editFolderDialog = EditBookmarkFolderDialog.folderDatabaseId(databaseId, favoriteIconBitmap);
+
+ // Make it so.
+ editFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.edit_folder));
+ } else {
+ // Instantiate the edit bookmark dialog.
+ DialogFragment editBookmarkDialog = EditBookmarkDialog.bookmarkDatabaseId(databaseId, favoriteIconBitmap);
+
+ // Make it so.
+ editBookmarkDialog.show(getSupportFragmentManager(), getResources().getString(R.string.edit_bookmark));
+ }
+ } else if (menuItemId == R.id.delete_bookmark) { // 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();
+
+ // Initialize a variable to count the number of bookmarks to delete.
+ int numberOfBookmarksToDelete = 0;
+
+ // Count the number of bookmarks.
+ for (long databaseIdLong : selectedBookmarksIdsLongArray) {
+ // Convert the database ID long to an int.
+ int databaseIdInt = (int) databaseIdLong;
+
+ // Count the contents of the folder if the selected bookmark is a folder.
+ if (bookmarksDatabaseHelper.isFolder(databaseIdInt)) {
+ // Add the bookmarks from the folder to the running total.
+ numberOfBookmarksToDelete = numberOfBookmarksToDelete + countBookmarkFolderContents(databaseIdInt);