mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
fixed: recent and favorites lists in Library
This commit is contained in:
parent
0db3957988
commit
554539940c
5 changed files with 28 additions and 30 deletions
|
@ -1,6 +1,4 @@
|
||||||
restore:
|
restore:
|
||||||
* recent list
|
|
||||||
* favorites list
|
|
||||||
* group titles by first letter
|
* group titles by first letter
|
||||||
|
|
||||||
new:
|
new:
|
||||||
|
|
|
@ -709,7 +709,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
myRemoveFromFavoritesStatement.execute();
|
myRemoveFromFavoritesStatement.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Long> loadFavoritesIds() {
|
protected List<Long> loadFavoriteIds() {
|
||||||
final Cursor cursor = myDatabase.rawQuery(
|
final Cursor cursor = myDatabase.rawQuery(
|
||||||
"SELECT book_id FROM Favorites", null
|
"SELECT book_id FROM Favorites", null
|
||||||
);
|
);
|
||||||
|
|
|
@ -165,6 +165,25 @@ public class BookCollection implements IBookCollection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Book> recentBooks() {
|
||||||
|
return books(myDatabase.loadRecentBookIds());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Book> favorites() {
|
||||||
|
return books(myDatabase.loadFavoriteIds());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Book> books(List<Long> ids) {
|
||||||
|
final List<Book> bookList = new ArrayList<Book>(ids.size());
|
||||||
|
for (long id : ids) {
|
||||||
|
final Book book = getBookById(id);
|
||||||
|
if (book != null) {
|
||||||
|
bookList.add(book);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bookList;
|
||||||
|
}
|
||||||
|
|
||||||
public Book getRecentBook(int index) {
|
public Book getRecentBook(int index) {
|
||||||
List<Long> recentIds = myDatabase.loadRecentBookIds();
|
List<Long> recentIds = myDatabase.loadRecentBookIds();
|
||||||
return recentIds.size() > index ? getBookById(recentIds.get(index)) : null;
|
return recentIds.size() > index ? getBookById(recentIds.get(index)) : null;
|
||||||
|
@ -224,8 +243,7 @@ public class BookCollection implements IBookCollection {
|
||||||
savedBooksByBookId.put(b.getId(), b);
|
savedBooksByBookId.put(b.getId(), b);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 1: set myDoGroupTitlesByFirstLetter value,
|
// Step 1: set myDoGroupTitlesByFirstLetter value
|
||||||
// add "existing" books into recent and favorites lists
|
|
||||||
//if (savedBooksByFileId.size() > 10) {
|
//if (savedBooksByFileId.size() > 10) {
|
||||||
// final HashSet<String> letterSet = new HashSet<String>();
|
// final HashSet<String> letterSet = new HashSet<String>();
|
||||||
// for (Book book : savedBooksByFileId.values()) {
|
// for (Book book : savedBooksByFileId.values()) {
|
||||||
|
@ -237,30 +255,6 @@ public class BookCollection implements IBookCollection {
|
||||||
// myDoGroupTitlesByFirstLetter = savedBooksByFileId.values().size() > letterSet.size() * 5 / 4;
|
// myDoGroupTitlesByFirstLetter = savedBooksByFileId.values().size() > letterSet.size() * 5 / 4;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
for (long id : myDatabase.loadRecentBookIds()) {
|
|
||||||
final Book book = savedBooksByBookId.get(id);
|
|
||||||
if (book != null) {
|
|
||||||
addBook(book);
|
|
||||||
} else {
|
|
||||||
getBookById(id);
|
|
||||||
}
|
|
||||||
//if (book != null) {
|
|
||||||
// new BookTree(getFirstLevelTree(ROOT_RECENT), book, true);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (long id : myDatabase.loadFavoritesIds()) {
|
|
||||||
final Book book = savedBooksByBookId.get(id);
|
|
||||||
if (book != null) {
|
|
||||||
addBook(book);
|
|
||||||
} else {
|
|
||||||
getBookById(id);
|
|
||||||
}
|
|
||||||
//if (book != null) {
|
|
||||||
// getFirstLevelTree(ROOT_FAVORITES).getBookSubTree(book, true);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 2: check if files corresponding to "existing" books really exists;
|
// Step 2: check if files corresponding to "existing" books really exists;
|
||||||
// add books to library if yes (and reload book info if needed);
|
// add books to library if yes (and reload book info if needed);
|
||||||
// remove from recent/favorites list if no;
|
// remove from recent/favorites list if no;
|
||||||
|
|
|
@ -86,7 +86,7 @@ public abstract class BooksDatabase {
|
||||||
protected abstract List<Long> loadRecentBookIds();
|
protected abstract List<Long> loadRecentBookIds();
|
||||||
protected abstract void saveRecentBookIds(final List<Long> ids);
|
protected abstract void saveRecentBookIds(final List<Long> ids);
|
||||||
|
|
||||||
protected abstract List<Long> loadFavoritesIds();
|
protected abstract List<Long> loadFavoriteIds();
|
||||||
protected abstract void addToFavorites(long bookId);
|
protected abstract void addToFavorites(long bookId);
|
||||||
protected abstract void removeFromFavorites(long bookId);
|
protected abstract void removeFromFavorites(long bookId);
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,12 @@ public final class Library {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case Started:
|
case Started:
|
||||||
Library.this.fireModelChangedEvent(ChangeListener.Code.StatusChanged);
|
Library.this.fireModelChangedEvent(ChangeListener.Code.StatusChanged);
|
||||||
|
for (Book book : myCollection.recentBooks()) {
|
||||||
|
new BookTree(getFirstLevelTree(ROOT_RECENT), book, true);
|
||||||
|
}
|
||||||
|
for (Book book : myCollection.favorites()) {
|
||||||
|
new BookTree(getFirstLevelTree(ROOT_FAVORITES), book, true);
|
||||||
|
}
|
||||||
setStatus(myStatusMask | STATUS_LOADING);
|
setStatus(myStatusMask | STATUS_LOADING);
|
||||||
break;
|
break;
|
||||||
case Completed:
|
case Completed:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue