mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
favorites code: simplified
This commit is contained in:
parent
82cc9fd8d2
commit
8207b5db87
11 changed files with 101 additions and 46 deletions
|
@ -204,6 +204,26 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized boolean hasFavorites() {
|
||||
if (myInterface != null) {
|
||||
try {
|
||||
return myInterface.hasFavorites();
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public synchronized boolean isFavorite(Book book) {
|
||||
if (myInterface != null) {
|
||||
try {
|
||||
return myInterface.isFavorite(SerializerUtil.serialize(book));
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public synchronized void setBookFavorite(Book book, boolean favorite) {
|
||||
if (myInterface != null) {
|
||||
try {
|
||||
|
|
|
@ -20,6 +20,9 @@ interface LibraryInterface {
|
|||
boolean saveBook(in String book, in boolean force);
|
||||
void removeBook(in String book, in boolean deleteFromDisk);
|
||||
void addBookToRecentList(in String book);
|
||||
|
||||
boolean hasFavorites();
|
||||
boolean isFavorite(in String book);
|
||||
void setBookFavorite(in String book, in boolean favorite);
|
||||
|
||||
TextPosition getStoredPosition(in long bookId);
|
||||
|
|
|
@ -161,6 +161,14 @@ public class LibraryService extends Service {
|
|||
myCollection.addBookToRecentList(SerializerUtil.deserializeBook(book));
|
||||
}
|
||||
|
||||
public boolean hasFavorites() {
|
||||
return myCollection.hasFavorites();
|
||||
}
|
||||
|
||||
public boolean isFavorite(String book) {
|
||||
return myCollection.isFavorite(SerializerUtil.deserializeBook(book));
|
||||
}
|
||||
|
||||
public void setBookFavorite(String book, boolean favorite) {
|
||||
myCollection.setBookFavorite(SerializerUtil.deserializeBook(book), favorite);
|
||||
}
|
||||
|
|
|
@ -691,6 +691,25 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
return ids;
|
||||
}
|
||||
|
||||
protected boolean hasFavorites() {
|
||||
final Cursor cursor = myDatabase.rawQuery(
|
||||
"SELECT book_id FROM Favorites LIMIT 1", null
|
||||
);
|
||||
boolean result = cursor.moveToNext();
|
||||
cursor.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
protected boolean isFavorite(long bookId) {
|
||||
final Cursor cursor = myDatabase.rawQuery(
|
||||
"SELECT book_id FROM Favorites WHERE book_id = ? LIMIT 1",
|
||||
new String[] { String.valueOf(bookId) }
|
||||
);
|
||||
boolean result = cursor.moveToNext();
|
||||
cursor.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
private SQLiteStatement myAddToFavoritesStatement;
|
||||
protected void addToFavorites(long bookId) {
|
||||
if (myAddToFavoritesStatement == null) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue