1
0
Fork 0
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:
Nikolay Pultsin 2013-04-22 16:53:03 +02:00
parent 7808a7e105
commit be2c7a90a6
6 changed files with 79 additions and 5 deletions

View file

@ -222,7 +222,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
"SELECT book_id,author_id FROM BookAuthor ORDER BY author_index", null "SELECT book_id,author_id FROM BookAuthor ORDER BY author_index", null
); );
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
Book book = booksById.get(cursor.getLong(0)); final Book book = booksById.get(cursor.getLong(0));
if (book != null) { if (book != null) {
Author author = authorById.get(cursor.getLong(1)); Author author = authorById.get(cursor.getLong(1));
if (author != null) { if (author != null) {
@ -234,7 +234,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
cursor = myDatabase.rawQuery("SELECT book_id,tag_id FROM BookTag", null); cursor = myDatabase.rawQuery("SELECT book_id,tag_id FROM BookTag", null);
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
Book book = booksById.get(cursor.getLong(0)); final Book book = booksById.get(cursor.getLong(0));
if (book != null) { if (book != null) {
addTag(book, getTagById(cursor.getLong(1))); 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 "SELECT book_id,series_id,book_index FROM BookSeries", null
); );
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
Book book = booksById.get(cursor.getLong(0)); final Book book = booksById.get(cursor.getLong(0));
if (book != null) { if (book != null) {
final String series = seriesById.get(cursor.getLong(1)); final String series = seriesById.get(cursor.getLong(1));
if (series != null) { if (series != null) {
@ -263,6 +263,43 @@ final class SQLiteBooksDatabase extends BooksDatabase {
} }
} }
cursor.close(); 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; return booksByFileId;
} }
@ -781,6 +818,17 @@ final class SQLiteBooksDatabase extends BooksDatabase {
myRemoveLabelStatement.execute(); 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 @Override
protected List<Bookmark> loadBookmarks(BookmarkQuery query) { protected List<Bookmark> loadBookmarks(BookmarkQuery query) {
final LinkedList<Bookmark> list = new LinkedList<Bookmark>(); final LinkedList<Bookmark> list = new LinkedList<Bookmark>();

View file

@ -50,6 +50,8 @@ public class Book extends TitledEntity {
private volatile SeriesInfo mySeriesInfo; private volatile SeriesInfo mySeriesInfo;
private volatile List<UID> myUids; private volatile List<UID> myUids;
public volatile boolean HasBookmark;
private volatile boolean myIsSaved; private volatile boolean myIsSaved;
private static final WeakReference<ZLImage> NULL_IMAGE = new WeakReference<ZLImage>(null); private static final WeakReference<ZLImage> NULL_IMAGE = new WeakReference<ZLImage>(null);
@ -146,6 +148,8 @@ public class Book extends TitledEntity {
myLabels = database.listLabels(myId); myLabels = database.listLabels(myId);
mySeriesInfo = database.getSeriesInfo(myId); mySeriesInfo = database.getSeriesInfo(myId);
myUids = database.listUids(myId); myUids = database.listUids(myId);
HasBookmark = database.hasVisibleBookmark(myId);
System.err.println(myId + ": " + getTitle() + " :: " + HasBookmark);
myIsSaved = true; myIsSaved = true;
if (myUids == null || myUids.isEmpty()) { if (myUids == null || myUids.isEmpty()) {
try { try {

View file

@ -612,12 +612,24 @@ public class BookCollection extends AbstractBookCollection {
public void saveBookmark(Bookmark bookmark) { public void saveBookmark(Bookmark bookmark) {
if (bookmark != null) { if (bookmark != null) {
bookmark.setId(myDatabase.saveBookmark(bookmark)); 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) { public void deleteBookmark(Bookmark bookmark) {
if (bookmark != null && bookmark.getId() != -1) { if (bookmark != null && bookmark.getId() != -1) {
myDatabase.deleteBookmark(bookmark); myDatabase.deleteBookmark(bookmark);
if (bookmark.IsVisible) {
final Book book = getBookById(bookmark.getBookId());
if (book != null) {
book.HasBookmark = myDatabase.hasVisibleBookmark(bookmark.getBookId());
}
}
} }
} }

View file

@ -56,6 +56,7 @@ public abstract class BooksDatabase {
protected abstract List<String> listLabels(long bookId); protected abstract List<String> listLabels(long bookId);
protected abstract SeriesInfo getSeriesInfo(long bookId); protected abstract SeriesInfo getSeriesInfo(long bookId);
protected abstract List<UID> listUids(long bookId); protected abstract List<UID> listUids(long bookId);
protected abstract boolean hasVisibleBookmark(long bookId);
protected abstract Long bookIdByUid(UID uid); protected abstract Long bookIdByUid(UID uid);

View file

@ -109,8 +109,7 @@ public abstract class Filter {
public final static class HasBookmark extends Filter { public final static class HasBookmark extends Filter {
public boolean matches(Book book) { public boolean matches(Book book) {
// TODO: implement return book != null && book.HasBookmark;
return true;
} }
} }

View file

@ -208,6 +208,11 @@ class XMLSerializer extends AbstractSerializer {
appendTagWithContent(buffer, "calibre:series_index", seriesInfo.Index); appendTagWithContent(buffer, "calibre:series_index", seriesInfo.Index);
} }
} }
if (book.HasBookmark) {
appendTag(buffer, "has-bookmark", true);
}
// TODO: serialize description (?) // TODO: serialize description (?)
// TODO: serialize cover (?) // TODO: serialize cover (?)
@ -382,6 +387,7 @@ class XMLSerializer extends AbstractSerializer {
private final StringBuilder myAuthorName = new StringBuilder(); private final StringBuilder myAuthorName = new StringBuilder();
private final StringBuilder mySeriesTitle = new StringBuilder(); private final StringBuilder mySeriesTitle = new StringBuilder();
private final StringBuilder mySeriesIndex = new StringBuilder(); private final StringBuilder mySeriesIndex = new StringBuilder();
private boolean myHasBookmark;
private Book myBook; private Book myBook;
@ -405,6 +411,7 @@ class XMLSerializer extends AbstractSerializer {
myAuthors.clear(); myAuthors.clear();
myTags.clear(); myTags.clear();
myLabels.clear(); myLabels.clear();
myHasBookmark = false;
myState = State.READ_NOTHING; myState = State.READ_NOTHING;
} }
@ -434,6 +441,7 @@ class XMLSerializer extends AbstractSerializer {
myBook.addUid(uid); myBook.addUid(uid);
} }
myBook.setSeriesInfoWithNoCheck(string(mySeriesTitle), string(mySeriesIndex)); myBook.setSeriesInfoWithNoCheck(string(mySeriesTitle), string(mySeriesIndex));
myBook.HasBookmark = myHasBookmark;
} }
@Override @Override
@ -475,6 +483,8 @@ class XMLSerializer extends AbstractSerializer {
myState = State.READ_SERIES_TITLE; myState = State.READ_SERIES_TITLE;
} else if ("series_index".equals(localName) && XMLNamespaces.CalibreMetadata.equals(uri)) { } else if ("series_index".equals(localName) && XMLNamespaces.CalibreMetadata.equals(uri)) {
myState = State.READ_SERIES_INDEX; myState = State.READ_SERIES_INDEX;
} else if ("has-bookmark".equals(localName)) {
myHasBookmark = true;
} else if ("link".equals(localName)) { } else if ("link".equals(localName)) {
// TODO: use "rel" attribute // TODO: use "rel" attribute
myUrl = attributes.getValue("href"); myUrl = attributes.getValue("href");