mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
Library uses BookCollection for some operations
This commit is contained in:
parent
bf4bbb2eac
commit
7f6442827e
3 changed files with 10 additions and 37 deletions
|
@ -712,7 +712,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
myRemoveFromFavoritesStatement.execute();
|
||||
}
|
||||
|
||||
public /*protected*/ List<Long> loadFavoriteIds() {
|
||||
protected List<Long> loadFavoriteIds() {
|
||||
final Cursor cursor = myDatabase.rawQuery(
|
||||
"SELECT book_id FROM Favorites", null
|
||||
);
|
||||
|
|
|
@ -88,7 +88,7 @@ public abstract class BooksDatabase {
|
|||
public /*protected*/ abstract List<Long> loadRecentBookIds();
|
||||
public /*protected*/ abstract void saveRecentBookIds(final List<Long> ids);
|
||||
|
||||
public /*protected*/ abstract List<Long> loadFavoriteIds();
|
||||
protected abstract List<Long> loadFavoriteIds();
|
||||
public /*protected*/ abstract void addToFavorites(long bookId);
|
||||
public /*protected*/ abstract void removeFromFavorites(long bookId);
|
||||
|
||||
|
|
|
@ -110,8 +110,8 @@ public final class Library {
|
|||
}
|
||||
|
||||
public Library(BooksDatabase db) {
|
||||
Collection = null;
|
||||
myDatabase = db;
|
||||
Collection = new BookCollection(db);
|
||||
|
||||
new FavoritesTree(myRootTree, ROOT_FAVORITES);
|
||||
new FirstLevelTree(myRootTree, ROOT_RECENT);
|
||||
|
@ -356,30 +356,12 @@ public final class Library {
|
|||
myDoGroupTitlesByFirstLetter = savedBooksByFileId.values().size() > letterSet.size() * 5 / 4;
|
||||
}
|
||||
|
||||
for (long id : myDatabase.loadRecentBookIds()) {
|
||||
Book book = savedBooksByBookId.get(id);
|
||||
if (book == null) {
|
||||
book = Book.getById(id);
|
||||
if (book != null && !book.File.exists()) {
|
||||
book = null;
|
||||
}
|
||||
}
|
||||
if (book != null) {
|
||||
new BookTree(getFirstLevelTree(ROOT_RECENT), book, true);
|
||||
}
|
||||
for (Book book : Collection.recentBooks()) {
|
||||
new BookTree(getFirstLevelTree(ROOT_RECENT), book, true);
|
||||
}
|
||||
|
||||
for (long id : myDatabase.loadFavoriteIds()) {
|
||||
Book book = savedBooksByBookId.get(id);
|
||||
if (book == null) {
|
||||
book = Book.getById(id);
|
||||
if (book != null && !book.File.exists()) {
|
||||
book = null;
|
||||
}
|
||||
}
|
||||
if (book != null) {
|
||||
getFirstLevelTree(ROOT_FAVORITES).getBookSubTree(book, true);
|
||||
}
|
||||
for (Book book : Collection.favorites()) {
|
||||
getFirstLevelTree(ROOT_FAVORITES).getBookSubTree(book, true);
|
||||
}
|
||||
|
||||
fireModelChangedEvent(ChangeListener.Code.BookAdded);
|
||||
|
@ -504,13 +486,11 @@ public final class Library {
|
|||
}
|
||||
|
||||
public Book getRecentBook() {
|
||||
List<Long> recentIds = myDatabase.loadRecentBookIds();
|
||||
return recentIds.size() > 0 ? Book.getById(recentIds.get(0)) : null;
|
||||
return Collection.getRecentBook(0);
|
||||
}
|
||||
|
||||
public Book getPreviousBook() {
|
||||
List<Long> recentIds = myDatabase.loadRecentBookIds();
|
||||
return recentIds.size() > 1 ? Book.getById(recentIds.get(1)) : null;
|
||||
return Collection.getRecentBook(1);
|
||||
}
|
||||
|
||||
public void startBookSearch(final String pattern) {
|
||||
|
@ -568,14 +548,7 @@ public final class Library {
|
|||
}
|
||||
|
||||
public void addBookToRecentList(Book book) {
|
||||
final List<Long> ids = myDatabase.loadRecentBookIds();
|
||||
final Long bookId = book.getId();
|
||||
ids.remove(bookId);
|
||||
ids.add(0, bookId);
|
||||
if (ids.size() > 12) {
|
||||
ids.remove(12);
|
||||
}
|
||||
myDatabase.saveRecentBookIds(ids);
|
||||
Collection.addBookToRecentList(book);
|
||||
}
|
||||
|
||||
public boolean isBookInFavorites(Book book) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue