+ // 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 menu item.
+ if (selectedBookmarkDatabaseId == firstBookmarkDatabaseId) { // The selected bookmark is in the first position.
+ // Disable the move bookmark up menu item.
+ moveBookmarkUpMenuItem.setEnabled(false);
+
+ // Set the icon.
+ moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_disabled);
+ } else { // The selected bookmark is not in the first position.
+ // Enable the move bookmark up menu item.
+ moveBookmarkUpMenuItem.setEnabled(true);
+
+ // Set the icon according to the theme.
+ moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled);
+ }
+
+ // Update the move bookmark down menu item.
+ if (selectedBookmarkDatabaseId == lastBookmarkDatabaseId) { // The selected bookmark is in the last position.
+ // Disable the move bookmark down menu item.
+ moveBookmarkDownMenuItem.setEnabled(false);
+
+ // Set the icon.
+ moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_disabled);
+ } else { // The selected bookmark is not in the last position.
+ // Enable the move bookmark down menu item.
+ moveBookmarkDownMenuItem.setEnabled(true);
+
+ // Set the icon.
+ moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled);
+ }
+ }
+
+ 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 list view. This command scrolls to display the selected bookmark at the bottom of the screen.
+ // `+1` assures that the entire bookmark will be displayed in situations where only a partial bookmark fits at the bottom of the list view.
+ bookmarksListView.setSelection(selectedBookmarkPosition - numberOfBookmarksPerScreen + 1);
+ }
+ }
+
+ private void loadFolder() {
+ // Update bookmarks cursor with the contents of the bookmarks database for the current folder.
+ bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder);
+
+ // Setup a `CursorAdapter`. `this` specifies the `Context`. `false` disables `autoRequery`.
+ bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) {