+ // Update the folder name and icon.
+ public void updateFolder(int databaseId, String oldFolderName, String newFolderName, String parentFolder, int displayOrder, byte[] folderIcon) {
+ // Get a writable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getWritableDatabase();
+
+ // Update the folder first. Store the updated values in `folderContentValues`.
+ ContentValues folderContentValues = new ContentValues();
+ folderContentValues.put(BOOKMARK_NAME, newFolderName);
+ folderContentValues.put(PARENT_FOLDER, parentFolder);
+ folderContentValues.put(DISPLAY_ORDER, displayOrder);
+ folderContentValues.put(FAVORITE_ICON, folderIcon);
+
+ // Run the update on the folder. The last argument is `null` because there are no `whereArgs`.
+ bookmarksDatabase.update(BOOKMARKS_TABLE, folderContentValues, _ID + " = " + databaseId, null);
+
+ // Update the bookmarks inside the folder. Store the new parent folder name in `bookmarkContentValues`.
+ ContentValues bookmarkContentValues = new ContentValues();
+ bookmarkContentValues.put(PARENT_FOLDER, newFolderName);
+
+ // SQL escape `oldFolderName`.
+ oldFolderName = DatabaseUtils.sqlEscapeString(oldFolderName);
+
+ // Run the update on all the bookmarks that currently list `oldFolderName` as their parent folder. The last argument is `null` because there are no `whereArgs`.
+ bookmarksDatabase.update(BOOKMARKS_TABLE, bookmarkContentValues, PARENT_FOLDER + " = " + oldFolderName, null);
+
+ // Close the database handle.
+ bookmarksDatabase.close();
+ }
+