mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
Merge branch 'master' into library-service
Conflicts: src/org/geometerplus/fbreader/library/Library.java
This commit is contained in:
commit
e6598e2da7
11 changed files with 230 additions and 54 deletions
|
@ -801,6 +801,7 @@
|
|||
<node name="dictionaryIsNotInstalled" value="Dictionary is not installed, sorry"/>
|
||||
<node name="permissionDenied" value="Permission denied, 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="emptyBasket" value="Your basket is empty, 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) {
|
||||
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() {
|
||||
if (myInterface == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
//try {
|
||||
// TODO: implement
|
||||
try {
|
||||
return myInterface.series();
|
||||
} catch (RemoteException e) {
|
||||
return Collections.emptyList();
|
||||
//} catch (RemoteException e) {
|
||||
// return Collections.emptyList();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean saveBook(Book book, boolean force) {
|
||||
|
|
|
@ -12,6 +12,8 @@ interface LibraryInterface {
|
|||
List<String> books();
|
||||
List<String> booksForAuthor(in String author);
|
||||
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> recentBooks();
|
||||
List<String> favorites();
|
||||
|
@ -20,6 +22,7 @@ interface LibraryInterface {
|
|||
String getRecentBook(in int index);
|
||||
|
||||
List<String> authors();
|
||||
boolean hasSeries();
|
||||
List<String> series();
|
||||
List<String> tags();
|
||||
|
||||
|
|
|
@ -132,8 +132,16 @@ public class LibraryService extends Service {
|
|||
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) {
|
||||
return SerializerUtil.serializeBookList(myCollection.books(pattern));
|
||||
return SerializerUtil.serializeBookList(myCollection.booksForPattern(pattern));
|
||||
}
|
||||
|
||||
public List<String> recentBooks() {
|
||||
|
@ -165,6 +173,10 @@ public class LibraryService extends Service {
|
|||
return strings;
|
||||
}
|
||||
|
||||
public boolean hasSeries() {
|
||||
return myCollection.hasSeries();
|
||||
}
|
||||
|
||||
public List<String> series() {
|
||||
return myCollection.series();
|
||||
}
|
||||
|
|
|
@ -222,7 +222,26 @@ public class BookCollection extends AbstractBookCollection {
|
|||
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) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -289,6 +308,17 @@ public class BookCollection extends AbstractBookCollection {
|
|||
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() {
|
||||
final Set<String> series = new TreeSet<String>();
|
||||
synchronized (myBooksByFile) {
|
||||
|
|
|
@ -46,26 +46,30 @@ public interface IBookCollection {
|
|||
List<Book> books();
|
||||
List<Book> books(Author author);
|
||||
List<Book> books(Tag tag);
|
||||
List<Book> books(String pattern);
|
||||
List<Book> recentBooks();
|
||||
List<Book> booksForSeries(String series);
|
||||
List<Book> booksForTitlePrefix(String prefix);
|
||||
List<Book> booksForPattern(String pattern);
|
||||
|
||||
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 getBookById(long id);
|
||||
Book getRecentBook(int index);
|
||||
|
||||
List<Author> authors();
|
||||
List<Tag> tags();
|
||||
boolean hasSeries();
|
||||
List<String> series();
|
||||
|
||||
boolean saveBook(Book book, boolean force);
|
||||
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);
|
||||
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) {
|
||||
final SeriesInfo seriesInfo = book.getSeriesInfo();
|
||||
if (seriesInfo != null) {
|
||||
|
|
|
@ -96,6 +96,7 @@ public final class Library {
|
|||
new RecentBooksTree(myRootTree);
|
||||
new AuthorListTree(myRootTree);
|
||||
new FirstLevelTree(myRootTree, LibraryTree.ROOT_BY_TITLE);
|
||||
new SeriesListTree(myRootTree);
|
||||
new TagListTree(myRootTree);
|
||||
new FileFirstLevelTree(myRootTree);
|
||||
}
|
||||
|
@ -176,20 +177,6 @@ public final class Library {
|
|||
myBooks.put(book.getId(), 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) {
|
||||
final String letter = TitleTree.firstTitleLetter(book);
|
||||
if (letter != null) {
|
||||
|
@ -225,7 +212,6 @@ public final class Library {
|
|||
myBooks.remove(book.getId());
|
||||
removeFromTree(LibraryTree.ROOT_FOUND, book);
|
||||
removeFromTree(LibraryTree.ROOT_BY_TITLE, book);
|
||||
removeFromTree(LibraryTree.ROOT_BY_SERIES, book);
|
||||
addBookToLibrary(book);
|
||||
fireModelChangedEvent(ChangeListener.Code.BookAdded);
|
||||
}
|
||||
|
@ -265,7 +251,7 @@ public final class Library {
|
|||
|
||||
FirstLevelTree newSearchResults = null;
|
||||
synchronized (this) {
|
||||
for (Book book : Collection.books(pattern)) {
|
||||
for (Book book : Collection.booksForPattern(pattern)) {
|
||||
if (newSearchResults == null) {
|
||||
if (oldSearchResults != null) {
|
||||
oldSearchResults.removeSelf();
|
||||
|
|
|
@ -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) {
|
||||
final LinkedList<FBTree> toRemove = new LinkedList<FBTree>();
|
||||
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();
|
||||
}
|
||||
|
||||
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
|
||||
public boolean containsBook(Book book) {
|
||||
if (book == null) {
|
||||
|
@ -70,4 +59,42 @@ public final class SeriesTree extends LibraryTree {
|
|||
protected String 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