1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 10:19:33 +02:00

synchronization with library-service branch + constants are moved from Library to LibraryTree

This commit is contained in:
Nikolay Pultsin 2013-02-07 15:01:46 +00:00
parent 5f6a41fb3a
commit a46e23e78e
17 changed files with 100 additions and 94 deletions

View file

@ -99,7 +99,11 @@
</activity> </activity>
<activity android:name="org.geometerplus.android.fbreader.CancelActivity" android:theme="@style/FBReader.Dialog"/> <activity android:name="org.geometerplus.android.fbreader.CancelActivity" android:theme="@style/FBReader.Dialog"/>
<activity android:name="org.geometerplus.android.fbreader.image.ImageViewActivity" android:process=":imageView" android:theme="@style/FBReader.Activity"/> <activity android:name="org.geometerplus.android.fbreader.image.ImageViewActivity" android:process=":imageView" android:theme="@style/FBReader.Activity"/>
<service android:name="org.geometerplus.android.fbreader.libraryService.LibraryService" android:launchMode="singleTask" android:process=":libraryService"/> <service android:name="org.geometerplus.android.fbreader.libraryService.LibraryService" android:launchMode="singleTask" android:process=":libraryService">
<intent-filter>
<action android:name="android.fbreader.action.LIBRARY_SERVICE"/>
</intent-filter>
</service>
<activity android:name="org.geometerplus.android.fbreader.library.BookInfoActivity" android:theme="@style/FBReader.Activity" android:process=":library"/> <activity android:name="org.geometerplus.android.fbreader.library.BookInfoActivity" android:theme="@style/FBReader.Activity" android:process=":library"/>
<receiver android:name="org.geometerplus.android.fbreader.library.KillerCallback" android:process=":library"/> <receiver android:name="org.geometerplus.android.fbreader.library.KillerCallback" android:process=":library"/>
<activity android:name="org.geometerplus.android.fbreader.library.LibrarySearchActivity" android:process=":library" android:theme="@android:style/Theme.NoDisplay"> <activity android:name="org.geometerplus.android.fbreader.library.LibrarySearchActivity" android:process=":library" android:theme="@android:style/Theme.NoDisplay">

View file

@ -99,7 +99,11 @@
</activity> </activity>
<activity android:name="org.geometerplus.android.fbreader.CancelActivity" android:theme="@style/FBReader.Dialog"/> <activity android:name="org.geometerplus.android.fbreader.CancelActivity" android:theme="@style/FBReader.Dialog"/>
<activity android:name="org.geometerplus.android.fbreader.image.ImageViewActivity" android:process=":imageView" android:theme="@style/FBReader.Activity"/> <activity android:name="org.geometerplus.android.fbreader.image.ImageViewActivity" android:process=":imageView" android:theme="@style/FBReader.Activity"/>
<service android:name="org.geometerplus.android.fbreader.libraryService.LibraryService" android:launchMode="singleTask" android:process=":libraryService"/> <service android:name="org.geometerplus.android.fbreader.libraryService.LibraryService" android:launchMode="singleTask" android:process=":libraryService">
<intent-filter>
<action android:name="android.fbreader.action.LIBRARY_SERVICE"/>
</intent-filter>
</service>
<activity android:name="org.geometerplus.android.fbreader.library.BookInfoActivity" android:theme="@style/FBReader.Activity" android:process=":library"/> <activity android:name="org.geometerplus.android.fbreader.library.BookInfoActivity" android:theme="@style/FBReader.Activity" android:process=":library"/>
<receiver android:name="org.geometerplus.android.fbreader.library.KillerCallback" android:process=":library"/> <receiver android:name="org.geometerplus.android.fbreader.library.KillerCallback" android:process=":library"/>
<activity android:name="org.geometerplus.android.fbreader.library.LibrarySearchActivity" android:process=":library" android:theme="@android:style/Theme.NoDisplay"> <activity android:name="org.geometerplus.android.fbreader.library.LibrarySearchActivity" android:process=":library" android:theme="@android:style/Theme.NoDisplay">

View file

@ -149,7 +149,7 @@ public class LibraryActivity extends TreeActivity<LibraryTree> implements MenuIt
new ZLStringOption("BookSearch", "Pattern", ""); new ZLStringOption("BookSearch", "Pattern", "");
private void openSearchResults() { private void openSearchResults() {
final FBTree tree = myLibrary.getRootTree().getSubTree(Library.ROOT_FOUND); final FBTree tree = myLibrary.getRootTree().getSubTree(LibraryTree.ROOT_FOUND);
if (tree != null) { if (tree != null) {
openTree(tree); openTree(tree);
} }

View file

@ -77,19 +77,19 @@ class LibraryTreeAdapter extends TreeAdapter {
return R.drawable.ic_list_library_book; return R.drawable.ic_list_library_book;
} else if (tree instanceof FirstLevelTree) { } else if (tree instanceof FirstLevelTree) {
final String id = tree.getUniqueKey().Id; final String id = tree.getUniqueKey().Id;
if (Library.ROOT_FAVORITES.equals(id)) { if (LibraryTree.ROOT_FAVORITES.equals(id)) {
return R.drawable.ic_list_library_favorites; return R.drawable.ic_list_library_favorites;
} else if (Library.ROOT_RECENT.equals(id)) { } else if (LibraryTree.ROOT_RECENT.equals(id)) {
return R.drawable.ic_list_library_recent; return R.drawable.ic_list_library_recent;
} else if (Library.ROOT_BY_AUTHOR.equals(id)) { } else if (LibraryTree.ROOT_BY_AUTHOR.equals(id)) {
return R.drawable.ic_list_library_authors; return R.drawable.ic_list_library_authors;
} else if (Library.ROOT_BY_TITLE.equals(id)) { } else if (LibraryTree.ROOT_BY_TITLE.equals(id)) {
return R.drawable.ic_list_library_books; return R.drawable.ic_list_library_books;
} else if (Library.ROOT_BY_TAG.equals(id)) { } else if (LibraryTree.ROOT_BY_TAG.equals(id)) {
return R.drawable.ic_list_library_tags; return R.drawable.ic_list_library_tags;
} else if (Library.ROOT_FILE_TREE.equals(id)) { } else if (LibraryTree.ROOT_FILE_TREE.equals(id)) {
return R.drawable.ic_list_library_folder; return R.drawable.ic_list_library_folder;
} else if (Library.ROOT_FOUND.equals(id)) { } else if (LibraryTree.ROOT_FOUND.equals(id)) {
return R.drawable.ic_list_library_search; return R.drawable.ic_list_library_search;
} }
} else if (tree instanceof FileTree) { } else if (tree instanceof FileTree) {

View file

@ -19,13 +19,13 @@
package org.geometerplus.fbreader.library; package org.geometerplus.fbreader.library;
import org.geometerplus.fbreader.book.Author; import org.geometerplus.fbreader.book.*;
import org.geometerplus.fbreader.book.Book;
public class AuthorTree extends LibraryTree { public class AuthorTree extends LibraryTree {
public final Author Author; public final Author Author;
AuthorTree(Author author) { AuthorTree(IBookCollection collection, Author author) {
super(collection);
Author = author; Author = author;
} }

View file

@ -22,11 +22,12 @@ package org.geometerplus.fbreader.library;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.geometerplus.fbreader.book.Book; import org.geometerplus.fbreader.book.Book;
import org.geometerplus.fbreader.book.IBookCollection;
import org.geometerplus.fbreader.tree.FBTree; import org.geometerplus.fbreader.tree.FBTree;
public final class BookInSeriesTree extends BookTree { public final class BookInSeriesTree extends BookTree {
BookInSeriesTree(Book book) { BookInSeriesTree(IBookCollection collection, Book book) {
super(book, false); super(collection, book, false);
} }
BookInSeriesTree(LibraryTree parent, Book book, int position) { BookInSeriesTree(LibraryTree parent, Book book, int position) {

View file

@ -28,7 +28,8 @@ public class BookTree extends LibraryTree {
public final Book Book; public final Book Book;
private final boolean myShowAuthors; private final boolean myShowAuthors;
BookTree(Book book, boolean showAuthors) { BookTree(IBookCollection collection, Book book, boolean showAuthors) {
super(collection);
Book = book; Book = book;
myShowAuthors = showAuthors; myShowAuthors = showAuthors;
} }

View file

@ -23,11 +23,8 @@ import org.geometerplus.fbreader.book.Book;
import org.geometerplus.fbreader.book.IBookCollection; import org.geometerplus.fbreader.book.IBookCollection;
public class FavoritesTree extends FirstLevelTree { public class FavoritesTree extends FirstLevelTree {
private final IBookCollection myCollection; FavoritesTree(RootTree root) {
super(root, ROOT_FAVORITES);
FavoritesTree(IBookCollection collection, RootTree root, String id) {
super(root, id);
myCollection = collection;
} }
@Override @Override

View file

@ -23,14 +23,10 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.fbreader.Paths; import org.geometerplus.fbreader.Paths;
import org.geometerplus.fbreader.book.IBookCollection;
public class FileFirstLevelTree extends FirstLevelTree { public class FileFirstLevelTree extends FirstLevelTree {
private final IBookCollection myCollection; FileFirstLevelTree(RootTree root) {
super(root, ROOT_FILE_TREE);
FileFirstLevelTree(IBookCollection collection, RootTree root, String id) {
super(root, id);
myCollection = collection;
addChild(Paths.BooksDirectoryOption().getValue(), "fileTreeLibrary"); addChild(Paths.BooksDirectoryOption().getValue(), "fileTreeLibrary");
addChild("/", "fileTreeRoot"); addChild("/", "fileTreeRoot");
addChild(Paths.cardDirectory(), "fileTreeCard"); addChild(Paths.cardDirectory(), "fileTreeCard");
@ -42,7 +38,6 @@ public class FileFirstLevelTree extends FirstLevelTree {
final ZLResource resource = Library.resource().getResource(resourceKey); final ZLResource resource = Library.resource().getResource(resourceKey);
new FileTree( new FileTree(
this, this,
myCollection,
file, file,
resource.getValue(), resource.getValue(),
resource.getResource("summary").getValue() resource.getResource("summary").getValue()

View file

@ -29,15 +29,13 @@ import org.geometerplus.fbreader.formats.PluginCollection;
import org.geometerplus.fbreader.tree.FBTree; import org.geometerplus.fbreader.tree.FBTree;
public class FileTree extends LibraryTree { public class FileTree extends LibraryTree {
private final IBookCollection myCollection;
private final ZLFile myFile; private final ZLFile myFile;
private final String myName; private final String myName;
private final String mySummary; private final String mySummary;
private final boolean myIsSelectable; private final boolean myIsSelectable;
FileTree(LibraryTree parent, IBookCollection collection, ZLFile file, String name, String summary) { FileTree(LibraryTree parent, ZLFile file, String name, String summary) {
super(parent); super(parent);
myCollection = collection;
myFile = file; myFile = file;
myName = name; myName = name;
mySummary = summary; mySummary = summary;
@ -46,7 +44,6 @@ public class FileTree extends LibraryTree {
public FileTree(FileTree parent, ZLFile file) { public FileTree(FileTree parent, ZLFile file) {
super(parent); super(parent);
myCollection = parent.myCollection;
myFile = file; myFile = file;
myName = null; myName = null;
mySummary = null; mySummary = null;

View file

@ -35,15 +35,6 @@ public final class Library {
return ZLResource.resource("library"); return ZLResource.resource("library");
} }
public static final String ROOT_FOUND = "found";
public static final String ROOT_FAVORITES = "favorites";
public static final String ROOT_RECENT = "recent";
public static final String ROOT_BY_AUTHOR = "byAuthor";
public static final String ROOT_BY_TITLE = "byTitle";
public static final String ROOT_BY_SERIES = "bySeries";
public static final String ROOT_BY_TAG = "byTag";
public static final String ROOT_FILE_TREE = "fileTree";
public static final int REMOVE_DONT_REMOVE = 0x00; public static final int REMOVE_DONT_REMOVE = 0x00;
public static final int REMOVE_FROM_LIBRARY = 0x01; public static final int REMOVE_FROM_LIBRARY = 0x01;
public static final int REMOVE_FROM_DISK = 0x02; public static final int REMOVE_FROM_DISK = 0x02;
@ -92,7 +83,7 @@ public final class Library {
private final Map<ZLFile,Book> myBooks = private final Map<ZLFile,Book> myBooks =
Collections.synchronizedMap(new HashMap<ZLFile,Book>()); Collections.synchronizedMap(new HashMap<ZLFile,Book>());
private final RootTree myRootTree = new RootTree(); private final RootTree myRootTree;
private boolean myDoGroupTitlesByFirstLetter; private boolean myDoGroupTitlesByFirstLetter;
private final static int STATUS_LOADING = 1; private final static int STATUS_LOADING = 1;
@ -113,12 +104,14 @@ public final class Library {
myDatabase = db; myDatabase = db;
Collection = new BookCollection(db); Collection = new BookCollection(db);
new FavoritesTree(Collection, myRootTree, ROOT_FAVORITES); myRootTree = new RootTree(Collection);
new RecentBooksTree(Collection, myRootTree, ROOT_RECENT);
new FirstLevelTree(myRootTree, ROOT_BY_AUTHOR); new FavoritesTree(myRootTree);
new FirstLevelTree(myRootTree, ROOT_BY_TITLE); new RecentBooksTree(myRootTree);
new FirstLevelTree(myRootTree, ROOT_BY_TAG); new FirstLevelTree(myRootTree, LibraryTree.ROOT_BY_AUTHOR);
new FileFirstLevelTree(Collection, myRootTree, ROOT_FILE_TREE); new FirstLevelTree(myRootTree, LibraryTree.ROOT_BY_TITLE);
new FirstLevelTree(myRootTree, LibraryTree.ROOT_BY_TAG);
new FileFirstLevelTree(myRootTree);
} }
public LibraryTree getRootTree() { public LibraryTree getRootTree() {
@ -235,7 +228,7 @@ public final class Library {
private LibraryTree getTagTree(Tag tag) { private LibraryTree getTagTree(Tag tag) {
if (tag == null || tag.Parent == null) { if (tag == null || tag.Parent == null) {
return getFirstLevelTree(ROOT_BY_TAG).getTagSubTree(tag); return getFirstLevelTree(LibraryTree.ROOT_BY_TAG).getTagSubTree(tag);
} else { } else {
return getTagTree(tag.Parent).getTagSubTree(tag); return getTagTree(tag.Parent).getTagSubTree(tag);
} }
@ -253,7 +246,7 @@ public final class Library {
} }
final SeriesInfo seriesInfo = book.getSeriesInfo(); final SeriesInfo seriesInfo = book.getSeriesInfo();
for (Author a : authors) { for (Author a : authors) {
final AuthorTree authorTree = getFirstLevelTree(ROOT_BY_AUTHOR).getAuthorSubTree(a); final AuthorTree authorTree = getFirstLevelTree(LibraryTree.ROOT_BY_AUTHOR).getAuthorSubTree(a);
if (seriesInfo == null) { if (seriesInfo == null) {
authorTree.getBookSubTree(book, false); authorTree.getBookSubTree(book, false);
} else { } else {
@ -262,12 +255,12 @@ public final class Library {
} }
if (seriesInfo != null) { if (seriesInfo != null) {
FirstLevelTree seriesRoot = getFirstLevelTree(ROOT_BY_SERIES); FirstLevelTree seriesRoot = getFirstLevelTree(LibraryTree.ROOT_BY_SERIES);
if (seriesRoot == null) { if (seriesRoot == null) {
seriesRoot = new FirstLevelTree( seriesRoot = new FirstLevelTree(
myRootTree, myRootTree,
myRootTree.indexOf(getFirstLevelTree(ROOT_BY_TITLE)) + 1, myRootTree.indexOf(getFirstLevelTree(LibraryTree.ROOT_BY_TITLE)) + 1,
ROOT_BY_SERIES LibraryTree.ROOT_BY_SERIES
); );
} }
seriesRoot.getSeriesSubTree(seriesInfo.Title).getBookInSeriesSubTree(book); seriesRoot.getSeriesSubTree(seriesInfo.Title).getBookInSeriesSubTree(book);
@ -277,11 +270,11 @@ public final class Library {
final String letter = TitleTree.firstTitleLetter(book); final String letter = TitleTree.firstTitleLetter(book);
if (letter != null) { if (letter != null) {
final TitleTree tree = final TitleTree tree =
getFirstLevelTree(ROOT_BY_TITLE).getTitleSubTree(letter); getFirstLevelTree(LibraryTree.ROOT_BY_TITLE).getTitleSubTree(letter);
tree.getBookSubTree(book, true); tree.getBookSubTree(book, true);
} }
} else { } else {
getFirstLevelTree(ROOT_BY_TITLE).getBookSubTree(book, true); getFirstLevelTree(LibraryTree.ROOT_BY_TITLE).getBookSubTree(book, true);
} }
List<Tag> tags = book.tags(); List<Tag> tags = book.tags();
@ -293,7 +286,7 @@ public final class Library {
} }
final SearchResultsTree found = final SearchResultsTree found =
(SearchResultsTree)getFirstLevelTree(ROOT_FOUND); (SearchResultsTree)getFirstLevelTree(LibraryTree.ROOT_FOUND);
if (found != null && book.matches(found.getPattern())) { if (found != null && book.matches(found.getPattern())) {
found.getBookSubTree(book, true); found.getBookSubTree(book, true);
} }
@ -309,7 +302,7 @@ public final class Library {
private void refreshInTree(String rootId, Book book) { private void refreshInTree(String rootId, Book book) {
final FirstLevelTree tree = getFirstLevelTree(rootId); final FirstLevelTree tree = getFirstLevelTree(rootId);
if (tree != null) { if (tree != null) {
int index = tree.indexOf(new BookTree(book, true)); int index = tree.indexOf(new BookTree(Collection, book, true));
if (index >= 0) { if (index >= 0) {
tree.removeBook(book, false); tree.removeBook(book, false);
new BookTree(tree, book, true, index); new BookTree(tree, book, true, index);
@ -323,13 +316,12 @@ public final class Library {
} }
myBooks.remove(book.File); myBooks.remove(book.File);
refreshInTree(ROOT_FAVORITES, book); refreshInTree(LibraryTree.ROOT_FAVORITES, book);
refreshInTree(ROOT_RECENT, book); removeFromTree(LibraryTree.ROOT_FOUND, book);
removeFromTree(ROOT_FOUND, book); removeFromTree(LibraryTree.ROOT_BY_TITLE, book);
removeFromTree(ROOT_BY_TITLE, book); removeFromTree(LibraryTree.ROOT_BY_SERIES, book);
removeFromTree(ROOT_BY_SERIES, book); removeFromTree(LibraryTree.ROOT_BY_AUTHOR, book);
removeFromTree(ROOT_BY_AUTHOR, book); removeFromTree(LibraryTree.ROOT_BY_TAG, book);
removeFromTree(ROOT_BY_TAG, book);
addBookToLibrary(book); addBookToLibrary(book);
fireModelChangedEvent(ChangeListener.Code.BookAdded); fireModelChangedEvent(ChangeListener.Code.BookAdded);
} }
@ -357,7 +349,7 @@ public final class Library {
} }
for (Book book : Collection.favorites()) { for (Book book : Collection.favorites()) {
getFirstLevelTree(ROOT_FAVORITES).getBookSubTree(book, true); getFirstLevelTree(LibraryTree.ROOT_FAVORITES).getBookSubTree(book, true);
} }
fireModelChangedEvent(ChangeListener.Code.BookAdded); fireModelChangedEvent(ChangeListener.Code.BookAdded);
@ -512,7 +504,7 @@ public final class Library {
pattern = pattern.toLowerCase(); pattern = pattern.toLowerCase();
final SearchResultsTree oldSearchResults = (SearchResultsTree)getFirstLevelTree(ROOT_FOUND); final SearchResultsTree oldSearchResults = (SearchResultsTree)getFirstLevelTree(LibraryTree.ROOT_FOUND);
if (oldSearchResults != null && pattern.equals(oldSearchResults.getPattern())) { if (oldSearchResults != null && pattern.equals(oldSearchResults.getPattern())) {
fireModelChangedEvent(ChangeListener.Code.Found); fireModelChangedEvent(ChangeListener.Code.Found);
return; return;
@ -530,7 +522,7 @@ public final class Library {
if (oldSearchResults != null) { if (oldSearchResults != null) {
oldSearchResults.removeSelf(); oldSearchResults.removeSelf();
} }
newSearchResults = new SearchResultsTree(myRootTree, ROOT_FOUND, pattern); newSearchResults = new SearchResultsTree(myRootTree, LibraryTree.ROOT_FOUND, pattern);
fireModelChangedEvent(ChangeListener.Code.Found); fireModelChangedEvent(ChangeListener.Code.Found);
} }
newSearchResults.getBookSubTree(book, true); newSearchResults.getBookSubTree(book, true);
@ -551,7 +543,7 @@ public final class Library {
if (book == null) { if (book == null) {
return false; return false;
} }
final LibraryTree rootFavorites = getFirstLevelTree(ROOT_FAVORITES); final LibraryTree rootFavorites = getFirstLevelTree(LibraryTree.ROOT_FAVORITES);
for (FBTree tree : rootFavorites.subTrees()) { for (FBTree tree : rootFavorites.subTrees()) {
if (tree instanceof BookTree && book.equals(((BookTree)tree).Book)) { if (tree instanceof BookTree && book.equals(((BookTree)tree).Book)) {
return true; return true;
@ -564,13 +556,13 @@ public final class Library {
if (isBookInFavorites(book)) { if (isBookInFavorites(book)) {
return; return;
} }
final LibraryTree rootFavorites = getFirstLevelTree(ROOT_FAVORITES); final LibraryTree rootFavorites = getFirstLevelTree(LibraryTree.ROOT_FAVORITES);
rootFavorites.getBookSubTree(book, true); rootFavorites.getBookSubTree(book, true);
Collection.setBookFavorite(book, true); Collection.setBookFavorite(book, true);
} }
public void removeBookFromFavorites(Book book) { public void removeBookFromFavorites(Book book) {
if (getFirstLevelTree(ROOT_FAVORITES).removeBook(book, false)) { if (getFirstLevelTree(LibraryTree.ROOT_FAVORITES).removeBook(book, false)) {
Collection.setBookFavorite(book, false); Collection.setBookFavorite(book, false);
fireModelChangedEvent(ChangeListener.Code.BookRemoved); fireModelChangedEvent(ChangeListener.Code.BookRemoved);
} }
@ -595,12 +587,12 @@ public final class Library {
return; return;
} }
myBooks.remove(book.File); myBooks.remove(book.File);
if (getFirstLevelTree(ROOT_RECENT).removeBook(book, false)) { if (getFirstLevelTree(LibraryTree.ROOT_RECENT).removeBook(book, false)) {
final List<Long> ids = myDatabase.loadRecentBookIds(); final List<Long> ids = myDatabase.loadRecentBookIds();
ids.remove(book.getId()); ids.remove(book.getId());
myDatabase.saveRecentBookIds(ids); myDatabase.saveRecentBookIds(ids);
} }
getFirstLevelTree(ROOT_FAVORITES).removeBook(book, false); getFirstLevelTree(LibraryTree.ROOT_FAVORITES).removeBook(book, false);
myRootTree.removeBook(book, true); myRootTree.removeBook(book, true);
if ((removeMode & REMOVE_FROM_DISK) != 0) { if ((removeMode & REMOVE_FROM_DISK) != 0) {

View file

@ -25,16 +25,30 @@ import org.geometerplus.fbreader.book.*;
import org.geometerplus.fbreader.tree.FBTree; import org.geometerplus.fbreader.tree.FBTree;
public abstract class LibraryTree extends FBTree { public abstract class LibraryTree extends FBTree {
protected LibraryTree() { public static final String ROOT_FOUND = "found";
public static final String ROOT_FAVORITES = "favorites";
public static final String ROOT_RECENT = "recent";
public static final String ROOT_BY_AUTHOR = "byAuthor";
public static final String ROOT_BY_TITLE = "byTitle";
public static final String ROOT_BY_SERIES = "bySeries";
public static final String ROOT_BY_TAG = "byTag";
public static final String ROOT_FILE_TREE = "fileTree";
public final IBookCollection Collection;
protected LibraryTree(IBookCollection collection) {
super(); super();
Collection = collection;
} }
protected LibraryTree(LibraryTree parent) { protected LibraryTree(LibraryTree parent) {
super(parent); super(parent);
Collection = parent.Collection;
} }
protected LibraryTree(LibraryTree parent, int position) { protected LibraryTree(LibraryTree parent, int position) {
super(parent, position); super(parent, position);
Collection = parent.Collection;
} }
public Book getBook() { public Book getBook() {
@ -50,7 +64,7 @@ public abstract class LibraryTree extends FBTree {
} }
TagTree getTagSubTree(Tag tag) { TagTree getTagSubTree(Tag tag) {
final TagTree temp = new TagTree(tag); final TagTree temp = new TagTree(Collection, tag);
int position = Collections.binarySearch(subTrees(), temp); int position = Collections.binarySearch(subTrees(), temp);
if (position >= 0) { if (position >= 0) {
return (TagTree)subTrees().get(position); return (TagTree)subTrees().get(position);
@ -60,7 +74,7 @@ public abstract class LibraryTree extends FBTree {
} }
TitleTree getTitleSubTree(String title) { TitleTree getTitleSubTree(String title) {
final TitleTree temp = new TitleTree(title); final TitleTree temp = new TitleTree(Collection, title);
int position = Collections.binarySearch(subTrees(), temp); int position = Collections.binarySearch(subTrees(), temp);
if (position >= 0) { if (position >= 0) {
return (TitleTree)subTrees().get(position); return (TitleTree)subTrees().get(position);
@ -70,7 +84,7 @@ public abstract class LibraryTree extends FBTree {
} }
AuthorTree getAuthorSubTree(Author author) { AuthorTree getAuthorSubTree(Author author) {
final AuthorTree temp = new AuthorTree(author); final AuthorTree temp = new AuthorTree(Collection, author);
int position = Collections.binarySearch(subTrees(), temp); int position = Collections.binarySearch(subTrees(), temp);
if (position >= 0) { if (position >= 0) {
return (AuthorTree)subTrees().get(position); return (AuthorTree)subTrees().get(position);
@ -80,7 +94,7 @@ public abstract class LibraryTree extends FBTree {
} }
BookTree getBookSubTree(Book book, boolean showAuthors) { BookTree getBookSubTree(Book book, boolean showAuthors) {
final BookTree temp = new BookTree(book, showAuthors); final BookTree temp = new BookTree(Collection, book, showAuthors);
int position = Collections.binarySearch(subTrees(), temp); int position = Collections.binarySearch(subTrees(), temp);
if (position >= 0) { if (position >= 0) {
return (BookTree)subTrees().get(position); return (BookTree)subTrees().get(position);
@ -90,7 +104,7 @@ public abstract class LibraryTree extends FBTree {
} }
SeriesTree getSeriesSubTree(String series) { SeriesTree getSeriesSubTree(String series) {
final SeriesTree temp = new SeriesTree(series); final SeriesTree temp = new SeriesTree(Collection, series);
int position = Collections.binarySearch(subTrees(), temp); int position = Collections.binarySearch(subTrees(), temp);
if (position >= 0) { if (position >= 0) {
return (SeriesTree)subTrees().get(position); return (SeriesTree)subTrees().get(position);

View file

@ -20,14 +20,10 @@
package org.geometerplus.fbreader.library; package org.geometerplus.fbreader.library;
import org.geometerplus.fbreader.book.Book; import org.geometerplus.fbreader.book.Book;
import org.geometerplus.fbreader.book.IBookCollection;
public class RecentBooksTree extends FirstLevelTree { public class RecentBooksTree extends FirstLevelTree {
private final IBookCollection myCollection; RecentBooksTree(RootTree root) {
super(root, ROOT_RECENT);
RecentBooksTree(IBookCollection collection, RootTree root, String id) {
super(root, id);
myCollection = collection;
} }
@Override @Override
@ -38,7 +34,7 @@ public class RecentBooksTree extends FirstLevelTree {
@Override @Override
public void waitForOpening() { public void waitForOpening() {
clear(); clear();
for (Book book : myCollection.recentBooks()) { for (Book book : Collection.recentBooks()) {
new BookTree(this, book, true); new BookTree(this, book, true);
} }
} }

View file

@ -19,8 +19,11 @@
package org.geometerplus.fbreader.library; package org.geometerplus.fbreader.library;
import org.geometerplus.fbreader.book.IBookCollection;
class RootTree extends LibraryTree { class RootTree extends LibraryTree {
RootTree() { RootTree(IBookCollection collection) {
super(collection);
} }
@Override @Override

View file

@ -21,13 +21,13 @@ package org.geometerplus.fbreader.library;
import java.util.Collections; import java.util.Collections;
import org.geometerplus.fbreader.book.Book; import org.geometerplus.fbreader.book.*;
import org.geometerplus.fbreader.book.SeriesInfo;
public final class SeriesTree extends LibraryTree { public final class SeriesTree extends LibraryTree {
public final String Series; public final String Series;
SeriesTree(String series) { SeriesTree(IBookCollection collection, String series) {
super(collection);
Series = series; Series = series;
} }
@ -47,7 +47,7 @@ public final class SeriesTree extends LibraryTree {
} }
BookTree getBookInSeriesSubTree(Book book) { BookTree getBookInSeriesSubTree(Book book) {
final BookInSeriesTree temp = new BookInSeriesTree(book); final BookInSeriesTree temp = new BookInSeriesTree(Collection, book);
int position = Collections.binarySearch(subTrees(), temp); int position = Collections.binarySearch(subTrees(), temp);
if (position >= 0) { if (position >= 0) {
return (BookInSeriesTree)subTrees().get(position); return (BookInSeriesTree)subTrees().get(position);

View file

@ -19,13 +19,13 @@
package org.geometerplus.fbreader.library; package org.geometerplus.fbreader.library;
import org.geometerplus.fbreader.book.Book; import org.geometerplus.fbreader.book.*;
import org.geometerplus.fbreader.book.Tag;
public final class TagTree extends LibraryTree { public final class TagTree extends LibraryTree {
public final Tag Tag; public final Tag Tag;
TagTree(Tag tag) { TagTree(IBookCollection collection, Tag tag) {
super(collection);
Tag = tag; Tag = tag;
} }

View file

@ -20,6 +20,7 @@
package org.geometerplus.fbreader.library; package org.geometerplus.fbreader.library;
import org.geometerplus.fbreader.book.Book; import org.geometerplus.fbreader.book.Book;
import org.geometerplus.fbreader.book.IBookCollection;
public final class TitleTree extends LibraryTree { public final class TitleTree extends LibraryTree {
static String firstTitleLetter(Book book) { static String firstTitleLetter(Book book) {
@ -45,7 +46,8 @@ public final class TitleTree extends LibraryTree {
public final String Title; public final String Title;
TitleTree(String title) { TitleTree(IBookCollection collection, String title) {
super(collection);
Title = title; Title = title;
} }