]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java
Allow exiting the Bookmarks activity from a subfolder. https://redmine.stoutner...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / BookmarksActivity.java
index 4536001b1554b4f586ac7468f5600a8a9d879358..e55b6711f0b757d4ee78a497ae313f29991160d0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2016-2017 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2016-2018 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
  *
@@ -34,6 +34,7 @@ import android.support.design.widget.Snackbar;
 import android.support.v4.app.NavUtils;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
+// `AppCompatDialogFragment` is required instead of `DialogFragment` or an error is produced on API <=22.
 import android.support.v7.app.AppCompatDialogFragment;
 import android.support.v7.widget.Toolbar;
 import android.util.SparseBooleanArray;
@@ -42,8 +43,8 @@ import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.WindowManager;
 import android.widget.AbsListView;
-import android.widget.AdapterView;
 import android.widget.CursorAdapter;
 import android.widget.EditText;
 import android.widget.ImageView;
@@ -61,42 +62,62 @@ import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
 
 import java.io.ByteArrayOutputStream;
 
-public class BookmarksActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener, EditBookmarkDialog.EditBookmarkListener, EditBookmarkFolderDialog.EditBookmarkFolderListener,
-        MoveToFolderDialog.MoveToFolderListener {
-
-    // `bookmarksDatabaseHelper` is public static so it can be accessed from `EditBookmarkDialog` and `MoveToFolderDialog`.  It is also used in `onCreate()`,
-    // `onCreateBookmarkCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`.
-    public static BookmarksDatabaseHelper bookmarksDatabaseHelper;
+public class BookmarksActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener, EditBookmarkDialog.EditBookmarkListener,
+        EditBookmarkFolderDialog.EditBookmarkFolderListener, MoveToFolderDialog.MoveToFolderListener {
 
     // `currentFolder` is public static so it can be accessed from `MoveToFolderDialog`.
-    // It is used in `onCreate`, `onOptionsItemSelected()`, `onCreateBookmarkCreate`, `onCreateBookmarkFolderCreate`, and `onEditBookmarkSave`.
+    // It is used in `onCreate`, `onOptionsItemSelected()`, `onBackPressed()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`,
+    // and `loadFolder()`.
     public static String currentFolder;
 
-    // `checkedItemIds` is public static so it can be accessed from `EditBookmarkDialog`, `EditBookmarkFolderDialog`, and `MoveToFolderDialog`.
-    // It is also used in `onActionItemClicked`.
+    // `checkedItemIds` is public static so it can be accessed from `MoveToFolderDialog`.  It is also used in `onCreate()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`,
+    // and `updateMoveIcons()`.
     public static long[] checkedItemIds;
 
 
-    // `bookmarksListView` is used in `onCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`.
+    // `bookmarksDatabaseHelper` is used in `onCreate()`, `onOptionsItemSelected()`, `onBackPressed()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`,
+    // `onMoveToFolder()`, `deleteBookmarkFolderContents()`, `loadFolder()`, and `onDestroy()`.
+    private BookmarksDatabaseHelper bookmarksDatabaseHelper;
+
+    // `bookmarksListView` is used in `onCreate()`, `onOptionsItemSelected()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`,
+    // `updateMoveIcons()`, `scrollBookmarks()`, and `loadFolder()`.
     private ListView bookmarksListView;
 
-    // `contextualActionMode` is used in `onCreate()` and `onEditBookmarkSave()`.
-    private ActionMode contextualActionMode;
+    // `bookmarksCursor` is used in `onCreate()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`, `deleteBookmarkFolderContents()`,
+    // `loadFolder()`, and `onDestroy()`.
+    private Cursor bookmarksCursor;
 
-    // `selectedBookmarkPosition` is used in `onCreate()` and `onEditBookmarkSave()`.
-    private int selectedBookmarkPosition;
+    // `bookmarksCursorAdapter` is used in `onCreate(), `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`, and `onLoadFolder()`.
+    private CursorAdapter bookmarksCursorAdapter;
 
-    // `appBar` is used in `onCreate()` and `updateBookmarksListView()`.
-    private ActionBar appBar;
+    // `contextualActionMode` is used in `onCreate()`, `onSaveEditBookmark()`, `onSaveEditBookmarkFolder()` and `onMoveToFolder()`.
+    private ActionMode contextualActionMode;
 
-    // `bookmarksCursor` is used in `onCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`.
-    private Cursor bookmarksCursor;
+    // `appBar` is used in `onCreate()` and `loadFolder()`.
+    private ActionBar appBar;
 
-    // `oldFolderName` is used in `onCreate()` and `onEditBookmarkFolderSave()`.
+    // `oldFolderName` is used in `onCreate()` and `onSaveBookmarkFolder()`.
     private String oldFolderNameString;
 
+    // `moveBookmarkUpMenuItem` is used in `onCreate()` and `updateMoveIcons()`.
+    private MenuItem moveBookmarkUpMenuItem;
+
+    // `moveBookmarkDownMenuItem` is used in `onCreate()` and `updateMoveIcons()`.
+    private MenuItem moveBookmarkDownMenuItem;
+
+    // `bookmarksDeletedSnackbar` is used in `onCreate()`, `onOptionsItemSelected()`, and `onBackPressed()`.
+    private Snackbar bookmarksDeletedSnackbar;
+
+    // `closeActivityAfterDismissingSnackbar` is used in `onCreate()`, `onOptionsItemSelected()`, and `onBackPressed()`.
+    private boolean closeActivityAfterDismissingSnackbar;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
+        // Disable screenshots if not allowed.
+        if (!MainWebViewActivity.allowScreenshots) {
+            getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
+        }
+
         // Set the activity theme.
         if (MainWebViewActivity.darkTheme) {
             setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
@@ -107,74 +128,88 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         // Run the default commands.
         super.onCreate(savedInstanceState);
 
+        // Get the intent that launched the activity.
+        Intent launchingIntent = getIntent();
+
+        // 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);
 
         // Use the `SupportActionBar` from `android.support.v7.app.ActionBar` until the minimum API is >= 21.
-        final Toolbar bookmarksAppBar = (Toolbar) findViewById(R.id.bookmarks_toolbar);
+        final Toolbar bookmarksAppBar = findViewById(R.id.bookmarks_toolbar);
         setSupportActionBar(bookmarksAppBar);
 
-        // Display the home arrow on `SupportActionBar`.
+        // Get a handle for the activity, the app bar, and the ListView.
+        final Activity bookmarksActivity = this;
         appBar = getSupportActionBar();
-        assert appBar != null;// This assert removes the incorrect warning in Android Studio on the following line that `appBar` might be null.
-        appBar.setDisplayHomeAsUpEnabled(true);
+        bookmarksListView = findViewById(R.id.bookmarks_listview);
+
+        // Remove the incorrect lint warning that `appBar` might be null.
+        assert appBar != null;
 
+        // Display the home arrow on the app bar.
+        appBar.setDisplayHomeAsUpEnabled(true);
 
-        // Initialize the database handler and the `ListView`.  `this` specifies the context.  The two `nulls` do not specify the database name or a `CursorFactory`.
+        // Initialize the database helper.  `this` specifies the context.  The two `nulls` do not specify the database name or a `CursorFactory`.
         // The `0` specifies a database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`.
         bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this, null, null, 0);
-        bookmarksListView = (ListView) findViewById(R.id.bookmarks_listview);
 
-        // Set currentFolder to the home folder, which is `""` in the database.
-        currentFolder = "";
+        // Load the home folder.
+        loadFolder();
 
-        // Display the bookmarks in the ListView.
-        updateBookmarksListView(currentFolder);
+        // Set a listener so that tapping a list item loads the URL or folder.
+        bookmarksListView.setOnItemClickListener((parent, view, position, id) -> {
+            // Convert the id from long to int to match the format of the bookmarks database.
+            int databaseID = (int) id;
 
-        // Set a listener so that tapping a list item loads the URL.  We need to store the activity in a variable so that we can return to the parent activity after loading the URL.
-        final Activity bookmarksActivity = this;
-        bookmarksListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
-            @Override
-            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-                // Convert the id from long to int to match the format of the bookmarks database.
-                int databaseID = (int) id;
-
-                // Get the bookmark `Cursor` for this ID and move it to the first row.
-                Cursor bookmarkCursor = bookmarksDatabaseHelper.getBookmarkCursor(databaseID);
-                bookmarkCursor.moveToFirst();
-
-                // If the bookmark is a folder load its contents into the ListView.
-                if (bookmarkCursor.getInt(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) {
-                    // Update `currentFolder`.
-                    currentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
-
-                    // Reload the ListView with `currentFolder`.
-                    updateBookmarksListView(currentFolder);
-                } else {  // Load the URL into `mainWebView`.
-                    // Get the bookmark URL and assign it to formattedUrlString.  `mainWebView` will automatically reload when `BookmarksActivity` closes.
-                    MainWebViewActivity.formattedUrlString = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL));
-
-                    NavUtils.navigateUpFromSameTask(bookmarksActivity);
-                }
+            // Get the bookmark cursor for this ID and move it to the first row.
+            Cursor bookmarkCursor = bookmarksDatabaseHelper.getBookmarkCursor(databaseID);
+            bookmarkCursor.moveToFirst();
 
-                // Close the `Cursor`.
-                bookmarkCursor.close();
+            // Act upon the bookmark according to the type.
+            if (bookmarkCursor.getInt(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) {  // The selected bookmark is a folder.
+                // Update the current folder.
+                currentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
+
+                // Load the new folder.
+                loadFolder();
+            } else {  // The selected bookmark is not a folder.
+                // Get the bookmark URL and assign it to `formattedUrlString`.
+                MainWebViewActivity.formattedUrlString = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL));
+
+                // Set `MainWebViewActivity` to load the new URL on restart.
+                MainWebViewActivity.loadUrlOnRestart = true;
+
+                // Update the bookmarks folder for the bookmarks drawer in `MainWebViewActivity`.
+                MainWebViewActivity.currentBookmarksFolder = currentFolder;
+
+                // Close the bookmarks drawer and reload the bookmarks `ListView` when returning to `MainWebViewActivity`.
+                MainWebViewActivity.restartFromBookmarksActivity = true;
+
+                // Return to `MainWebViewActivity`.
+                NavUtils.navigateUpFromSameTask(bookmarksActivity);
             }
+
+            // Close the `Cursor`.
+            bookmarkCursor.close();
         });
 
+        // Get a handle for the activity.
+        Activity activity = this;
+
         // `MultiChoiceModeListener` handles long clicks.
         bookmarksListView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
-            // `moveBookmarkUpMenuItem` is used in `onCreateActionMode()` and `onItemCheckedStateChanged`.
-            MenuItem moveBookmarkUpMenuItem;
-
-            // `moveBookmarkDownMenuItem` is used in `onCreateActionMode()` and `onItemCheckedStateChanged`.
-            MenuItem moveBookmarkDownMenuItem;
-
-            // `editBookmarkMenuItem` is used in `onCreateActionMode()` and `onItemCheckedStateChanged`.
+            // Instantiate the common variables.
             MenuItem editBookmarkMenuItem;
-
-            // `selectAllBookmarks` is used in `onCreateActionMode()` and `onItemCheckedStateChanges`.
+            MenuItem deleteBookmarksMenuItem;
             MenuItem selectAllBookmarksMenuItem;
+            boolean deletingBookmarks;
 
             @Override
             public boolean onCreateActionMode(ActionMode mode, Menu menu) {
@@ -189,15 +224,22 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                     mode.setTitle(currentFolder);
                 }
 
-                // Get a handle for MenuItems we need to selectively disable.
+                // Get a handle for `MenuItems` that need to be selectively disabled.
                 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);
 
-                // Store `contextualActionMode` so we can close it programatically.
+                // 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;
 
+                // Make it so.
                 return true;
             }
 
@@ -212,22 +254,23 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                 // 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.
+                // Make it so.
                 return true;
             }
 
             @Override
             public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
-                // Get an array of the selected bookmarks.
+                // Get a long array of the selected bookmarks.
                 long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
 
                 // Calculate the number of selected bookmarks.
                 int numberOfSelectedBookmarks = selectedBookmarksLongArray.length;
 
-                // Adjust the `mode` and the menu for the number of selected bookmarks.
-                if (numberOfSelectedBookmarks == 0) {
+                // Adjust the `ActionMode` and the `Menu` according to the number of selected bookmarks.
+                if (numberOfSelectedBookmarks == 0) {  // No bookmarks are selected.
+                    // Close the `ActionMode`.
                     mode.finish();
-                } else if (numberOfSelectedBookmarks == 1) {
+                } else if (numberOfSelectedBookmarks == 1) {  // One bookmark is selected.
                     // List the number of selected bookmarks in the subtitle.
                     mode.setSubtitle(getString(R.string.one_selected));
 
@@ -236,44 +279,27 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                     moveBookmarkDownMenuItem.setVisible(true);
                     editBookmarkMenuItem.setVisible(true);
 
-                    // Get the database IDs for the bookmarks.
-                    int selectedBookmarkDatabaseId = (int) selectedBookmarksLongArray[0];
-                    int firstBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(0);
-                    // bookmarksListView is 0 indexed.
-                    int lastBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(bookmarksListView.getCount() - 1);
-
-                    // Disable `moveBookmarkUpMenuItem` if the selected bookmark is at the top of the ListView.
-                    if (selectedBookmarkDatabaseId == firstBookmarkDatabaseId) {
-                        moveBookmarkUpMenuItem.setEnabled(false);
-                        moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_disabled);
-                    } else {  // Otherwise enable `moveBookmarkUpMenuItem`.
-                        moveBookmarkUpMenuItem.setEnabled(true);
-
-                        // 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_down_disabled);
-                    } else {  // Otherwise enable `moveBookmarkDownMenuItem`.
-                        moveBookmarkDownMenuItem.setEnabled(true);
-
-                        // 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);
+                    // Update the enabled status of the move icons.
+                    updateMoveIcons();
+                } else {  // More than one bookmark is selected.
+                    // List the number of selected bookmarks 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 numberOfSelectedBookmarksString = String.valueOf(numberOfSelectedBookmarks);
+
+                        // Russian follows rule #7 at <https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals>.
+                        if (numberOfSelectedBookmarksString.endsWith("1") && !numberOfSelectedBookmarksString.equals("11")) {  //  Ends in 1.
+                            mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected_russian_ends_in_1));
+                        } else if ((numberOfSelectedBookmarksString.endsWith("2") || numberOfSelectedBookmarksString.endsWith("3") || numberOfSelectedBookmarksString.endsWith("4")) &&
+                                !numberOfSelectedBookmarksString.equals("12") && !numberOfSelectedBookmarksString.equals("13") && !numberOfSelectedBookmarksString.equals("14")) {  // Ends in 2-4.
+                            mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected_russian_ends_in_2));
+                        } else {  // Everything else.
+                            mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected_russian_everything_else));
                         }
+                    } else {  // Another language is used.
+                        // List the number of selected bookmarks in the subtitle.
+                        mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected));
                     }
-                } else {  // More than one bookmark is selected.
-                    // List the number of selected bookmarks in the subtitle.
-                    mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected));
 
                     // Hide non-applicable `MenuItems`.
                     moveBookmarkUpMenuItem.setVisible(false);
@@ -295,20 +321,20 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                 int menuItemId = item.getItemId();
 
                 // Instantiate the common variables.
-                int numberOfBookmarks;
+                int selectedBookmarkPosition;
                 int selectedBookmarkNewPosition;
-                SparseBooleanArray bookmarkPositionSparseBooleanArray;
+                final SparseBooleanArray selectedBookmarksPositionsSparseBooleanArray;
 
                 switch (menuItemId) {
                     case R.id.move_bookmark_up:
-                        // Get the array of checked bookmarks.
-                        bookmarkPositionSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
+                        // Get the array of checked bookmark positions.
+                        selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
 
-                        // Store the position of the selected bookmark.
-                        selectedBookmarkPosition = bookmarkPositionSparseBooleanArray.keyAt(0);
+                        // Store the position of the selected bookmark.  Only one bookmark is selected when `move_bookmark_up` is enabled.
+                        selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(0);
 
-                        // Initialize `selectedBookmarkNewPosition`.
-                        selectedBookmarkNewPosition = 0;
+                        // Calculate the new position of the selected bookmark.
+                        selectedBookmarkNewPosition = selectedBookmarkPosition - 1;
 
                         // Iterate through the bookmarks.
                         for (int i = 0; i < bookmarksListView.getCount(); i++) {
@@ -318,42 +344,43 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                             // 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;
+                                bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, 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);
+                                bookmarksDatabaseHelper.updateDisplayOrder(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);
+                                    bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i);
                                 }
                             }
                         }
 
-                        // Refresh the ListView.
-                        updateBookmarksListView(currentFolder);
+                        // Update `bookmarksCursor` with the current contents of the bookmarks database.
+                        bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
 
-                        // Select the previously selected bookmark in the new location.
-                        bookmarksListView.setItemChecked(selectedBookmarkNewPosition, true);
+                        // Update the `ListView`.
+                        bookmarksCursorAdapter.changeCursor(bookmarksCursor);
 
-                        // Scroll `bookmarksListView` to five items above `selectedBookmarkNewPosition`.
-                        bookmarksListView.setSelection(selectedBookmarkNewPosition - 5);
+                        // Scroll with the bookmark.
+                        scrollBookmarks(selectedBookmarkNewPosition);
 
+                        // Update the enabled status of the move icons.
+                        updateMoveIcons();
                         break;
 
                     case R.id.move_bookmark_down:
-                        // Get the array of checked bookmarks.
-                        bookmarkPositionSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
+                        // Get the array of checked bookmark positions.
+                        selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
 
-                        // Store the position of the selected bookmark.
-                        selectedBookmarkPosition = bookmarkPositionSparseBooleanArray.keyAt(0);
+                        // Store the position of the selected bookmark.  Only one bookmark is selected when `move_bookmark_down` is enabled.
+                        selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(0);
 
-                        // Initialize `selectedBookmarkNewPosition`.
-                        selectedBookmarkNewPosition = 0;
+                        // Calculate the new position of the selected bookmark.
+                        selectedBookmarkNewPosition = selectedBookmarkPosition + 1;
 
                         // Iterate through the bookmarks.
                         for (int i = 0; i <bookmarksListView.getCount(); i++) {
@@ -363,30 +390,32 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                             // 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;
+                                bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, 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);
+                                bookmarksDatabaseHelper.updateDisplayOrder(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);
+                                    bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i);
                                 }
                             }
                         }
 
-                        // Refresh the ListView.
-                        updateBookmarksListView(currentFolder);
+                        // Update `bookmarksCursor` with the current contents of the bookmarks database.
+                        bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
 
-                        // Select the previously selected bookmark in the new location.
-                        bookmarksListView.setItemChecked(selectedBookmarkNewPosition, true);
+                        // Update the `ListView`.
+                        bookmarksCursorAdapter.changeCursor(bookmarksCursor);
 
-                        // Scroll `bookmarksListView` to five items above `selectedBookmarkNewPosition`.
-                        bookmarksListView.setSelection(selectedBookmarkNewPosition - 5);
+                        // Scroll with the bookmark.
+                        scrollBookmarks(selectedBookmarkNewPosition);
+
+                        // Update the enabled status of the move icons.
+                        updateMoveIcons();
                         break;
 
                     case R.id.move_to_folder:
@@ -399,65 +428,80 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                         break;
 
                     case R.id.edit_bookmark:
-                        // Get the array of checked bookmarks.
-                        bookmarkPositionSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
+                        // Get the array of checked bookmark positions.
+                        selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
 
-                        // Store the position of the selected bookmark.
-                        selectedBookmarkPosition = bookmarkPositionSparseBooleanArray.keyAt(0);
+                        // Get the position of the selected bookmark.  Only one bookmark is selected when `edit_bookmark_down` is enabled.
+                        selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(0);
 
-                        // Move to the selected database ID and find out if it is a folder.
+                        // 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);
 
-                        // Store `checkedItemIds` for use by the `AlertDialog`.
-                        checkedItemIds = bookmarksListView.getCheckedItemIds();
+                        // 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.
+                            // Save the current folder name, which is used in `onSaveBookmarkFolder()`.
                             oldFolderNameString = bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
 
-                            // Show the `EditBookmarkFolderDialog` `AlertDialog` and name the instance `@string/edit_folder`.
-                            AppCompatDialogFragment editFolderDialog = new EditBookmarkFolderDialog();
+                            // Show the edit bookmark folder dialog.
+                            AppCompatDialogFragment editFolderDialog = EditBookmarkFolderDialog.folderDatabaseId(databaseId);
                             editFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.edit_folder));
                         } else {
-                            // Show the `EditBookmarkDialog` `AlertDialog` and name the instance `@string/edit_bookmark`.
-                            AppCompatDialogFragment editBookmarkDialog = new EditBookmarkDialog();
+                            // 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:
-                        // Get an array of the selected rows.
-                        final long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
+                        // Set the deleting bookmarks flag, which prevents the delete menu item from being enabled until the current process finishes.
+                        deletingBookmarks = true;
 
-                        // Get the array of checked bookmarks.
-                        bookmarkPositionSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
+                        // Get an array of the selected row IDs.
+                        final long[] selectedBookmarksIdsLongArray = bookmarksListView.getCheckedItemIds();
 
-                        // Store the position of the first selected bookmark.
-                        selectedBookmarkPosition = bookmarkPositionSparseBooleanArray.keyAt(0);
+                        // 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();
 
-                        updateBookmarksListViewExcept(selectedBookmarksLongArray, currentFolder);
+                        // Update `bookmarksCursor` with the current contents of the bookmarks database except for the specified database IDs.
+                        bookmarksCursor = bookmarksDatabaseHelper.getBookmarksCursorExcept(selectedBookmarksIdsLongArray, currentFolder);
 
-                        // Scroll to where the first deleted bookmark was located.
-                        bookmarksListView.setSelection(selectedBookmarkPosition - 5);
+                        // Update the `ListView`.
+                        bookmarksCursorAdapter.changeCursor(bookmarksCursor);
 
-                        // Create `snackbarMessage`.
+                        // Instantiate `snackbarMessage`.
                         String snackbarMessage;
 
-                        // Determine how many items are in the array and prepare an appropriate Snackbar message.
-                        if (selectedBookmarksLongArray.length == 1) {
+                        // 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 {
-                            snackbarMessage = selectedBookmarksLongArray.length + " " + getString(R.string.bookmarks_deleted);
+                            // 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);
+                            }
                         }
 
                         // Show a SnackBar.
-                        Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), snackbarMessage, Snackbar.LENGTH_LONG)
-                                .setAction(R.string.undo, new View.OnClickListener() {
-                                    @Override
-                                    public void onClick(View view) {
-                                        // Do nothing because everything will be handled by `onDismissed()` below.
-                                    }
+                        bookmarksDeletedSnackbar = Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), snackbarMessage, Snackbar.LENGTH_LONG)
+                                .setAction(R.string.undo, view -> {
+                                    // Do nothing because everything will be handled by `onDismissed()` below.
                                 })
                                 .addCallback(new Snackbar.Callback() {
                                     @Override
@@ -465,25 +509,32 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                                         switch (event) {
                                             // The user pushed the `Undo` button.
                                             case Snackbar.Callback.DISMISS_EVENT_ACTION:
-                                                // Refresh the ListView to show the rows again.
-                                                updateBookmarksListView(currentFolder);
+                                                // Update `bookmarksCursor` with the current contents of the bookmarks database, including the "deleted" bookmarks.
+                                                bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
+
+                                                // Update the `ListView`.
+                                                bookmarksCursorAdapter.changeCursor(bookmarksCursor);
+
+                                                // Re-select the previously selected bookmarks.
+                                                for (int i = 0; i < selectedBookmarksPositionsSparseBooleanArray.size(); i++) {
+                                                    bookmarksListView.setItemChecked(selectedBookmarksPositionsSparseBooleanArray.keyAt(i), true);
+                                                }
 
-                                                // Scroll to where the first deleted bookmark was located.
-                                                bookmarksListView.setSelection(selectedBookmarkPosition - 5);
                                                 break;
 
                                             // The `Snackbar` was dismissed without the `Undo` button being pushed.
                                             default:
-                                                // Delete each selected row.
-                                                for (long databaseIdLong : selectedBookmarksLongArray) {
+                                                // Delete each selected bookmark.
+                                                for (long databaseIdLong : selectedBookmarksIdsLongArray) {
                                                     // Convert `databaseIdLong` to an int.
                                                     int databaseIdInt = (int) databaseIdLong;
 
+                                                    // Delete the contents of the folder if the selected bookmark is a folder.
                                                     if (bookmarksDatabaseHelper.isFolder(databaseIdInt)) {
                                                         deleteBookmarkFolderContents(databaseIdInt);
                                                     }
 
-                                                    // Delete `databaseIdInt`.
+                                                    // Delete the selected bookmark.
                                                     bookmarksDatabaseHelper.deleteBookmark(databaseIdInt);
                                                 }
 
@@ -497,46 +548,75 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
                                                     // 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);
+                                                        bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i);
                                                     }
                                                 }
-                                                break;
+                                        }
+
+                                        // Enable the delete bookmarks menu item.
+                                        deleteBookmarksMenuItem.setEnabled(true);
+
+                                        // Reset the deleting bookmarks flag.
+                                        deletingBookmarks = false;
+
+                                        // Close the activity if back has been pressed.
+                                        if (closeActivityAfterDismissingSnackbar) {
+                                            // Update the bookmarks folder for the bookmarks drawer in the main WebView activity.
+                                            MainWebViewActivity.currentBookmarksFolder = currentFolder;
+
+                                            // Close the bookmarks drawer and reload the bookmarks ListView when returning to the main WebView activity.
+                                            MainWebViewActivity.restartFromBookmarksActivity = true;
+
+                                            // Return to `MainWebViewActivity`.
+                                            NavUtils.navigateUpFromSameTask(activity);
                                         }
                                     }
-                                })
-                                .show();
+                                });
+
+                        //Show the `SnackBar`.
+                        bookmarksDeletedSnackbar.show();
 
-                        // Close the contextual app bar.
+                        // Close the `ActionBar`.
                         mode.finish();
                         break;
 
                     case R.id.context_menu_select_all_bookmarks:
-                        numberOfBookmarks = bookmarksListView.getCount();
+                        // Get the total number of bookmarks.
+                        int numberOfBookmarks = bookmarksListView.getCount();
 
+                        // Select them all.
                         for (int i = 0; i < numberOfBookmarks; i++) {
                             bookmarksListView.setItemChecked(i, true);
                         }
                         break;
                 }
+
                 // Consume the click.
                 return true;
             }
 
             @Override
             public void onDestroyActionMode(ActionMode mode) {
-
+                // Do nothing.
             }
         });
 
-        // Set a FloatingActionButton for creating new bookmarks.
-        FloatingActionButton createBookmarkFAB = (FloatingActionButton) findViewById(R.id.create_bookmark_fab);
-        createBookmarkFAB.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View view) {
-                // Show the `CreateBookmarkDialog` `AlertDialog` and name the instance `@string/create_bookmark`.
-                AppCompatDialogFragment createBookmarkDialog = new CreateBookmarkDialog();
-                createBookmarkDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_bookmark));
-            }
+        // Get handles for the `FloatingActionButtons`.
+        FloatingActionButton createBookmarkFolderFab = findViewById(R.id.create_bookmark_folder_fab);
+        FloatingActionButton createBookmarkFab = findViewById(R.id.create_bookmark_fab);
+
+        // Set the create new bookmark folder FAB to display the `AlertDialog`.
+        createBookmarkFolderFab.setOnClickListener(v -> {
+            // Show the `CreateBookmarkFolderDialog` `AlertDialog` and name the instance `@string/create_folder`.
+            AppCompatDialogFragment createBookmarkFolderDialog = new CreateBookmarkFolderDialog();
+            createBookmarkFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_folder));
+        });
+
+        // Set the create new bookmark FAB to display the `AlertDialog`.
+        createBookmarkFab.setOnClickListener(view -> {
+            // Show the `CreateBookmarkDialog` `AlertDialog` and name the instance `@string/create_bookmark`.
+            AppCompatDialogFragment createBookmarkDialog = new CreateBookmarkDialog();
+            createBookmarkDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_bookmark));
         });
     }
 
@@ -556,26 +636,38 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
         switch (menuItemId) {
             case android.R.id.home:  // The home arrow is identified as `android.R.id.home`, not just `R.id.home`.
-                if (currentFolder.isEmpty()) {  // Exit BookmarksActivity if currently in the home folder.
-                    NavUtils.navigateUpFromSameTask(this);
-                } else {  // Navigate up one folder.
+                if (currentFolder.isEmpty()) {  // Currently in the home folder.
+                    // Go home.
+                    if ((bookmarksDeletedSnackbar != null) && bookmarksDeletedSnackbar.isShown()) {  // Close the bookmarks delete snackbar before going home.
+                        // Set the close flag.
+                        closeActivityAfterDismissingSnackbar = true;
+
+                        // Dismiss the snackbar.
+                        bookmarksDeletedSnackbar.dismiss();
+                    } else {  // Go home immediately.
+                        // Update the bookmarks folder for the bookmarks drawer in `MainWebViewActivity`.
+                        MainWebViewActivity.currentBookmarksFolder = "";
+
+                        // Close the bookmarks drawer and reload the bookmarks `ListView` when returning to `MainWebViewActivity`.
+                        MainWebViewActivity.restartFromBookmarksActivity = true;
+
+                        // Return to `MainWebViewActivity`.
+                        NavUtils.navigateUpFromSameTask(this);
+                    }
+                } else {  // Currently in a subfolder.
                     // Place the former parent folder in `currentFolder`.
                     currentFolder = bookmarksDatabaseHelper.getParentFolder(currentFolder);
 
-                    // Update `bookmarksListView`.
-                    updateBookmarksListView(currentFolder);
+                    // Load the new folder.
+                    loadFolder();
                 }
                 break;
 
-            case R.id.create_folder:
-                // Show the `CreateBookmarkFolderDialog` `AlertDialog` and name the instance `@string/create_folder`.
-                AppCompatDialogFragment createBookmarkFolderDialog = new CreateBookmarkFolderDialog();
-                createBookmarkFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_folder));
-                break;
-
             case R.id.options_menu_select_all_bookmarks:
+                // Get the total number of bookmarks.
                 int numberOfBookmarks = bookmarksListView.getCount();
 
+                // Select them all.
                 for (int i = 0; i < numberOfBookmarks; i++) {
                     bookmarksListView.setItemChecked(i, true);
                 }
@@ -592,30 +684,37 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
     @Override
     public void onBackPressed() {
-        if (currentFolder.isEmpty()) {  // Exit BookmarksActivity if currently in the home folder.
-            super.onBackPressed();
-        } else {  // Navigate up one folder.
-            // Place the former parent folder in `currentFolder`.
-            currentFolder = bookmarksDatabaseHelper.getParentFolder(currentFolder);
+        // Check to see if a snackbar is currently displayed.  If so, it must be closed before exiting so that a pending delete is completed before reloading the ListView in the bookmarks drawer.
+        if ((bookmarksDeletedSnackbar != null) && bookmarksDeletedSnackbar.isShown()) {  // Close the bookmarks delete snackbar before going home.
+            // Set the close flag.
+            closeActivityAfterDismissingSnackbar = true;
+
+            // Dismiss the snackbar.
+            bookmarksDeletedSnackbar.dismiss();
+        } else {  // Go home immediately.
+            // Update the bookmarks folder for the bookmarks drawer in the main WebView activity.
+            MainWebViewActivity.currentBookmarksFolder = currentFolder;
 
-            // Reload the `ListView`.
-            updateBookmarksListView(currentFolder);
+            // Close the bookmarks drawer and reload the bookmarks ListView when returning to the main WebView activity.
+            MainWebViewActivity.restartFromBookmarksActivity = true;
+
+            // Exit `BookmarksActivity`.
+            super.onBackPressed();
         }
     }
 
     @Override
     public void onCreateBookmark(AppCompatDialogFragment dialogFragment) {
         // Get the `EditTexts` from the `dialogFragment`.
-        EditText createBookmarkNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_bookmark_name_edittext);
-        EditText createBookmarkUrlEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_bookmark_url_edittext);
+        EditText createBookmarkNameEditText = dialogFragment.getDialog().findViewById(R.id.create_bookmark_name_edittext);
+        EditText createBookmarkUrlEditText = dialogFragment.getDialog().findViewById(R.id.create_bookmark_url_edittext);
 
         // Extract the strings from the `EditTexts`.
         String bookmarkNameString = createBookmarkNameEditText.getText().toString();
         String bookmarkUrlString = createBookmarkUrlEditText.getText().toString();
 
-        // Convert the favoriteIcon Bitmap to a byte array.
+        // Convert the favoriteIcon Bitmap to a byte array.  `0` is for lossless compression (the only option for a PNG).
         ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
-        // `0` is for lossless compression (the only option for a PNG).
         MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
         byte[] favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray();
 
@@ -623,29 +722,36 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         int newBookmarkDisplayOrder = bookmarksListView.getCount();
 
         // Create the bookmark.
-        bookmarksDatabaseHelper.createBookmark(bookmarkNameString, bookmarkUrlString, newBookmarkDisplayOrder, currentFolder, favoriteIconByteArray);
+        bookmarksDatabaseHelper.createBookmark(bookmarkNameString, bookmarkUrlString, currentFolder, newBookmarkDisplayOrder, favoriteIconByteArray);
+
+        // Update `bookmarksCursor` with the current contents of this folder.
+        bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
 
-        // Refresh the `ListView`.  `setSelection` scrolls to the bottom of the list.
-        updateBookmarksListView(currentFolder);
+        // Update the `ListView`.
+        bookmarksCursorAdapter.changeCursor(bookmarksCursor);
+
+        // Scroll to the new bookmark.
         bookmarksListView.setSelection(newBookmarkDisplayOrder);
     }
 
     @Override
     public void onCreateBookmarkFolder(AppCompatDialogFragment dialogFragment) {
-        // Get `create_folder_name_edit_text` and extract the string.
-        EditText createFolderNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_folder_name_edittext);
+        // Get handles for the views in `dialogFragment`.
+        EditText createFolderNameEditText = dialogFragment.getDialog().findViewById(R.id.create_folder_name_edittext);
+        RadioButton defaultFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon_radiobutton);
+        ImageView folderIconImageView = dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon);
+
+        // Get new folder name string.
         String folderNameString = createFolderNameEditText.getText().toString();
 
         // 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);
+        if (defaultFolderIconRadioButton.isChecked()) {  // Use the default folder icon.
+            // Get the default folder icon and convert it to a `Bitmap`.
             Drawable folderIconDrawable = folderIconImageView.getDrawable();
             BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
             folderIconBitmap = folderIconBitmapDrawable.getBitmap();
-        } else {  // Assign `favoriteIcon` from the `WebView`.
+        } else {  // Use the `WebView` favorite icon.
             folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
         }
 
@@ -657,34 +763,38 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         // 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);
+            bookmarksDatabaseHelper.updateDisplayOrder(databaseId, i + 1);
         }
 
-        // Create the folder, placing it at the top of the ListView
-        bookmarksDatabaseHelper.createFolder(folderNameString, 0, currentFolder, folderIconByteArray);
+        // Create the folder, which will be placed at the top of the `ListView`.
+        bookmarksDatabaseHelper.createFolder(folderNameString, currentFolder, folderIconByteArray);
 
-        // Refresh the ListView.
-        updateBookmarksListView(currentFolder);
+        // Update `bookmarksCursor` with the current contents of this folder.
+        bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
+
+        // Update the `ListView`.
+        bookmarksCursorAdapter.changeCursor(bookmarksCursor);
+
+        // Scroll to the new folder.
+        bookmarksListView.setSelection(0);
     }
 
     @Override
-    public void onSaveEditBookmark(AppCompatDialogFragment dialogFragment) {
-        // Get a long array with the the databaseId of the selected bookmark and convert it to an `int`.
-        long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
-        int selectedBookmarkDatabaseId = (int) selectedBookmarksLongArray[0];
+    public void onSaveBookmark(AppCompatDialogFragment dialogFragment, int selectedBookmarkDatabaseId) {
+        // Get handles for the views from `dialogFragment`.
+        EditText editBookmarkNameEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_name_edittext);
+        EditText editBookmarkUrlEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_url_edittext);
+        RadioButton currentBookmarkIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_current_icon_radiobutton);
 
-        // Get the `EditText`s from the `editBookmarkDialogFragment` and extract the strings.
-        EditText editBookmarkNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.edit_bookmark_name_edittext);
+        // Store the bookmark strings.
         String bookmarkNameString = editBookmarkNameEditText.getText().toString();
-        EditText editBookmarkUrlEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.edit_bookmark_url_edittext);
         String bookmarkUrlString = editBookmarkUrlEditText.getText().toString();
 
-        // Get `edit_bookmark_current_icon_radiobutton`.
-        RadioButton currentBookmarkIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_bookmark_current_icon_radiobutton);
-
+        // Update the bookmark.
         if (currentBookmarkIconRadioButton.isChecked()) {  // Update the bookmark without changing the favorite icon.
             bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString);
         } else {  // Update the bookmark using the `WebView` favorite icon.
+            // Convert the favorite icon to a byte array.  `0` is for lossless compression (the only option for a PNG).
             ByteArrayOutputStream newFavoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
             MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
             byte[] newFavoriteIconByteArray = newFavoriteIconByteArrayOutputStream.toByteArray();
@@ -696,85 +806,95 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         // Close the contextual action mode.
         contextualActionMode.finish();
 
-        // Refresh the `ListView`.  `setSelection` scrolls to the position of the bookmark that was edited.
-        updateBookmarksListView(currentFolder);
-        bookmarksListView.setSelection(selectedBookmarkPosition);
+        // Update `bookmarksCursor` with the contents of the current folder.
+        bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
+
+        // Update the `ListView`.
+        bookmarksCursorAdapter.changeCursor(bookmarksCursor);
     }
 
     @Override
-    public void onSaveEditBookmarkFolder(AppCompatDialogFragment dialogFragment) {
+    public void onSaveBookmarkFolder(AppCompatDialogFragment dialogFragment, int selectedFolderDatabaseId) {
+        // Get handles for the views from `dialogFragment`.
+        RadioButton currentFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_folder_current_icon_radiobutton);
+        RadioButton defaultFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_radiobutton);
+        ImageView defaultFolderIconImageView = dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_imageview);
+        EditText editFolderNameEditText = dialogFragment.getDialog().findViewById(R.id.edit_folder_name_edittext);
+
         // Get the new folder name.
-        EditText editFolderNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.edit_folder_name_edittext);
         String newFolderNameString = editFolderNameEditText.getText().toString();
 
-        // Check to see if the new folder name is unique.
-        Cursor bookmarkFolderCursor = bookmarksDatabaseHelper.getFolderCursor(newFolderNameString);
-        int existingFoldersWithNewName = bookmarkFolderCursor.getCount();
-        bookmarkFolderCursor.close();
-        if ( ((existingFoldersWithNewName == 0) || newFolderNameString.equals(oldFolderNameString)) && !newFolderNameString.isEmpty()) {
-            // Get a long array with the the database ID of the selected folder and convert it to an `int`.
-            long[] selectedFolderLongArray = bookmarksListView.getCheckedItemIds();
-            int selectedFolderDatabaseId = (int) selectedFolderLongArray[0];
-
-            // Get the `RadioButtons` from the `Dialog`.
-            RadioButton currentFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_folder_current_icon_radiobutton);
-            RadioButton defaultFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_radiobutton);
-
-            // Check if the favorite icon has changed.
-            if (currentFolderIconRadioButton.isChecked()) {
-                // Update the folder name if it has changed without modifying the favorite icon.
-                if (!newFolderNameString.equals(oldFolderNameString)) {
-                    bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString);
-
-                    // Refresh the `ListView`.  `setSelection` scrolls to the position of the folder that was edited.
-                    updateBookmarksListView(currentFolder);
-                    bookmarksListView.setSelection(selectedBookmarkPosition);
-                }
-            } else {  // Update the folder icon.
-                // Get the new folder icon `Bitmap`.
-                Bitmap folderIconBitmap;
-                if (defaultFolderIconRadioButton.isChecked()) {
-                    // Get the default folder icon `ImageView` from the `Drawable` and convert it to a `Bitmap`.
-                    ImageView folderIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon);
-                    Drawable folderIconDrawable = folderIconImageView.getDrawable();
-                    BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
-                    folderIconBitmap = folderIconBitmapDrawable.getBitmap();
-                } else {  // Get the web page icon `ImageView` from the `Dialog`.
-                    folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
-                }
+        // Check if the favorite icon has changed.
+        if (currentFolderIconRadioButton.isChecked()) {  // Only the name has changed.
+            // Update the name in the database.
+            bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString);
+        } else if (!currentFolderIconRadioButton.isChecked() && newFolderNameString.equals(oldFolderNameString)) {  // Only the icon has changed.
+            // Get the new folder icon `Bitmap`.
+            Bitmap folderIconBitmap;
+            if (defaultFolderIconRadioButton.isChecked()) {
+                // Get the default folder icon and convert it to a `Bitmap`.
+                Drawable folderIconDrawable = defaultFolderIconImageView.getDrawable();
+                BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
+                folderIconBitmap = folderIconBitmapDrawable.getBitmap();
+            } else {  // Use the `WebView` favorite icon.
+                folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+            }
 
-                // Convert the folder `Bitmap` 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 the folder `Bitmap` 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();
+
+            // Update the folder icon in the database.
+            bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, folderIconByteArray);
+        } else {  // The folder icon and the name have changed.
+            // Instantiate the new folder icon `Bitmap`.
+            Bitmap folderIconBitmap;
+
+            // Populate the new folder icon bitmap.
+            if (defaultFolderIconRadioButton.isChecked()) {
+                // Get the default folder icon and convert it to a `Bitmap`.
+                Drawable folderIconDrawable = defaultFolderIconImageView.getDrawable();
+                BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
+                folderIconBitmap = folderIconBitmapDrawable.getBitmap();
+            } else {  // Use the `WebView` favorite icon.
+                folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+            }
 
-                bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString, folderIconByteArray);
+            // Convert the folder `Bitmap` 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();
 
-                // 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_save_folder) + " \"" + newFolderNameString + "\"";
-            Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), cannot_rename_folder, Snackbar.LENGTH_INDEFINITE).show();
+            // Update the folder name and icon in the database.
+            bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString, folderIconByteArray);
         }
 
+        // Update `bookmarksCursor` with the current contents of this folder.
+        bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
+
+        // Update the `ListView`.
+        bookmarksCursorAdapter.changeCursor(bookmarksCursor);
+
         // Close the contextual action mode.
         contextualActionMode.finish();
     }
 
     @Override
     public void onMoveToFolder(AppCompatDialogFragment dialogFragment) {
-        // Get the new folder database id.
-        ListView folderListView = (ListView) dialogFragment.getDialog().findViewById(R.id.move_to_folder_listview);
+        // Get a handle for the `ListView` from `dialogFragment`.
+        ListView folderListView = dialogFragment.getDialog().findViewById(R.id.move_to_folder_listview);
+
+        // Store a long array of the selected folders.
         long[] newFolderLongArray = folderListView.getCheckedItemIds();
 
-        // Get the new folder database ID.
+        // Get the new folder database ID.  Only one folder will be selected.
         int newFolderDatabaseId = (int) newFolderLongArray[0];
 
         // Instantiate `newFolderName`.
         String newFolderName;
 
+        // Set the new folder name.
         if (newFolderDatabaseId == 0) {
             // The new folder is the home folder, represented as `""` in the database.
             newFolderName = "";
@@ -785,6 +905,8 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
         // Get a long array with the the database ID of the selected bookmarks.
         long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
+
+        // Move each of the selected bookmarks to the new folder.
         for (long databaseIdLong : selectedBookmarksLongArray) {
             // Get `databaseIdInt` for each selected bookmark.
             int databaseIdInt = (int) databaseIdLong;
@@ -793,127 +915,166 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
             bookmarksDatabaseHelper.moveToFolder(databaseIdInt, newFolderName);
         }
 
-        // Refresh the `ListView`.
-        updateBookmarksListView(currentFolder);
+        // Update `bookmarksCursor` with the current contents of this folder.
+        bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
+
+        // Update the `ListView`.
+        bookmarksCursorAdapter.changeCursor(bookmarksCursor);
 
         // Close the contextual app bar.
         contextualActionMode.finish();
     }
 
-    private void updateBookmarksListView(String folderName) {
-        // Get a `Cursor` with the current contents of the bookmarks database.
-        bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(folderName);
+    private void deleteBookmarkFolderContents(int databaseId) {
+        // Get the name of the folder.
+        String folderName = bookmarksDatabaseHelper.getFolderName(databaseId);
 
-        // Setup `bookmarksCursorAdapter` with `this` context.  `false` disables `autoRequery`.
-        CursorAdapter bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) {
-            @Override
-            public View newView(Context context, Cursor cursor, ViewGroup parent) {
-                // Inflate the individual item layout.  `false` does not attach it to the root.
-                return getLayoutInflater().inflate(R.layout.bookmarks_item_linearlayout, parent, false);
-            }
+        // Get the contents of the folder.
+        Cursor folderCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(folderName);
 
-            @Override
-            public void bindView(View view, Context context, Cursor cursor) {
-                // Get the favorite icon byte array from the `Cursor`.
-                byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON));
+        // Delete each of the bookmarks in the folder.
+        for (int i = 0; i < folderCursor.getCount(); i++) {
+            // Move `folderCursor` to the current row.
+            folderCursor.moveToPosition(i);
 
-                // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last.
-                Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length);
+            // Get the database ID of the item.
+            int itemDatabaseId = folderCursor.getInt(folderCursor.getColumnIndex(BookmarksDatabaseHelper._ID));
 
-                // Display the bitmap in `bookmarkFavoriteIcon`.
-                ImageView bookmarkFavoriteIcon = (ImageView) view.findViewById(R.id.bookmark_favorite_icon);
-                bookmarkFavoriteIcon.setImageBitmap(favoriteIconBitmap);
+            // If this is a folder, recursively delete the contents first.
+            if (bookmarksDatabaseHelper.isFolder(itemDatabaseId)) {
+                deleteBookmarkFolderContents(itemDatabaseId);
+            }
 
+            // Delete the bookmark.
+            bookmarksDatabaseHelper.deleteBookmark(itemDatabaseId);
+        }
+    }
 
-                // Get the bookmark name from the cursor and display it in `bookmarkNameTextView`.
-                String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
-                TextView bookmarkNameTextView = (TextView) view.findViewById(R.id.bookmark_name);
-                bookmarkNameTextView.setText(bookmarkNameString);
+    private void updateMoveIcons() {
+        // Get a long array of the selected bookmarks.
+        long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
 
-                // Make the font bold for folders.
-                if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) {
-                    bookmarkNameTextView.setTypeface(Typeface.DEFAULT_BOLD);
-                } else {  // Reset the font to default for normal bookmarks.
-                    bookmarkNameTextView.setTypeface(Typeface.DEFAULT);
-                }
+        // Get the database IDs for the first, last, and selected bookmarks.
+        int selectedBookmarkDatabaseId = (int) selectedBookmarksLongArray[0];
+        int firstBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(0);
+        // bookmarksListView is 0 indexed.
+        int lastBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(bookmarksListView.getCount() - 1);
+
+        // Update the move bookmark up `MenuItem`.
+        if (selectedBookmarkDatabaseId == firstBookmarkDatabaseId) {  // The selected bookmark is in the first position.
+            // Disable the move bookmark up `MenuItem`.
+            moveBookmarkUpMenuItem.setEnabled(false);
+
+            //  Set the move bookmark up icon to be ghosted.
+            moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_disabled);
+        } else {  // The selected bookmark is not in the first position.
+            // Enable the move bookmark up `MenuItem`.
+            moveBookmarkUpMenuItem.setEnabled(true);
+
+            // 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);
             }
-        };
+        }
 
-        // Update the ListView.
-        bookmarksListView.setAdapter(bookmarksCursorAdapter);
+        // Update the move bookmark down `MenuItem`.
+        if (selectedBookmarkDatabaseId == lastBookmarkDatabaseId) {  // The selected bookmark is in the last position.
+            // Disable the move bookmark down `MenuItem`.
+            moveBookmarkDownMenuItem.setEnabled(false);
+
+            // Set the move bookmark down icon to be ghosted.
+            moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_disabled);
+        } else {  // The selected bookmark is not in the last position.
+            // Enable the move bookmark down `MenuItem`.
+            moveBookmarkDownMenuItem.setEnabled(true);
+
+            // 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);
+            }
+        }
+    }
 
-        // Set the AppBar title.
-        if (currentFolder.isEmpty()) {
-            appBar.setTitle(R.string.bookmarks);
-        } else {
-            appBar.setTitle(currentFolder);
+    private void scrollBookmarks(int selectedBookmarkPosition) {
+        // Get the first and last visible bookmark positions.
+        int firstVisibleBookmarkPosition = bookmarksListView.getFirstVisiblePosition();
+        int lastVisibleBookmarkPosition = bookmarksListView.getLastVisiblePosition();
+
+        // Calculate the number of bookmarks per screen.
+        int numberOfBookmarksPerScreen = lastVisibleBookmarkPosition - firstVisibleBookmarkPosition;
+
+        // Scroll with the moved bookmark if necessary.
+        if (selectedBookmarkPosition <= firstVisibleBookmarkPosition) {  // The selected bookmark position is at or above the top of the screen.
+            // Scroll to the selected bookmark position.
+            bookmarksListView.setSelection(selectedBookmarkPosition);
+        } else if (selectedBookmarkPosition >= (lastVisibleBookmarkPosition - 1)) {  // The selected bookmark is at or below the bottom of the screen.  The `-1` handles partial bookmarks displayed at the bottom of the `ListView`.
+            // Scroll to display the selected bookmark at the bottom of the screen.  `+1` assured that the entire bookmark will be displayed in situations where only a partial bookmark fits at the bottom of the `ListView`.
+            bookmarksListView.setSelection(selectedBookmarkPosition - numberOfBookmarksPerScreen + 1);
         }
     }
 
-    private void updateBookmarksListViewExcept(long[] exceptIdLongArray, String folderName) {
-        // Get a `Cursor` with the current contents of the bookmarks database except for the specified database IDs.
-        bookmarksCursor = bookmarksDatabaseHelper.getBookmarksCursorExcept(exceptIdLongArray, folderName);
+    private void loadFolder() {
+        // Update `bookmarksCursor` with the contents of the bookmarks database for the current folder.
+        bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder);
 
-        // Setup `bookmarksCursorAdapter` with `this` context.  `false` disables autoRequery.
-        CursorAdapter bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) {
+        // Setup a `CursorAdapter`.  `this` specifies the `Context`.  `false` disables `autoRequery`.
+        bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) {
             @Override
             public View newView(Context context, Cursor cursor, ViewGroup parent) {
                 // Inflate the individual item layout.  `false` does not attach it to the root.
-                return getLayoutInflater().inflate(R.layout.bookmarks_item_linearlayout, parent, false);
+                return getLayoutInflater().inflate(R.layout.bookmarks_activity_item_linearlayout, parent, false);
             }
 
             @Override
             public void bindView(View view, Context context, Cursor cursor) {
-                // Get the favorite icon byte array from the cursor.
+                // Get handles for the views.
+                ImageView bookmarkFavoriteIcon = view.findViewById(R.id.bookmark_favorite_icon);
+                TextView bookmarkNameTextView = view.findViewById(R.id.bookmark_name);
+
+                // Get the favorite icon byte array from the `Cursor`.
                 byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON));
 
-                // Convert the byte array to a Bitmap beginning at the first byte and ending at the last.
+                // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last.
                 Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length);
 
                 // Display the bitmap in `bookmarkFavoriteIcon`.
-                ImageView bookmarkFavoriteIcon = (ImageView) view.findViewById(R.id.bookmark_favorite_icon);
                 bookmarkFavoriteIcon.setImageBitmap(favoriteIconBitmap);
 
-
                 // Get the bookmark name from the cursor and display it in `bookmarkNameTextView`.
                 String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
-                TextView bookmarkNameTextView = (TextView) view.findViewById(R.id.bookmark_name);
                 bookmarkNameTextView.setText(bookmarkNameString);
 
                 // Make the font bold for folders.
                 if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) {
-                    // The first argument is `null` because we don't want to change the font.
-                    bookmarkNameTextView.setTypeface(null, Typeface.BOLD);
-                } else {  // Reset the font to default.
+                    bookmarkNameTextView.setTypeface(Typeface.DEFAULT_BOLD);
+                } else {  // Reset the font to default for normal bookmarks.
                     bookmarkNameTextView.setTypeface(Typeface.DEFAULT);
                 }
             }
         };
 
-        // Update the `ListView`.
+        // Populate the `ListView` with the adapter.
         bookmarksListView.setAdapter(bookmarksCursorAdapter);
-    }
-
-    private void deleteBookmarkFolderContents(int databaseId) {
-        // Get the name of the folder.
-        String folderName = bookmarksDatabaseHelper.getFolderName(databaseId);
-
-        // Get the contents of the folder.
-        Cursor folderCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(folderName);
-
-        for (int i = 0; i < folderCursor.getCount(); i++) {
-            // Move `folderCursor` to the current row.
-            folderCursor.moveToPosition(i);
 
-            // Get the database ID of the item.
-            int itemDatabaseId = folderCursor.getInt(folderCursor.getColumnIndex(BookmarksDatabaseHelper._ID));
+        // Set the `AppBar` title.
+        if (currentFolder.isEmpty()) {
+            appBar.setTitle(R.string.bookmarks);
+        } else {
+            appBar.setTitle(currentFolder);
+        }
+    }
 
-            // If this is a folder, delete the contents first.
-            if (bookmarksDatabaseHelper.isFolder(itemDatabaseId)) {
-                deleteBookmarkFolderContents(itemDatabaseId);
-            }
+    @Override
+    public void onDestroy() {
+        // Close the bookmarks cursor and database.
+        bookmarksCursor.close();
+        bookmarksDatabaseHelper.close();
 
-            bookmarksDatabaseHelper.deleteBookmark(itemDatabaseId);
-        }
+        // Run the default commands.
+        super.onDestroy();
     }
 }
\ No newline at end of file