From: Soren Stoutner Date: Fri, 22 Sep 2017 16:48:26 +0000 (-0700) Subject: Update the display order after deleting a bookmark. Fixes https://redmine.stoutner... X-Git-Tag: v2.7~22 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=3a3c563abd8ddb1c3fc5f4fe60896626bca86c71;p=PrivacyBrowserAndroid.git Update the display order after deleting a bookmark. Fixes https://redmine.stoutner.com/issues/49. --- diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java index 5e9d9faf..efdb06a7 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java @@ -476,6 +476,20 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Delete `databaseIdInt`. bookmarksDatabaseHelper.deleteBookmark(databaseIdInt); } + + // Update the display order. + for (int i = 0; i < bookmarksListView.getCount(); i++) { + // Get the database ID for the current bookmark. + int currentBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(i); + + // Move `bookmarksCursor` to the current bookmark position. + bookmarksCursor.moveToPosition(i); + + // Update the display order only if it is not correct in the database. + if (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)) != i) { + bookmarksDatabaseHelper.updateBookmarkDisplayOrder(currentBookmarkDatabaseId, i); + } + } break; } }