mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
Filter.HasBookmark + fixed book loading
This commit is contained in:
parent
7808a7e105
commit
be2c7a90a6
6 changed files with 79 additions and 5 deletions
|
@ -222,7 +222,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
"SELECT book_id,author_id FROM BookAuthor ORDER BY author_index", null
|
||||
);
|
||||
while (cursor.moveToNext()) {
|
||||
Book book = booksById.get(cursor.getLong(0));
|
||||
final Book book = booksById.get(cursor.getLong(0));
|
||||
if (book != null) {
|
||||
Author author = authorById.get(cursor.getLong(1));
|
||||
if (author != null) {
|
||||
|
@ -234,7 +234,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
|
||||
cursor = myDatabase.rawQuery("SELECT book_id,tag_id FROM BookTag", null);
|
||||
while (cursor.moveToNext()) {
|
||||
Book book = booksById.get(cursor.getLong(0));
|
||||
final Book book = booksById.get(cursor.getLong(0));
|
||||
if (book != null) {
|
||||
addTag(book, getTagById(cursor.getLong(1)));
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
"SELECT book_id,series_id,book_index FROM BookSeries", null
|
||||
);
|
||||
while (cursor.moveToNext()) {
|
||||
Book book = booksById.get(cursor.getLong(0));
|
||||
final Book book = booksById.get(cursor.getLong(0));
|
||||
if (book != null) {
|
||||
final String series = seriesById.get(cursor.getLong(1));
|
||||
if (series != null) {
|
||||
|
@ -263,6 +263,43 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
cursor = myDatabase.rawQuery(
|
||||
"SELECT book_id,type,uid FROM BookUid", null
|
||||
);
|
||||
while (cursor.moveToNext()) {
|
||||
final Book book = booksById.get(cursor.getLong(0));
|
||||
if (book != null) {
|
||||
book.addUid(cursor.getString(1), cursor.getString(2));
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
cursor = myDatabase.rawQuery(
|
||||
"SELECT BookLabel.book_id,Labels.name FROM Labels" +
|
||||
" INNER JOIN BookLabel ON BookLabel.label_id=Labels.label_id",
|
||||
null
|
||||
);
|
||||
while (cursor.moveToNext()) {
|
||||
final Book book = booksById.get(cursor.getLong(0));
|
||||
if (book != null) {
|
||||
book.addLabel(cursor.getString(1));
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
cursor = myDatabase.rawQuery(
|
||||
"SELECT book_id FROM Bookmarks WHERE visible = 1 GROUP by book_id",
|
||||
null
|
||||
);
|
||||
while (cursor.moveToNext()) {
|
||||
final Book book = booksById.get(cursor.getLong(0));
|
||||
if (book != null) {
|
||||
book.HasBookmark = true;
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
return booksByFileId;
|
||||
}
|
||||
|
||||
|
@ -781,6 +818,17 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
myRemoveLabelStatement.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasVisibleBookmark(long bookId) {
|
||||
final Cursor cursor = myDatabase.rawQuery(
|
||||
"SELECT bookmark_id FROM Bookmarks WHERE book_id = " + bookId +
|
||||
" AND visible = 1 LIMIT 1", null
|
||||
);
|
||||
final boolean result = cursor.moveToNext();
|
||||
cursor.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Bookmark> loadBookmarks(BookmarkQuery query) {
|
||||
final LinkedList<Bookmark> list = new LinkedList<Bookmark>();
|
||||
|
|
|
@ -50,6 +50,8 @@ public class Book extends TitledEntity {
|
|||
private volatile SeriesInfo mySeriesInfo;
|
||||
private volatile List<UID> myUids;
|
||||
|
||||
public volatile boolean HasBookmark;
|
||||
|
||||
private volatile boolean myIsSaved;
|
||||
|
||||
private static final WeakReference<ZLImage> NULL_IMAGE = new WeakReference<ZLImage>(null);
|
||||
|
@ -146,6 +148,8 @@ public class Book extends TitledEntity {
|
|||
myLabels = database.listLabels(myId);
|
||||
mySeriesInfo = database.getSeriesInfo(myId);
|
||||
myUids = database.listUids(myId);
|
||||
HasBookmark = database.hasVisibleBookmark(myId);
|
||||
System.err.println(myId + ": " + getTitle() + " :: " + HasBookmark);
|
||||
myIsSaved = true;
|
||||
if (myUids == null || myUids.isEmpty()) {
|
||||
try {
|
||||
|
|
|
@ -612,12 +612,24 @@ public class BookCollection extends AbstractBookCollection {
|
|||
public void saveBookmark(Bookmark bookmark) {
|
||||
if (bookmark != null) {
|
||||
bookmark.setId(myDatabase.saveBookmark(bookmark));
|
||||
if (bookmark.IsVisible) {
|
||||
final Book book = getBookById(bookmark.getBookId());
|
||||
if (book != null) {
|
||||
book.HasBookmark = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteBookmark(Bookmark bookmark) {
|
||||
if (bookmark != null && bookmark.getId() != -1) {
|
||||
myDatabase.deleteBookmark(bookmark);
|
||||
if (bookmark.IsVisible) {
|
||||
final Book book = getBookById(bookmark.getBookId());
|
||||
if (book != null) {
|
||||
book.HasBookmark = myDatabase.hasVisibleBookmark(bookmark.getBookId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ public abstract class BooksDatabase {
|
|||
protected abstract List<String> listLabels(long bookId);
|
||||
protected abstract SeriesInfo getSeriesInfo(long bookId);
|
||||
protected abstract List<UID> listUids(long bookId);
|
||||
protected abstract boolean hasVisibleBookmark(long bookId);
|
||||
|
||||
protected abstract Long bookIdByUid(UID uid);
|
||||
|
||||
|
|
|
@ -109,8 +109,7 @@ public abstract class Filter {
|
|||
|
||||
public final static class HasBookmark extends Filter {
|
||||
public boolean matches(Book book) {
|
||||
// TODO: implement
|
||||
return true;
|
||||
return book != null && book.HasBookmark;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -208,6 +208,11 @@ class XMLSerializer extends AbstractSerializer {
|
|||
appendTagWithContent(buffer, "calibre:series_index", seriesInfo.Index);
|
||||
}
|
||||
}
|
||||
|
||||
if (book.HasBookmark) {
|
||||
appendTag(buffer, "has-bookmark", true);
|
||||
}
|
||||
|
||||
// TODO: serialize description (?)
|
||||
// TODO: serialize cover (?)
|
||||
|
||||
|
@ -382,6 +387,7 @@ class XMLSerializer extends AbstractSerializer {
|
|||
private final StringBuilder myAuthorName = new StringBuilder();
|
||||
private final StringBuilder mySeriesTitle = new StringBuilder();
|
||||
private final StringBuilder mySeriesIndex = new StringBuilder();
|
||||
private boolean myHasBookmark;
|
||||
|
||||
private Book myBook;
|
||||
|
||||
|
@ -405,6 +411,7 @@ class XMLSerializer extends AbstractSerializer {
|
|||
myAuthors.clear();
|
||||
myTags.clear();
|
||||
myLabels.clear();
|
||||
myHasBookmark = false;
|
||||
|
||||
myState = State.READ_NOTHING;
|
||||
}
|
||||
|
@ -434,6 +441,7 @@ class XMLSerializer extends AbstractSerializer {
|
|||
myBook.addUid(uid);
|
||||
}
|
||||
myBook.setSeriesInfoWithNoCheck(string(mySeriesTitle), string(mySeriesIndex));
|
||||
myBook.HasBookmark = myHasBookmark;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -475,6 +483,8 @@ class XMLSerializer extends AbstractSerializer {
|
|||
myState = State.READ_SERIES_TITLE;
|
||||
} else if ("series_index".equals(localName) && XMLNamespaces.CalibreMetadata.equals(uri)) {
|
||||
myState = State.READ_SERIES_INDEX;
|
||||
} else if ("has-bookmark".equals(localName)) {
|
||||
myHasBookmark = true;
|
||||
} else if ("link".equals(localName)) {
|
||||
// TODO: use "rel" attribute
|
||||
myUrl = attributes.getValue("href");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue