-
- // Update the display order for one bookmark or folder.
- fun updateDisplayOrder(databaseId: Int, displayOrder: Int) {
- // Get a writable database handle.
- val bookmarksDatabase = this.writableDatabase
-
- // Create a content values.
- val bookmarkContentValues = ContentValues()
-
- // Store the new display order.
- bookmarkContentValues.put(DISPLAY_ORDER, displayOrder)
-
- // Update the database.
- bookmarksDatabase.update(BOOKMARKS_TABLE, bookmarkContentValues, "$ID = $databaseId", null)
-
- // Close the database handle.
- bookmarksDatabase.close()
- }
-
- // Move one bookmark or folder to a new folder.
- fun moveToFolder(databaseId: Int, newFolder: String) {
- // Get a writable database handle.
- val bookmarksDatabase = this.writableDatabase
-
- // SQL escape the new folder name.
- val sqlEscapedNewFolder = DatabaseUtils.sqlEscapeString(newFolder)
-
- // Get a cursor for all the bookmarks in the new folder ordered by display order.
- val newFolderCursor = bookmarksDatabase.rawQuery("SELECT * FROM $BOOKMARKS_TABLE WHERE $PARENT_FOLDER = $sqlEscapedNewFolder ORDER BY $DISPLAY_ORDER ASC", null)
-
- // Set the new display order.
- val displayOrder: Int = if (newFolderCursor.count > 0) { // There are already bookmarks in the folder.
- // Move to the last bookmark.
- newFolderCursor.moveToLast()
-
- // Set the display order to be one greater that the last bookmark.
- newFolderCursor.getInt(newFolderCursor.getColumnIndexOrThrow(DISPLAY_ORDER)) + 1
- } else { // There are no bookmarks in the new folder.
- // Set the display order to be `0`.
- 0
- }
-
- // Close the cursor.
- newFolderCursor.close()
-
- // Create a content values.
- val bookmarkContentValues = ContentValues()
-
- // Store the new values.
- bookmarkContentValues.put(DISPLAY_ORDER, displayOrder)
- bookmarkContentValues.put(PARENT_FOLDER, newFolder)
-
- // Update the database.
- bookmarksDatabase.update(BOOKMARKS_TABLE, bookmarkContentValues, "$ID = $databaseId", null)
-
- // Close the database handle.
- bookmarksDatabase.close()
- }
-
- // Delete one bookmark.
- fun deleteBookmark(databaseId: Int) {
- // Get a writable database handle.
- val bookmarksDatabase = this.writableDatabase
-
- // Deletes the row with the given database ID.
- bookmarksDatabase.delete(BOOKMARKS_TABLE, "$ID = $databaseId", null)
-
- // Close the database handle.
- bookmarksDatabase.close()
- }
-}
\ No newline at end of file