mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
synchronization with library-service branch
This commit is contained in:
parent
fd338adbd1
commit
d01cd4841d
8 changed files with 89 additions and 12 deletions
|
@ -60,15 +60,28 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
|||
}
|
||||
};
|
||||
|
||||
private static Runnable combined(final Runnable action0, final Runnable action1) {
|
||||
if (action0 == null) {
|
||||
return action1;
|
||||
}
|
||||
if (action1 == null) {
|
||||
return action0;
|
||||
}
|
||||
return new Runnable() {
|
||||
public void run() {
|
||||
action0.run();
|
||||
action1.run();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public synchronized void bindToService(Context context, Runnable onBindAction) {
|
||||
if (myInterface != null && myContext == context) {
|
||||
if (onBindAction != null) {
|
||||
onBindAction.run();
|
||||
}
|
||||
} else {
|
||||
if (onBindAction != null) {
|
||||
myOnBindAction = onBindAction;
|
||||
}
|
||||
myOnBindAction = combined(myOnBindAction, onBindAction);
|
||||
context.bindService(
|
||||
new Intent(context, LibraryService.class),
|
||||
this,
|
||||
|
@ -149,7 +162,6 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
|||
try {
|
||||
return SerializerUtil.deserializeBook(myInterface.getRecentBook(index));
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -205,6 +217,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);
|
||||
|
|
|
@ -156,6 +156,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);
|
||||
}
|
||||
|
|
|
@ -690,8 +690,27 @@ public 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;
|
||||
public /*protected*/ void addToFavorites(long bookId) {
|
||||
protected void addToFavorites(long bookId) {
|
||||
if (myAddToFavoritesStatement == null) {
|
||||
myAddToFavoritesStatement = myDatabase.compileStatement(
|
||||
"INSERT OR IGNORE INTO Favorites(book_id) VALUES (?)"
|
||||
|
@ -702,7 +721,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}
|
||||
|
||||
private SQLiteStatement myRemoveFromFavoritesStatement;
|
||||
public /*protected*/ void removeFromFavorites(long bookId) {
|
||||
protected void removeFromFavorites(long bookId) {
|
||||
if (myRemoveFromFavoritesStatement == null) {
|
||||
myRemoveFromFavoritesStatement = myDatabase.compileStatement(
|
||||
"DELETE FROM Favorites WHERE book_id = ?"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue