mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
series trees on-the-fly
This commit is contained in:
parent
04f64f3d81
commit
454bd46593
11 changed files with 229 additions and 53 deletions
|
@ -801,6 +801,7 @@
|
||||||
<node name="dictionaryIsNotInstalled" value="Dictionary is not installed, sorry"/>
|
<node name="dictionaryIsNotInstalled" value="Dictionary is not installed, sorry"/>
|
||||||
<node name="permissionDenied" value="Permission denied, sorry"/>
|
<node name="permissionDenied" value="Permission denied, sorry"/>
|
||||||
<node name="noFavorites" value="Your favorites list is empty, sorry"/>
|
<node name="noFavorites" value="Your favorites list is empty, sorry"/>
|
||||||
|
<node name="noFavorites" value="There are no books in series, sorry"/>
|
||||||
<node name="emptyCatalog" value="Catalog is empty, sorry"/>
|
<node name="emptyCatalog" value="Catalog is empty, sorry"/>
|
||||||
<node name="emptyBasket" value="Your basket is empty, sorry"/>
|
<node name="emptyBasket" value="Your basket is empty, sorry"/>
|
||||||
<node name="emptyNetworkSearchResults" value="No books found, sorry"/>
|
<node name="emptyNetworkSearchResults" value="No books found, sorry"/>
|
||||||
|
|
|
@ -147,7 +147,29 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized List<Book> books(String pattern) {
|
public synchronized List<Book> booksForSeries(String series) {
|
||||||
|
if (myInterface == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return SerializerUtil.deserializeBookList(myInterface.booksForSeries(series));
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized List<Book> booksForTitlePrefix(String prefix) {
|
||||||
|
if (myInterface == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return SerializerUtil.deserializeBookList(myInterface.booksForTitlePrefix(prefix));
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized List<Book> booksForPattern(String pattern) {
|
||||||
if (myInterface == null) {
|
if (myInterface == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
@ -245,16 +267,25 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized boolean hasSeries() {
|
||||||
|
if (myInterface != null) {
|
||||||
|
try {
|
||||||
|
return myInterface.hasSeries();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized List<String> series() {
|
public synchronized List<String> series() {
|
||||||
if (myInterface == null) {
|
if (myInterface == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
//try {
|
try {
|
||||||
// TODO: implement
|
return myInterface.series();
|
||||||
|
} catch (RemoteException e) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
//} catch (RemoteException e) {
|
}
|
||||||
// return Collections.emptyList();
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean saveBook(Book book, boolean force) {
|
public synchronized boolean saveBook(Book book, boolean force) {
|
||||||
|
|
|
@ -12,6 +12,8 @@ interface LibraryInterface {
|
||||||
List<String> books();
|
List<String> books();
|
||||||
List<String> booksForAuthor(in String author);
|
List<String> booksForAuthor(in String author);
|
||||||
List<String> booksForTag(in String tag);
|
List<String> booksForTag(in String tag);
|
||||||
|
List<String> booksForSeries(in String series);
|
||||||
|
List<String> booksForTitlePrefix(in String prefix);
|
||||||
List<String> booksForPattern(in String pattern);
|
List<String> booksForPattern(in String pattern);
|
||||||
List<String> recentBooks();
|
List<String> recentBooks();
|
||||||
List<String> favorites();
|
List<String> favorites();
|
||||||
|
@ -20,6 +22,7 @@ interface LibraryInterface {
|
||||||
String getRecentBook(in int index);
|
String getRecentBook(in int index);
|
||||||
|
|
||||||
List<String> authors();
|
List<String> authors();
|
||||||
|
boolean hasSeries();
|
||||||
List<String> series();
|
List<String> series();
|
||||||
List<String> tags();
|
List<String> tags();
|
||||||
|
|
||||||
|
|
|
@ -127,8 +127,16 @@ public class LibraryService extends Service {
|
||||||
return SerializerUtil.serializeBookList(myCollection.books(Util.stringToTag(tag)));
|
return SerializerUtil.serializeBookList(myCollection.books(Util.stringToTag(tag)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> booksForSeries(String series) {
|
||||||
|
return SerializerUtil.serializeBookList(myCollection.booksForSeries(series));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> booksForTitlePrefix(String prefix) {
|
||||||
|
return SerializerUtil.serializeBookList(myCollection.booksForTitlePrefix(prefix));
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> booksForPattern(String pattern) {
|
public List<String> booksForPattern(String pattern) {
|
||||||
return SerializerUtil.serializeBookList(myCollection.books(pattern));
|
return SerializerUtil.serializeBookList(myCollection.booksForPattern(pattern));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> recentBooks() {
|
public List<String> recentBooks() {
|
||||||
|
@ -160,6 +168,10 @@ public class LibraryService extends Service {
|
||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasSeries() {
|
||||||
|
return myCollection.hasSeries();
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> series() {
|
public List<String> series() {
|
||||||
return myCollection.series();
|
return myCollection.series();
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,26 @@ public class BookCollection extends AbstractBookCollection {
|
||||||
return filtered;
|
return filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Book> books(String pattern) {
|
public List<Book> booksForSeries(String series) {
|
||||||
|
final LinkedList<Book> filtered = new LinkedList<Book>();
|
||||||
|
for (Book b : books()) {
|
||||||
|
final SeriesInfo info = b.getSeriesInfo();
|
||||||
|
if (info != null && series.equals(info.Title)) {
|
||||||
|
filtered.add(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Book> booksForTitlePrefix(String prefix) {
|
||||||
|
final LinkedList<Book> filtered = new LinkedList<Book>();
|
||||||
|
for (Book b : books()) {
|
||||||
|
// TODO: implement
|
||||||
|
}
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Book> booksForPattern(String pattern) {
|
||||||
if (pattern == null || pattern.length() == 0) {
|
if (pattern == null || pattern.length() == 0) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
@ -289,6 +308,17 @@ public class BookCollection extends AbstractBookCollection {
|
||||||
return new ArrayList<Tag>(tags);
|
return new ArrayList<Tag>(tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasSeries() {
|
||||||
|
synchronized (myBooksByFile) {
|
||||||
|
for (Book book : myBooksByFile.values()) {
|
||||||
|
if (book.getSeriesInfo() != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> series() {
|
public List<String> series() {
|
||||||
final Set<String> series = new TreeSet<String>();
|
final Set<String> series = new TreeSet<String>();
|
||||||
synchronized (myBooksByFile) {
|
synchronized (myBooksByFile) {
|
||||||
|
|
|
@ -46,26 +46,30 @@ public interface IBookCollection {
|
||||||
List<Book> books();
|
List<Book> books();
|
||||||
List<Book> books(Author author);
|
List<Book> books(Author author);
|
||||||
List<Book> books(Tag tag);
|
List<Book> books(Tag tag);
|
||||||
List<Book> books(String pattern);
|
List<Book> booksForSeries(String series);
|
||||||
List<Book> recentBooks();
|
List<Book> booksForTitlePrefix(String prefix);
|
||||||
|
List<Book> booksForPattern(String pattern);
|
||||||
|
|
||||||
List<Book> favorites();
|
List<Book> favorites();
|
||||||
|
boolean hasFavorites();
|
||||||
|
boolean isFavorite(Book book);
|
||||||
|
void setBookFavorite(Book book, boolean favorite);
|
||||||
|
|
||||||
|
List<Book> recentBooks();
|
||||||
|
Book getRecentBook(int index);
|
||||||
|
void addBookToRecentList(Book book);
|
||||||
|
|
||||||
Book getBookByFile(ZLFile file);
|
Book getBookByFile(ZLFile file);
|
||||||
Book getBookById(long id);
|
Book getBookById(long id);
|
||||||
Book getRecentBook(int index);
|
|
||||||
|
|
||||||
List<Author> authors();
|
List<Author> authors();
|
||||||
List<Tag> tags();
|
List<Tag> tags();
|
||||||
|
boolean hasSeries();
|
||||||
List<String> series();
|
List<String> series();
|
||||||
|
|
||||||
boolean saveBook(Book book, boolean force);
|
boolean saveBook(Book book, boolean force);
|
||||||
void removeBook(Book book, boolean deleteFromDisk);
|
void removeBook(Book book, boolean deleteFromDisk);
|
||||||
|
|
||||||
void addBookToRecentList(Book book);
|
|
||||||
|
|
||||||
boolean hasFavorites();
|
|
||||||
boolean isFavorite(Book book);
|
|
||||||
void setBookFavorite(Book book, boolean favorite);
|
|
||||||
|
|
||||||
ZLTextPosition getStoredPosition(long bookId);
|
ZLTextPosition getStoredPosition(long bookId);
|
||||||
void storePosition(long bookId, ZLTextPosition position);
|
void storePosition(long bookId, ZLTextPosition position);
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,16 @@ public class AuthorTree extends LibraryTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SeriesTree getSeriesSubTree(String series) {
|
||||||
|
final SeriesTree temp = new SeriesTree(Collection, series);
|
||||||
|
int position = Collections.binarySearch(subTrees(), temp);
|
||||||
|
if (position >= 0) {
|
||||||
|
return (SeriesTree)subTrees().get(position);
|
||||||
|
} else {
|
||||||
|
return new SeriesTree(this, series, - position - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean createBookSubTree(Book book) {
|
private boolean createBookSubTree(Book book) {
|
||||||
final SeriesInfo seriesInfo = book.getSeriesInfo();
|
final SeriesInfo seriesInfo = book.getSeriesInfo();
|
||||||
if (seriesInfo != null) {
|
if (seriesInfo != null) {
|
||||||
|
|
|
@ -110,6 +110,7 @@ public final class Library {
|
||||||
new RecentBooksTree(myRootTree);
|
new RecentBooksTree(myRootTree);
|
||||||
new AuthorListTree(myRootTree);
|
new AuthorListTree(myRootTree);
|
||||||
new FirstLevelTree(myRootTree, LibraryTree.ROOT_BY_TITLE);
|
new FirstLevelTree(myRootTree, LibraryTree.ROOT_BY_TITLE);
|
||||||
|
new SeriesListTree(myRootTree);
|
||||||
new TagListTree(myRootTree);
|
new TagListTree(myRootTree);
|
||||||
new FileFirstLevelTree(myRootTree);
|
new FileFirstLevelTree(myRootTree);
|
||||||
}
|
}
|
||||||
|
@ -230,20 +231,6 @@ public final class Library {
|
||||||
}
|
}
|
||||||
myBooks.put(book.File, book);
|
myBooks.put(book.File, book);
|
||||||
|
|
||||||
final SeriesInfo seriesInfo = book.getSeriesInfo();
|
|
||||||
|
|
||||||
if (seriesInfo != null) {
|
|
||||||
FirstLevelTree seriesRoot = getFirstLevelTree(LibraryTree.ROOT_BY_SERIES);
|
|
||||||
if (seriesRoot == null) {
|
|
||||||
seriesRoot = new FirstLevelTree(
|
|
||||||
myRootTree,
|
|
||||||
myRootTree.indexOf(getFirstLevelTree(LibraryTree.ROOT_BY_TITLE)) + 1,
|
|
||||||
LibraryTree.ROOT_BY_SERIES
|
|
||||||
);
|
|
||||||
}
|
|
||||||
seriesRoot.getSeriesSubTree(seriesInfo.Title).createBookInSeriesSubTree(book);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myDoGroupTitlesByFirstLetter) {
|
if (myDoGroupTitlesByFirstLetter) {
|
||||||
final String letter = TitleTree.firstTitleLetter(book);
|
final String letter = TitleTree.firstTitleLetter(book);
|
||||||
if (letter != null) {
|
if (letter != null) {
|
||||||
|
@ -277,7 +264,6 @@ public final class Library {
|
||||||
myBooks.remove(book.File);
|
myBooks.remove(book.File);
|
||||||
removeFromTree(LibraryTree.ROOT_FOUND, book);
|
removeFromTree(LibraryTree.ROOT_FOUND, book);
|
||||||
removeFromTree(LibraryTree.ROOT_BY_TITLE, book);
|
removeFromTree(LibraryTree.ROOT_BY_TITLE, book);
|
||||||
removeFromTree(LibraryTree.ROOT_BY_SERIES, book);
|
|
||||||
addBookToLibrary(book);
|
addBookToLibrary(book);
|
||||||
fireModelChangedEvent(ChangeListener.Code.BookAdded);
|
fireModelChangedEvent(ChangeListener.Code.BookAdded);
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,16 +95,6 @@ public abstract class LibraryTree extends FBTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SeriesTree getSeriesSubTree(String series) {
|
|
||||||
final SeriesTree temp = new SeriesTree(Collection, series);
|
|
||||||
int position = Collections.binarySearch(subTrees(), temp);
|
|
||||||
if (position >= 0) {
|
|
||||||
return (SeriesTree)subTrees().get(position);
|
|
||||||
} else {
|
|
||||||
return new SeriesTree(this, series, - position - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean removeBook(Book book) {
|
public boolean removeBook(Book book) {
|
||||||
final LinkedList<FBTree> toRemove = new LinkedList<FBTree>();
|
final LinkedList<FBTree> toRemove = new LinkedList<FBTree>();
|
||||||
for (FBTree tree : this) {
|
for (FBTree tree : this) {
|
||||||
|
|
82
src/org/geometerplus/fbreader/library/SeriesListTree.java
Normal file
82
src/org/geometerplus/fbreader/library/SeriesListTree.java
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* 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 java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.book.*;
|
||||||
|
|
||||||
|
public class SeriesListTree extends FirstLevelTree {
|
||||||
|
SeriesListTree(RootTree root) {
|
||||||
|
super(root, ROOT_BY_SERIES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status getOpeningStatus() {
|
||||||
|
if (!Collection.hasSeries()) {
|
||||||
|
return Status.CANNOT_OPEN;
|
||||||
|
}
|
||||||
|
return Status.ALWAYS_RELOAD_BEFORE_OPENING;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOpeningStatusMessage() {
|
||||||
|
return getOpeningStatus() == Status.CANNOT_OPEN
|
||||||
|
? "noSeries" : super.getOpeningStatusMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void waitForOpening() {
|
||||||
|
clear();
|
||||||
|
for (String s : Collection.series()) {
|
||||||
|
createSeriesSubTree(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBookEvent(BookEvent event, Book book) {
|
||||||
|
switch (event) {
|
||||||
|
case Added:
|
||||||
|
{
|
||||||
|
final SeriesInfo info = book.getSeriesInfo();
|
||||||
|
return info != null && createSeriesSubTree(info.Title);
|
||||||
|
}
|
||||||
|
case Removed:
|
||||||
|
// TODO: implement
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
case Updated:
|
||||||
|
// TODO: implement
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean createSeriesSubTree(String series) {
|
||||||
|
final SeriesTree temp = new SeriesTree(Collection, series);
|
||||||
|
int position = Collections.binarySearch(subTrees(), temp);
|
||||||
|
if (position >= 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
new SeriesTree(this, series, - position - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,17 +46,6 @@ public final class SeriesTree extends LibraryTree {
|
||||||
return "@SeriesTree " + getName();
|
return "@SeriesTree " + getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean createBookInSeriesSubTree(Book book) {
|
|
||||||
final BookInSeriesTree temp = new BookInSeriesTree(Collection, book);
|
|
||||||
int position = Collections.binarySearch(subTrees(), temp);
|
|
||||||
if (position >= 0) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
new BookInSeriesTree(this, book, - position - 1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsBook(Book book) {
|
public boolean containsBook(Book book) {
|
||||||
if (book == null) {
|
if (book == null) {
|
||||||
|
@ -70,4 +59,42 @@ public final class SeriesTree extends LibraryTree {
|
||||||
protected String getSortKey() {
|
protected String getSortKey() {
|
||||||
return " Series:" + super.getSortKey();
|
return " Series:" + super.getSortKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status getOpeningStatus() {
|
||||||
|
return Status.ALWAYS_RELOAD_BEFORE_OPENING;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void waitForOpening() {
|
||||||
|
clear();
|
||||||
|
for (Book book : Collection.booksForSeries(Series)) {
|
||||||
|
createBookInSeriesSubTree(book);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBookEvent(BookEvent event, Book book) {
|
||||||
|
switch (event) {
|
||||||
|
case Added:
|
||||||
|
return containsBook(book) && createBookInSeriesSubTree(book);
|
||||||
|
case Removed:
|
||||||
|
// TODO: implement
|
||||||
|
case Updated:
|
||||||
|
// TODO: implement
|
||||||
|
default:
|
||||||
|
return super.onBookEvent(event, book);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean createBookInSeriesSubTree(Book book) {
|
||||||
|
final BookInSeriesTree temp = new BookInSeriesTree(Collection, book);
|
||||||
|
int position = Collections.binarySearch(subTrees(), temp);
|
||||||
|
if (position >= 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
new BookInSeriesTree(this, book, - position - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue