- 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);