Hide the move to folder menu item if no folders exist. https://redmine.stoutner...
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / activities / BookmarksActivity.java
index 35ac9e34e897dfa425e436ca73fdd551abbb3628..4536001b1554b4f586ac7468f5600a8a9d879358 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016-2017 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2016-2017 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
  *
@@ -97,10 +97,20 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
+        // Set the activity theme.
+        if (MainWebViewActivity.darkTheme) {
+            setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
+        } else {
+            setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
+        }
+
+        // Run the default commands.
         super.onCreate(savedInstanceState);
+
+        // Set the content view.
         setContentView(R.layout.bookmarks_coordinatorlayout);
 
-        // We need to use the `SupportActionBar` from `android.support.v7.app.ActionBar` until the minimum API is >= 21.
+        // Use the `SupportActionBar` from `android.support.v7.app.ActionBar` until the minimum API is >= 21.
         final Toolbar bookmarksAppBar = (Toolbar) findViewById(R.id.bookmarks_toolbar);
         setSupportActionBar(bookmarksAppBar);
 
@@ -185,7 +195,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                 editBookmarkMenuItem = menu.findItem(R.id.edit_bookmark);
                 selectAllBookmarksMenuItem = menu.findItem(R.id.context_menu_select_all_bookmarks);
 
-                // Get a handle for `contextualActionMode` so we can close it programatically.
+                // Store `contextualActionMode` so we can close it programatically.
                 contextualActionMode = mode;
 
                 return true;
@@ -193,7 +203,17 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
             @Override
             public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
-                return false;
+                // Get a handle for the move to folder menu item.
+                MenuItem moveToFolderMenuItem = menu.findItem(R.id.move_to_folder);
+
+                // Get a `Cursor` with all of the folders.
+                Cursor folderCursor = bookmarksDatabaseHelper.getAllFoldersCursor();
+
+                // Enable the move to folder menu item if at least one folder exists.
+                moveToFolderMenuItem.setVisible(folderCursor.getCount() > 0);
+
+                // `return true` indicates that the menu has been updated.
+                return true;
             }
 
             @Override
@@ -225,19 +245,31 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                     // Disable `moveBookmarkUpMenuItem` if the selected bookmark is at the top of the ListView.
                     if (selectedBookmarkDatabaseId == firstBookmarkDatabaseId) {
                         moveBookmarkUpMenuItem.setEnabled(false);
-                        moveBookmarkUpMenuItem.setIcon(R.drawable.move_bookmark_up_disabled);
+                        moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_disabled);
                     } else {  // Otherwise enable `moveBookmarkUpMenuItem`.
                         moveBookmarkUpMenuItem.setEnabled(true);
-                        moveBookmarkUpMenuItem.setIcon(R.drawable.move_bookmark_up_enabled);
+
+                        // Set the icon according to the theme.
+                        if (MainWebViewActivity.darkTheme) {
+                            moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled_dark);
+                        } else {
+                            moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled_light);
+                        }
                     }
 
                     // Disable `moveBookmarkDownMenuItem` if the selected bookmark is at the bottom of the ListView.
                     if (selectedBookmarkDatabaseId == lastBookmarkDatabaseId) {
                         moveBookmarkDownMenuItem.setEnabled(false);
-                        moveBookmarkDownMenuItem.setIcon(R.drawable.move_bookmark_down_disabled);
+                        moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_disabled);
                     } else {  // Otherwise enable `moveBookmarkDownMenuItem`.
                         moveBookmarkDownMenuItem.setEnabled(true);
-                        moveBookmarkDownMenuItem.setIcon(R.drawable.move_bookmark_down_enabled);
+
+                        // Set the icon according to the theme.
+                        if (MainWebViewActivity.darkTheme) {
+                            moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled_dark);
+                        } else {
+                            moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled_light);
+                        }
                     }
                 } else {  // More than one bookmark is selected.
                     // List the number of selected bookmarks in the subtitle.
@@ -259,45 +291,46 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
             @Override
             public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
+                // Get the menu item ID.
                 int menuItemId = item.getItemId();
 
-                // `numberOfBookmarks` is used in `R.id.move_bookmark_up_enabled`, `R.id.move_bookmark_down_enabled`, and `R.id.context_menu_select_all_bookmarks`.
+                // Instantiate the common variables.
                 int numberOfBookmarks;
-
-                // `selectedBookmarkLongArray` is used in `R.id.move_bookmark_up`, `R.id.move_bookmark_down`, and `R.id.edit_bookmark`.
-                long[]selectedBookmarkLongArray;
-                // `selectedBookmarkDatabaseId` is used in `R.id.move_bookmark_up`, `R.id.move_bookmark_down`, and `R.id.edit_bookmark`.
-                int selectedBookmarkDatabaseId;
-                // `selectedBookmarkNewPosition` is used in `R.id.move_bookmark_up` and `R.id.move_bookmark_down`.
                 int selectedBookmarkNewPosition;
-                // `bookmarkPositionSparseBooleanArray` is used in `R.id.edit_bookmark` and `R.id.delete_bookmark`.
                 SparseBooleanArray bookmarkPositionSparseBooleanArray;
 
                 switch (menuItemId) {
                     case R.id.move_bookmark_up:
-                        // Get the selected bookmark database ID.
-                        selectedBookmarkLongArray = bookmarksListView.getCheckedItemIds();
-                        selectedBookmarkDatabaseId = (int) selectedBookmarkLongArray[0];
+                        // Get the array of checked bookmarks.
+                        bookmarkPositionSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
+
+                        // Store the position of the selected bookmark.
+                        selectedBookmarkPosition = bookmarkPositionSparseBooleanArray.keyAt(0);
 
                         // Initialize `selectedBookmarkNewPosition`.
                         selectedBookmarkNewPosition = 0;
 
+                        // Iterate through the bookmarks.
                         for (int i = 0; i < bookmarksListView.getCount(); i++) {
-                            int databaseId = (int) bookmarksListView.getItemIdAtPosition(i);
-                            int nextBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(i + 1);
-
-                            if (databaseId == selectedBookmarkDatabaseId || nextBookmarkDatabaseId == selectedBookmarkDatabaseId) {
-                                if (databaseId == selectedBookmarkDatabaseId) {
-                                    // Move the selected bookmark up one and store the new bookmark position.
-                                    bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i - 1);
-                                    selectedBookmarkNewPosition = i - 1;
-                                } else {  // Move the bookmark above the selected bookmark down one.
-                                    bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i + 1);
+                            // Get the database ID for the current bookmark.
+                            int currentBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(i);
+
+                            // Update the display order for the current bookmark.
+                            if (i == selectedBookmarkPosition) {  // The current bookmark is the selected bookmark.
+                                // Move the current bookmark up one.
+                                bookmarksDatabaseHelper.updateBookmarkDisplayOrder(currentBookmarkDatabaseId, i - 1);
+                                selectedBookmarkNewPosition = i - 1;
+                            } else if ((i + 1) == selectedBookmarkPosition){  // The current bookmark is immediately above the selected bookmark.
+                                // Move the current bookmark down one.
+                                bookmarksDatabaseHelper.updateBookmarkDisplayOrder(currentBookmarkDatabaseId, i + 1);
+                            } else {  // The current bookmark is not changing positions.
+                                // Move `bookmarksCursor` to the current bookmark position.
+                                bookmarksCursor.moveToPosition(i);
+
+                                // Update the display order only if it is not correct in the database.
+                                if (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)) != i) {
+                                    bookmarksDatabaseHelper.updateBookmarkDisplayOrder(currentBookmarkDatabaseId, i);
                                 }
-                            } else {
-                                // Reset the rest of the bookmarks' DISPLAY_ORDER to match the position in the ListView.
-                                // This isn't necessary, but it clears out any stray values that might have crept into the database.
-                                bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i);
                             }
                         }
 
@@ -313,29 +346,36 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                         break;
 
                     case R.id.move_bookmark_down:
-                        // Get the selected bookmark database ID.
-                        selectedBookmarkLongArray = bookmarksListView.getCheckedItemIds();
-                        selectedBookmarkDatabaseId = (int) selectedBookmarkLongArray[0];
+                        // Get the array of checked bookmarks.
+                        bookmarkPositionSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
+
+                        // Store the position of the selected bookmark.
+                        selectedBookmarkPosition = bookmarkPositionSparseBooleanArray.keyAt(0);
 
                         // Initialize `selectedBookmarkNewPosition`.
                         selectedBookmarkNewPosition = 0;
 
+                        // Iterate through the bookmarks.
                         for (int i = 0; i <bookmarksListView.getCount(); i++) {
-                            int databaseId = (int) bookmarksListView.getItemIdAtPosition(i);
-                            int previousBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(i - 1);
-
-                            if (databaseId == selectedBookmarkDatabaseId || previousBookmarkDatabaseId == selectedBookmarkDatabaseId) {
-                                if (databaseId == selectedBookmarkDatabaseId) {
-                                    // Move the selected bookmark down one and store the new bookmark position.
-                                    bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i + 1);
-                                    selectedBookmarkNewPosition = i + 1;
-                                } else {  // Move the bookmark below the selected bookmark up one.
-                                    bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i - 1);
+                            // Get the database ID for the current bookmark.
+                            int currentBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(i);
+
+                            // Update the display order for the current bookmark.
+                            if (i == selectedBookmarkPosition) {  // The current bookmark is the selected bookmark.
+                                // Move the current bookmark down one.
+                                bookmarksDatabaseHelper.updateBookmarkDisplayOrder(currentBookmarkDatabaseId, i + 1);
+                                selectedBookmarkNewPosition = i + 1;
+                            } else if ((i - 1) == selectedBookmarkPosition) {  // The current bookmark is immediately below the selected bookmark.
+                                // Move the bookmark below the selected bookmark up one.
+                                bookmarksDatabaseHelper.updateBookmarkDisplayOrder(currentBookmarkDatabaseId, i - 1);
+                            } else {  // The current bookmark is not changing positions.
+                                // Move `bookmarksCursor` to the current bookmark position.
+                                bookmarksCursor.moveToPosition(i);
+
+                                // Update the display order only if it is not correct in the database.
+                                if (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)) != i) {
+                                    bookmarksDatabaseHelper.updateBookmarkDisplayOrder(currentBookmarkDatabaseId, i);
                                 }
-                            } else {
-                                // Reset the rest of the bookmark' DISPLAY_ORDER to match the position in the ListView.
-                                // This isn't necessary, but it clears out any stray values that might have crept into the database.
-                                bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i);
                             }
                         }
 
@@ -359,13 +399,11 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                         break;
 
                     case R.id.edit_bookmark:
-                        // Get a handle for `selectedBookmarkPosition` so we can scroll to it after refreshing the ListView.
+                        // Get the array of checked bookmarks.
                         bookmarkPositionSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
-                        for (int i = 0; i < bookmarkPositionSparseBooleanArray.size(); i++) {
-                            // Find the bookmark that is selected and save the position to `selectedBookmarkPosition`.
-                            if (bookmarkPositionSparseBooleanArray.valueAt(i))
-                                selectedBookmarkPosition = bookmarkPositionSparseBooleanArray.keyAt(i);
-                        }
+
+                        // Store the position of the selected bookmark.
+                        selectedBookmarkPosition = bookmarkPositionSparseBooleanArray.keyAt(0);
 
                         // Move to the selected database ID and find out if it is a folder.
                         bookmarksCursor.moveToPosition(selectedBookmarkPosition);
@@ -392,20 +430,18 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                         // Get an array of the selected rows.
                         final long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
 
-                        // Get a handle for `selectedBookmarkPosition` so we can scroll to it after refreshing the ListView.
+                        // Get the array of checked bookmarks.
                         bookmarkPositionSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
-                        for (int i = 0; i < bookmarkPositionSparseBooleanArray.size(); i++) {
-                            // Find the bookmark that is selected and save the position to `selectedBookmarkPosition`.
-                            if (bookmarkPositionSparseBooleanArray.valueAt(i))
-                                selectedBookmarkPosition = bookmarkPositionSparseBooleanArray.keyAt(i);
-                        }
+
+                        // Store the position of the first selected bookmark.
+                        selectedBookmarkPosition = bookmarkPositionSparseBooleanArray.keyAt(0);
 
                         updateBookmarksListViewExcept(selectedBookmarksLongArray, currentFolder);
 
-                        // Scroll to where the deleted bookmark was located.
+                        // Scroll to where the first deleted bookmark was located.
                         bookmarksListView.setSelection(selectedBookmarkPosition - 5);
 
-                        // Initialize `snackbarMessage`.
+                        // Create `snackbarMessage`.
                         String snackbarMessage;
 
                         // Determine how many items are in the array and prepare an appropriate Snackbar message.
@@ -432,7 +468,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                                                 // Refresh the ListView to show the rows again.
                                                 updateBookmarksListView(currentFolder);
 
-                                                // Scroll to where the deleted bookmark was located.
+                                                // Scroll to where the first deleted bookmark was located.
                                                 bookmarksListView.setSelection(selectedBookmarkPosition - 5);
                                                 break;
 
@@ -450,6 +486,20 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                                                     // Delete `databaseIdInt`.
                                                     bookmarksDatabaseHelper.deleteBookmark(databaseIdInt);
                                                 }
+
+                                                // Update the display order.
+                                                for (int i = 0; i < bookmarksListView.getCount(); i++) {
+                                                    // Get the database ID for the current bookmark.
+                                                    int currentBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(i);
+
+                                                    // Move `bookmarksCursor` to the current bookmark position.
+                                                    bookmarksCursor.moveToPosition(i);
+
+                                                    // Update the display order only if it is not correct in the database.
+                                                    if (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)) != i) {
+                                                        bookmarksDatabaseHelper.updateBookmarkDisplayOrder(currentBookmarkDatabaseId, i);
+                                                    }
+                                                }
                                                 break;
                                         }
                                     }
@@ -566,7 +616,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         // Convert the favoriteIcon Bitmap to a byte array.
         ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
         // `0` is for lossless compression (the only option for a PNG).
-        MainWebViewActivity.favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
+        MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
         byte[] favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray();
 
         // Display the new bookmark below the current items in the (0 indexed) list.
@@ -586,44 +636,35 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         EditText createFolderNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_folder_name_edittext);
         String folderNameString = createFolderNameEditText.getText().toString();
 
-        // Check to see if the folder already exists.
-        Cursor bookmarkFolderCursor = bookmarksDatabaseHelper.getFolderCursor(folderNameString);
-        int existingFoldersWithNewName = bookmarkFolderCursor.getCount();
-        bookmarkFolderCursor.close();
-        if (folderNameString.isEmpty() || (existingFoldersWithNewName > 0)) {
-            String cannotCreateFolder = getResources().getString(R.string.cannot_create_folder) + " \"" + folderNameString + "\"";
-            Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), cannotCreateFolder, Snackbar.LENGTH_INDEFINITE).show();
-        } else {  // Create the folder.
-            // Get the new folder icon `Bitmap`.
-            RadioButton defaultFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon_radiobutton);
-            Bitmap folderIconBitmap;
-            if (defaultFolderIconRadioButton.isChecked()) {
-                // Get the default folder icon `ImageView` from the `Dialog` and convert it to a `Bitmap`.
-                ImageView folderIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon);
-                Drawable folderIconDrawable = folderIconImageView.getDrawable();
-                BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
-                folderIconBitmap = folderIconBitmapDrawable.getBitmap();
-            } else {  // Assign `favoriteIcon` from the `WebView`.
-                folderIconBitmap = MainWebViewActivity.favoriteIcon;
-            }
+        // Get the new folder icon `Bitmap`.
+        RadioButton defaultFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon_radiobutton);
+        Bitmap folderIconBitmap;
+        if (defaultFolderIconRadioButton.isChecked()) {
+            // Get the default folder icon `ImageView` from the `Dialog` and convert it to a `Bitmap`.
+            ImageView folderIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon);
+            Drawable folderIconDrawable = folderIconImageView.getDrawable();
+            BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
+            folderIconBitmap = folderIconBitmapDrawable.getBitmap();
+        } else {  // Assign `favoriteIcon` from the `WebView`.
+            folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+        }
 
-            // Convert `folderIconBitmap` to a byte array.  `0` is for lossless compression (the only option for a PNG).
-            ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
-            folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
-            byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
+        // Convert `folderIconBitmap` to a byte array.  `0` is for lossless compression (the only option for a PNG).
+        ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
+        folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
+        byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
 
-            // Move all the bookmarks down one in the display order.
-            for (int i = 0; i < bookmarksListView.getCount(); i++) {
-                int databaseId = (int) bookmarksListView.getItemIdAtPosition(i);
-                bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i + 1);
-            }
+        // Move all the bookmarks down one in the display order.
+        for (int i = 0; i < bookmarksListView.getCount(); i++) {
+            int databaseId = (int) bookmarksListView.getItemIdAtPosition(i);
+            bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i + 1);
+        }
 
-            // Create the folder, placing it at the top of the ListView
-            bookmarksDatabaseHelper.createFolder(folderNameString, 0, currentFolder, folderIconByteArray);
+        // Create the folder, placing it at the top of the ListView
+        bookmarksDatabaseHelper.createFolder(folderNameString, 0, currentFolder, folderIconByteArray);
 
-            // Refresh the ListView.
-            updateBookmarksListView(currentFolder);
-        }
+        // Refresh the ListView.
+        updateBookmarksListView(currentFolder);
     }
 
     @Override
@@ -645,7 +686,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
             bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString);
         } else {  // Update the bookmark using the `WebView` favorite icon.
             ByteArrayOutputStream newFavoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
-            MainWebViewActivity.favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
+            MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
             byte[] newFavoriteIconByteArray = newFavoriteIconByteArrayOutputStream.toByteArray();
 
             //  Update the bookmark and the favorite icon.
@@ -699,7 +740,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                     BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
                     folderIconBitmap = folderIconBitmapDrawable.getBitmap();
                 } else {  // Get the web page icon `ImageView` from the `Dialog`.
-                    folderIconBitmap = MainWebViewActivity.favoriteIcon;
+                    folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
                 }
 
                 // Convert the folder `Bitmap` to a byte array.  `0` is for lossless compression (the only option for a PNG).
@@ -728,39 +769,35 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         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_INDEFINITE).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 = bookmarksDatabaseHelper.getFolderName(newFolderDatabaseId);
-            }
+        // Get the new folder database ID.
+        int newFolderDatabaseId = (int) newFolderLongArray[0];
 
-            // 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;
+        // Instantiate `newFolderName`.
+        String newFolderName;
 
-                // Move the selected bookmark to the new folder.
-                bookmarksDatabaseHelper.moveToFolder(databaseIdInt, 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 = bookmarksDatabaseHelper.getFolderName(newFolderDatabaseId);
+        }
 
-            // Refresh the `ListView`.
-            updateBookmarksListView(currentFolder);
+        // 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;
 
-            // Close the contextual app bar.
-            contextualActionMode.finish();
+            // Move the selected bookmark to the new folder.
+            bookmarksDatabaseHelper.moveToFolder(databaseIdInt, newFolderName);
         }
+
+        // Refresh the `ListView`.
+        updateBookmarksListView(currentFolder);
+
+        // Close the contextual app bar.
+        contextualActionMode.finish();
     }
 
     private void updateBookmarksListView(String folderName) {