X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2FBookmarksDatabaseHandler.java;h=5a5a025a16aae46bb03fd25cc23bf67c81df9d77;hp=2194bc9957d709c57d5eb509e6c5af7646d51936;hb=81931a2a88e383f1071ab5134afe5bd70b31895d;hpb=bf644cc5270aca79529a87f19cbd04d3f5313f32 diff --git a/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseHandler.java b/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseHandler.java index 2194bc99..5a5a025a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseHandler.java +++ b/app/src/main/java/com/stoutner/privacybrowser/BookmarksDatabaseHandler.java @@ -62,10 +62,11 @@ public class BookmarksDatabaseHandler extends SQLiteOpenHelper { // Code for upgrading the database will be added here when the schema version > 1. } - public void createBookmark(String bookmarkName, String bookmarkURL, byte[] favoriteIcon) { + public void createBookmark(String bookmarkName, String bookmarkURL, int displayOrder, byte[] favoriteIcon) { ContentValues bookmarkContentValues = new ContentValues(); // ID is created automatically. + bookmarkContentValues.put(DISPLAY_ORDER, displayOrder); bookmarkContentValues.put(BOOKMARK_NAME, bookmarkName); bookmarkContentValues.put(BOOKMARK_URL, bookmarkURL); bookmarkContentValues.put(PARENT_FOLDER, ""); @@ -86,7 +87,7 @@ public class BookmarksDatabaseHandler extends SQLiteOpenHelper { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); - // Prepare the SQL statement to get the cursor for `databaseId`. + // Prepare the SQL statement to get the cursor for `databaseId` final String GET_ONE_BOOKMARK = "Select * FROM " + BOOKMARKS_TABLE + " WHERE " + _ID + " = " + databaseId; @@ -113,7 +114,7 @@ public class BookmarksDatabaseHandler extends SQLiteOpenHelper { // Prepare the SQL statement to select all items except those with the specified IDs. final String GET_All_BOOKMARKS_EXCEPT_SPECIFIED = "Select * FROM " + BOOKMARKS_TABLE + - " WHERE " + _ID + " NOT IN (" + doNotGetIdsString + ")"; + " WHERE " + _ID + " NOT IN (" + doNotGetIdsString + ") ORDER BY " + DISPLAY_ORDER + " ASC"; // Return the results as a `Cursor`. The second argument is `null` because there are no selectionArgs. // We can't close the `Cursor` because we need to use it in the parent activity. @@ -125,7 +126,7 @@ public class BookmarksDatabaseHandler extends SQLiteOpenHelper { SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); // Get everything in the BOOKMARKS_TABLE. - final String GET_ALL_BOOKMARKS = "Select * FROM " + BOOKMARKS_TABLE; + final String GET_ALL_BOOKMARKS = "Select * FROM " + BOOKMARKS_TABLE + " ORDER BY " + DISPLAY_ORDER + " ASC"; // Return the results as a Cursor. The second argument is `null` because there are no selectionArgs. // We can't close the Cursor because we need to use it in the parent activity. @@ -191,6 +192,22 @@ public class BookmarksDatabaseHandler extends SQLiteOpenHelper { bookmarksDatabase.close(); } + public void updateBookmarkDisplayOrder(int databaseId, int displayOrder) { + // Store the updated values in `bookmarkContentValues`. + ContentValues bookmarkContentValues = new ContentValues(); + + bookmarkContentValues.put(DISPLAY_ORDER, displayOrder); + + // Get a writable database handle. + SQLiteDatabase bookmarksDatabase = this.getWritableDatabase(); + + // Update the database. The last argument is `null` because there are no `whereArgs`. + bookmarksDatabase.update(BOOKMARKS_TABLE, bookmarkContentValues, _ID + " = " + databaseId, null); + + // Close the database handle. + bookmarksDatabase.close(); + } + public void deleteBookmark(int databaseId) { // Get a writable database handle. SQLiteDatabase bookmarksDatabase = this.getWritableDatabase();