+ public void createFolder(String folderName, int displayOrder, String parentFolder, byte[] favoriteIcon) {
+ ContentValues bookmarkContentValues = new ContentValues();
+
+ // ID is created automatically.
+ bookmarkContentValues.put(DISPLAY_ORDER, displayOrder);
+ bookmarkContentValues.put(BOOKMARK_NAME, folderName);
+ bookmarkContentValues.put(PARENT_FOLDER, parentFolder);
+ bookmarkContentValues.put(IS_FOLDER, true);
+ bookmarkContentValues.put(FAVORITE_ICON, favoriteIcon);
+
+ // Get a writable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getWritableDatabase();
+
+ // The second argument is `null`, which makes it so that completely null rows cannot be created. Not a problem in our case.
+ bookmarksDatabase.insert(BOOKMARKS_TABLE, null, bookmarkContentValues);
+
+ // Close the database handle.
+ bookmarksDatabase.close();
+ }
+
+ public Cursor getBookmarkCursor(int databaseId) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // Prepare the SQL statement to get the `Cursor` for `databaseId`
+ final String GET_ONE_BOOKMARK = "Select * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + _ID + " = " + databaseId;
+
+ // 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.
+ return bookmarksDatabase.rawQuery(GET_ONE_BOOKMARK, null);
+ }
+
+ public Cursor getFolderCursor(String folderName) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // SQL escape `folderName`.
+ folderName = DatabaseUtils.sqlEscapeString(folderName);
+
+ // Prepare the SQL statement to get the `Cursor` for the folder.
+ final String GET_FOLDER = "Select * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + BOOKMARK_NAME + " = " + folderName +
+ " AND " + IS_FOLDER + " = " + 1;
+
+ // 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.
+ return bookmarksDatabase.rawQuery(GET_FOLDER, null);
+ }
+
+ public String getParentFolder(String currentFolder) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // SQL escape `currentFolder`.
+ currentFolder = DatabaseUtils.sqlEscapeString(currentFolder);
+
+ // Prepare the SQL statement to get the parent folder.
+ final String GET_PARENT_FOLDER = "Select * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + IS_FOLDER + " = " + 1 + " AND " + BOOKMARK_NAME + " = " + currentFolder;
+
+ // The second argument is `null` because there are no `selectionArgs`.
+ Cursor bookmarkCursor = bookmarksDatabase.rawQuery(GET_PARENT_FOLDER, null);
+ bookmarkCursor.moveToFirst();
+
+ // Store the name of the parent folder.
+ String parentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(PARENT_FOLDER));
+
+ // Close the `Cursor`.
+ bookmarkCursor.close();
+
+ return parentFolder;
+ }
+
+ public Cursor getAllBookmarksCursor() {