diff --git a/app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java b/app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java index 3bfcf1f..cfe7174 100644 --- a/app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java +++ b/app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java @@ -142,6 +142,8 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel if (cursor.moveToFirst()) { subscriber.onItem(bindCursorToHistoryItem(cursor)); + } else { + subscriber.onItem(null); } cursor.close(); diff --git a/app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkModel.java b/app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkModel.java index 9d27d2c..d4cb905 100644 --- a/app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkModel.java +++ b/app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkModel.java @@ -19,42 +19,136 @@ import acr.browser.lightning.database.HistoryItem; */ public interface BookmarkModel { + /** + * Gets the bookmark associated with the URL. + * + * @param url the URL to look for. + * @return an observable that will emit either + * the bookmark associated with the URL or null. + */ @NonNull Single findBookmarkForUrl(@NonNull String url); + /** + * Determines if a URL is associated with a bookmark. + * + * @param url the URL to check. + * @return an observable that will emit true if + * the URL is a bookmark, false otherwise. + */ @NonNull Single isBookmark(@NonNull String url); + /** + * Adds a bookmark if one does not already exist with + * the same URL. + * + * @param item the bookmark to add. + * @return an observable that emits true if the bookmark + * was added, false otherwise. + */ @NonNull Single addBookmarkIfNotExists(@NonNull HistoryItem item); + /** + * Adds a list of bookmarks to the database. + * + * @param bookmarkItems the bookmarks to add. + * @return an observable that emits a complete event + * when all the bookmarks have been added. + */ @NonNull Completable addBookmarkList(@NonNull List bookmarkItems); + /** + * Deletes a bookmark from the database. + * + * @param bookmark the bookmark to delete. + * @return an observable that emits true when + * the bookmark is deleted, false otherwise. + */ @NonNull Single deleteBookmark(@NonNull HistoryItem bookmark); + /** + * Moves all bookmarks in the old folder to the new folder. + * + * @param oldName the name of the old folder. + * @param newName the name of the new folder. + * @return an observable that emits a completion + * event when the folder is renamed. + */ @NonNull Completable renameFolder(@NonNull String oldName, @NonNull String newName); + /** + * Deletes a folder from the database, all bookmarks + * in that folder will be moved to the root level. + * + * @param folderToDelete the folder to delete. + * @return an observable that emits a completion + * event when the folder has been deleted. + */ @NonNull Completable deleteFolder(@NonNull String folderToDelete); + /** + * Deletes all bookmarks in the database. + * + * @return an observable that emits a completion + * event when all bookmarks have been deleted. + */ @NonNull Completable deleteAllBookmarks(); + /** + * Changes the bookmark with the original URL + * with all the data from the new bookmark. + * + * @param oldBookmark the old bookmark to replace. + * @param newBookmark the new bookmark. + * @return an observable that emits a completion event + * when the bookmark edit is done. + */ @NonNull Completable editBookmark(@NonNull HistoryItem oldBookmark, @NonNull HistoryItem newBookmark); + /** + * Emits a list of all bookmarks + * + * @return an observable that emits a list + * of all bookmarks. + */ @NonNull Single> getAllBookmarks(); + /** + * Emits all bookmarks in a certain folder. + * If the folder chosen is null, then all bookmarks + * without a specified folder will be returned. + * + * @param folder gets the bookmarks from this folder, may be null. + * @return an observable that emits a list of bookmarks + * in the given folder. + */ @NonNull Single> getBookmarksFromFolder(@Nullable String folder); + /** + * Returns all folders as {@link HistoryItem}. + * The root folder is omitted. + * + * @return an observable that emits a list of folders. + */ @NonNull Single> getFolders(); + /** + * Returns the names of all folders. + * The root folder is omitted. + * + * @return an observable that emits a list of folder names. + */ @NonNull Single> getFolderNames(); }