+ bookmarksDatabaseHandler.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString, folderIconByteArray);
+
+ // Refresh the `ListView`. `setSelection` scrolls to the position of the folder that was edited.
+ updateBookmarksListView(currentFolder);
+ bookmarksListView.setSelection(selectedBookmarkPosition);
+ }
+ } else { // Don't edit the folder because the new name is not unique.
+ String cannot_rename_folder = getResources().getString(R.string.cannot_rename_folder) + " \"" + newFolderNameString + "\"";
+ Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), cannot_rename_folder, Snackbar.LENGTH_INDEFINITE).show();
+ }
+
+ // Close the contextual action mode.
+ contextualActionMode.finish();
+ }
+
+ @Override
+ public void onMoveToFolder(DialogFragment dialogFragment) {
+ // Get the new folder database id.
+ ListView folderListView = (ListView) dialogFragment.getDialog().findViewById(R.id.move_to_folder_listview);
+ long[] newFolderLongArray = folderListView.getCheckedItemIds();
+
+ if (newFolderLongArray.length == 0) { // No new folder was selected.
+ Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), getString(R.string.cannot_move_bookmarks), Snackbar.LENGTH_LONG).show();
+ } else { // Move the selected bookmarks.
+ // Get the new folder database ID.
+ int newFolderDatabaseId = (int) newFolderLongArray[0];
+
+ // Instantiate `newFolderName`.
+ String newFolderName;
+
+ if (newFolderDatabaseId == 0) {
+ // The new folder is the home folder, represented as `""` in the database.
+ newFolderName = "";
+ } else {
+ // Get the new folder name from the database.
+ newFolderName = bookmarksDatabaseHandler.getFolderName(newFolderDatabaseId);
+ }
+
+ // Get a long array with the the database ID of the selected bookmarks.
+ long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
+ for (long databaseIdLong : selectedBookmarksLongArray) {
+ // Get `databaseIdInt` for each selected bookmark.
+ int databaseIdInt = (int) databaseIdLong;
+
+ // Move the selected bookmark to the new folder.
+ bookmarksDatabaseHandler.moveToFolder(databaseIdInt, newFolderName);
+ }
+
+ // Refresh the `ListView`.
+ updateBookmarksListView(currentFolder);
+
+ // Close the contextual app bar.
+ contextualActionMode.finish();
+ }
+ }
+
+ private void updateBookmarksListView(String folderName) {
+ // Get a `Cursor` with the current contents of the bookmarks database.
+ bookmarksCursor = bookmarksDatabaseHandler.getAllBookmarksCursorByDisplayOrder(folderName);
+
+ // Setup `bookmarksCursorAdapter` with `this` context. `false` disables autoRequery.