1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 02:39:23 +02:00

introduced BookWithAuthorsTree class

This commit is contained in:
Nikolay Pultsin 2013-02-08 08:27:46 +00:00
parent a46e23e78e
commit dfd771c346
6 changed files with 81 additions and 42 deletions

View file

@ -27,11 +27,11 @@ import org.geometerplus.fbreader.tree.FBTree;
public final class BookInSeriesTree extends BookTree { public final class BookInSeriesTree extends BookTree {
BookInSeriesTree(IBookCollection collection, Book book) { BookInSeriesTree(IBookCollection collection, Book book) {
super(collection, book, false); super(collection, book);
} }
BookInSeriesTree(LibraryTree parent, Book book, int position) { BookInSeriesTree(LibraryTree parent, Book book, int position) {
super(parent, book, false, position); super(parent, book, position);
} }
@Override @Override

View file

@ -26,24 +26,20 @@ import org.geometerplus.fbreader.tree.FBTree;
public class BookTree extends LibraryTree { public class BookTree extends LibraryTree {
public final Book Book; public final Book Book;
private final boolean myShowAuthors;
BookTree(IBookCollection collection, Book book, boolean showAuthors) { BookTree(IBookCollection collection, Book book) {
super(collection); super(collection);
Book = book; Book = book;
myShowAuthors = showAuthors;
} }
BookTree(LibraryTree parent, Book book, boolean showAuthors) { BookTree(LibraryTree parent, Book book) {
super(parent); super(parent);
Book = book; Book = book;
myShowAuthors = showAuthors;
} }
BookTree(LibraryTree parent, Book book, boolean showAuthors, int position) { BookTree(LibraryTree parent, Book book, int position) {
super(parent, position); super(parent, position);
Book = book; Book = book;
myShowAuthors = showAuthors;
} }
@Override @Override
@ -61,25 +57,6 @@ public class BookTree extends LibraryTree {
return "@BookTree " + getName(); return "@BookTree " + getName();
} }
@Override
public String getSummary() {
if (!myShowAuthors) {
return super.getSummary();
}
StringBuilder builder = new StringBuilder();
int count = 0;
for (Author author : Book.authors()) {
if (count++ > 0) {
builder.append(", ");
}
builder.append(author.DisplayName);
if (count == 5) {
break;
}
}
return builder.toString();
}
@Override @Override
protected ZLImage createCover() { protected ZLImage createCover() {
return BookUtil.getCover(Book); return BookUtil.getCover(Book);

View file

@ -0,0 +1,52 @@
/*
* Copyright (C) 2009-2013 Geometer Plus <contact@geometerplus.com>
*
* 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.*;
public class BookWithAuthorsTree extends BookTree {
BookWithAuthorsTree(IBookCollection collection, Book book) {
super(collection, book);
}
BookWithAuthorsTree(LibraryTree parent, Book book) {
super(parent, book);
}
BookWithAuthorsTree(LibraryTree parent, Book book, int position) {
super(parent, book, position);
}
@Override
public String getSummary() {
StringBuilder builder = new StringBuilder();
int count = 0;
for (Author author : Book.authors()) {
if (count++ > 0) {
builder.append(", ");
}
builder.append(author.DisplayName);
if (count == 5) {
break;
}
}
return builder.toString();
}
}

View file

@ -248,7 +248,7 @@ public final class Library {
for (Author a : authors) { for (Author a : authors) {
final AuthorTree authorTree = getFirstLevelTree(LibraryTree.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);
} else { } else {
authorTree.getSeriesSubTree(seriesInfo.Title).getBookInSeriesSubTree(book); authorTree.getSeriesSubTree(seriesInfo.Title).getBookInSeriesSubTree(book);
} }
@ -271,10 +271,10 @@ public final class Library {
if (letter != null) { if (letter != null) {
final TitleTree tree = final TitleTree tree =
getFirstLevelTree(LibraryTree.ROOT_BY_TITLE).getTitleSubTree(letter); getFirstLevelTree(LibraryTree.ROOT_BY_TITLE).getTitleSubTree(letter);
tree.getBookSubTree(book, true); tree.getBookWithAuthorsSubTree(book);
} }
} else { } else {
getFirstLevelTree(LibraryTree.ROOT_BY_TITLE).getBookSubTree(book, true); getFirstLevelTree(LibraryTree.ROOT_BY_TITLE).getBookWithAuthorsSubTree(book);
} }
List<Tag> tags = book.tags(); List<Tag> tags = book.tags();
@ -282,13 +282,13 @@ public final class Library {
tags = (List<Tag>)myNullList; tags = (List<Tag>)myNullList;
} }
for (Tag t : tags) { for (Tag t : tags) {
getTagTree(t).getBookSubTree(book, true); getTagTree(t).getBookWithAuthorsSubTree(book);
} }
final SearchResultsTree found = final SearchResultsTree found =
(SearchResultsTree)getFirstLevelTree(LibraryTree.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.getBookWithAuthorsSubTree(book);
} }
} }
@ -302,10 +302,10 @@ 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(Collection, book, true)); int index = tree.indexOf(new BookWithAuthorsTree(Collection, book));
if (index >= 0) { if (index >= 0) {
tree.removeBook(book, false); tree.removeBook(book, false);
new BookTree(tree, book, true, index); new BookWithAuthorsTree(tree, book, index);
} }
} }
} }
@ -349,7 +349,7 @@ public final class Library {
} }
for (Book book : Collection.favorites()) { for (Book book : Collection.favorites()) {
getFirstLevelTree(LibraryTree.ROOT_FAVORITES).getBookSubTree(book, true); getFirstLevelTree(LibraryTree.ROOT_FAVORITES).getBookWithAuthorsSubTree(book);
} }
fireModelChangedEvent(ChangeListener.Code.BookAdded); fireModelChangedEvent(ChangeListener.Code.BookAdded);
@ -525,7 +525,7 @@ public final class Library {
newSearchResults = new SearchResultsTree(myRootTree, LibraryTree.ROOT_FOUND, pattern); newSearchResults = new SearchResultsTree(myRootTree, LibraryTree.ROOT_FOUND, pattern);
fireModelChangedEvent(ChangeListener.Code.Found); fireModelChangedEvent(ChangeListener.Code.Found);
} }
newSearchResults.getBookSubTree(book, true); newSearchResults.getBookWithAuthorsSubTree(book);
fireModelChangedEvent(ChangeListener.Code.BookAdded); fireModelChangedEvent(ChangeListener.Code.BookAdded);
} }
} }
@ -557,7 +557,7 @@ public final class Library {
return; return;
} }
final LibraryTree rootFavorites = getFirstLevelTree(LibraryTree.ROOT_FAVORITES); final LibraryTree rootFavorites = getFirstLevelTree(LibraryTree.ROOT_FAVORITES);
rootFavorites.getBookSubTree(book, true); rootFavorites.getBookWithAuthorsSubTree(book);
Collection.setBookFavorite(book, true); Collection.setBookFavorite(book, true);
} }

View file

@ -93,13 +93,23 @@ public abstract class LibraryTree extends FBTree {
} }
} }
BookTree getBookSubTree(Book book, boolean showAuthors) { BookTree getBookSubTree(Book book) {
final BookTree temp = new BookTree(Collection, book, showAuthors); final BookTree temp = new BookTree(Collection, book);
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);
} else { } else {
return new BookTree(this, book, showAuthors, - position - 1); return new BookTree(this, book, - position - 1);
}
}
BookTree getBookWithAuthorsSubTree(Book book) {
final BookTree temp = new BookWithAuthorsTree(Collection, book);
int position = Collections.binarySearch(subTrees(), temp);
if (position >= 0) {
return (BookTree)subTrees().get(position);
} else {
return new BookWithAuthorsTree(this, book, - position - 1);
} }
} }

View file

@ -35,7 +35,7 @@ public class RecentBooksTree extends FirstLevelTree {
public void waitForOpening() { public void waitForOpening() {
clear(); clear();
for (Book book : Collection.recentBooks()) { for (Book book : Collection.recentBooks()) {
new BookTree(this, book, true); new BookWithAuthorsTree(this, book);
} }
} }
} }