From a235ea9a9bba8a189fd873d3618b4928f1e4e6ae Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Fri, 1 Feb 2013 20:05:58 +0000 Subject: [PATCH] synchronization with library-service branch --- .../fbreader/library/FavoritesTree.java | 8 +++- .../fbreader/library/Library.java | 8 +--- .../fbreader/library/RecentBooksTree.java | 45 +++++++++++++++++++ 3 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 src/org/geometerplus/fbreader/library/RecentBooksTree.java diff --git a/src/org/geometerplus/fbreader/library/FavoritesTree.java b/src/org/geometerplus/fbreader/library/FavoritesTree.java index c7ed19d20..a862bde1d 100644 --- a/src/org/geometerplus/fbreader/library/FavoritesTree.java +++ b/src/org/geometerplus/fbreader/library/FavoritesTree.java @@ -19,9 +19,15 @@ package org.geometerplus.fbreader.library; +import org.geometerplus.fbreader.book.Book; +import org.geometerplus.fbreader.book.IBookCollection; + public class FavoritesTree extends FirstLevelTree { - FavoritesTree(RootTree root, String id) { + private final IBookCollection myCollection; + + FavoritesTree(IBookCollection collection, RootTree root, String id) { super(root, id); + myCollection = collection; } @Override diff --git a/src/org/geometerplus/fbreader/library/Library.java b/src/org/geometerplus/fbreader/library/Library.java index a987aebc8..759faa6cc 100644 --- a/src/org/geometerplus/fbreader/library/Library.java +++ b/src/org/geometerplus/fbreader/library/Library.java @@ -113,8 +113,8 @@ public final class Library { myDatabase = db; Collection = new BookCollection(db); - new FavoritesTree(myRootTree, ROOT_FAVORITES); - new FirstLevelTree(myRootTree, ROOT_RECENT); + new FavoritesTree(Collection, myRootTree, ROOT_FAVORITES); + new RecentBooksTree(Collection, myRootTree, ROOT_RECENT); new FirstLevelTree(myRootTree, ROOT_BY_AUTHOR); new FirstLevelTree(myRootTree, ROOT_BY_TITLE); new FirstLevelTree(myRootTree, ROOT_BY_TAG); @@ -356,10 +356,6 @@ public final class Library { myDoGroupTitlesByFirstLetter = savedBooksByFileId.values().size() > letterSet.size() * 5 / 4; } - for (Book book : Collection.recentBooks()) { - new BookTree(getFirstLevelTree(ROOT_RECENT), book, true); - } - for (Book book : Collection.favorites()) { getFirstLevelTree(ROOT_FAVORITES).getBookSubTree(book, true); } diff --git a/src/org/geometerplus/fbreader/library/RecentBooksTree.java b/src/org/geometerplus/fbreader/library/RecentBooksTree.java new file mode 100644 index 000000000..13e5bf31f --- /dev/null +++ b/src/org/geometerplus/fbreader/library/RecentBooksTree.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2009-2013 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +package org.geometerplus.fbreader.library; + +import org.geometerplus.fbreader.book.Book; +import org.geometerplus.fbreader.book.IBookCollection; + +public class RecentBooksTree extends FirstLevelTree { + private final IBookCollection myCollection; + + RecentBooksTree(IBookCollection collection, RootTree root, String id) { + super(root, id); + myCollection = collection; + } + + @Override + public Status getOpeningStatus() { + return Status.ALWAYS_RELOAD_BEFORE_OPENING; + } + + @Override + public void waitForOpening() { + clear(); + for (Book book : myCollection.recentBooks()) { + new BookTree(this, book, true); + } + } +}