+ case R.id.move_bookmark_up:
+ // Get the selected bookmark database ID.
+ selectedBookmarkLongArray = bookmarksListView.getCheckedItemIds();
+ selectedBookmarkDatabaseId = (int) selectedBookmarkLongArray[0];
+
+ // Initialize `selectedBookmarkNewPosition`.
+ selectedBookmarkNewPosition = 0;
+
+ 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.
+ bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i - 1);
+ selectedBookmarkNewPosition = i - 1;
+ } else { // Move the bookmark above the selected bookmark down one.
+ bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i + 1);
+ }
+ } 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.
+ bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i);
+ }
+ }
+
+ // Refresh the ListView.
+ updateBookmarksListView();
+
+ // Select the previously selected bookmark in the new location.
+ bookmarksListView.setItemChecked(selectedBookmarkNewPosition, true);
+
+ bookmarksListView.setSelection(selectedBookmarkNewPosition - 5);
+
+ break;
+
+ case R.id.move_bookmark_down:
+ // Get the selected bookmark database ID.
+ selectedBookmarkLongArray = bookmarksListView.getCheckedItemIds();
+ selectedBookmarkDatabaseId = (int) selectedBookmarkLongArray[0];
+
+ // Initialize `selectedBookmarkNewPosition`.
+ selectedBookmarkNewPosition = 0;
+
+ 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.
+ bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i + 1);
+ selectedBookmarkNewPosition = i + 1;
+ } else { // Move the bookmark below the selected bookmark up one.
+ bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i - 1);
+ }
+ } 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.
+ bookmarksDatabaseHandler.updateBookmarkDisplayOrder(databaseId, i);
+ }
+ }
+
+ // Refresh the ListView.
+ updateBookmarksListView();
+
+ // Select the previously selected bookmark in the new location.
+ bookmarksListView.setItemChecked(selectedBookmarkNewPosition, true);
+
+ bookmarksListView.setSelection(selectedBookmarkNewPosition - 5);
+ break;
+