- // 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));
- }
- 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();
-
- // Get the array of checked bookmarks. `.clone()` makes a copy that won't change if `bookmarksListView` is reloaded, which is needed for re-selecting the bookmarks on undelete.
- selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions().clone();
-
- // Update `bookmarksCursor` with the current contents of the bookmarks database except for the specified database IDs.
- bookmarksCursor = bookmarksDatabaseHelper.getBookmarksCursorExcept(selectedBookmarksIdsLongArray, currentFolder);
-
- // Update the `ListView`.
- bookmarksCursorAdapter.changeCursor(bookmarksCursor);
-
- // Instantiate `snackbarMessage`.
- String snackbarMessage;
-
- // Determine how many items are in the array and prepare an appropriate snackbar message.
- if (selectedBookmarksIdsLongArray.length == 1) {
- snackbarMessage = getString(R.string.one_bookmark_deleted);
- } else {
- // Prepare a snackbar according to the language.
- if (getString(R.string.android_asset_path).equals("ru")) { // The Russian translation is used.
- // Convert the number of selected bookmarks to a string.
- String numberOfBookmarksString = String.valueOf(selectedBookmarksIdsLongArray.length);
-
- // Russian follows rule #7 at <https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals>.
- if (numberOfBookmarksString.endsWith("1") && !numberOfBookmarksString.equals("11")) { // Ends in 1.
- snackbarMessage = numberOfBookmarksString + " " + getString(R.string.bookmarks_deleted_russian_ends_in_1);
- } else if ((numberOfBookmarksString.endsWith("2") || numberOfBookmarksString.endsWith("3") || numberOfBookmarksString.endsWith("4")) &&
- !numberOfBookmarksString.equals("12") && !numberOfBookmarksString.equals("13") && !numberOfBookmarksString.equals("14")) { // Ends in 2-4.
- snackbarMessage = numberOfBookmarksString + " " + getString(R.string.bookmarks_deleted_russian_ends_in_2);
- } else { // Everything else.
- snackbarMessage = numberOfBookmarksString + " " + getString(R.string.bookmarks_deleted_russian_everything_else);
- }
- } else { // Another language is used.
- snackbarMessage = selectedBookmarksIdsLongArray.length + " " + getString(R.string.bookmarks_deleted);
- }
+ // 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);