mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
code simplification
This commit is contained in:
parent
84bc24cad2
commit
9a8e964e8f
7 changed files with 16 additions and 25 deletions
|
@ -339,7 +339,7 @@ public class LibraryActivity extends TreeActivity<LibraryTree> implements MenuIt
|
|||
|
||||
if (oldSearchResults != null && pattern.equals(oldSearchResults.Pattern)) {
|
||||
onSearchEvent(true);
|
||||
} else if (myRootTree.Collection.hasBooks(new Query(new Filter.ByPattern(pattern), 1))) {
|
||||
} else if (myRootTree.Collection.hasBooks(new Filter.ByPattern(pattern))) {
|
||||
if (oldSearchResults != null) {
|
||||
oldSearchResults.removeSelf();
|
||||
}
|
||||
|
|
|
@ -144,12 +144,12 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized boolean hasBooks(Query query) {
|
||||
public synchronized boolean hasBooks(Filter filter) {
|
||||
if (myInterface == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return myInterface.hasBooks(SerializerUtil.serialize(query));
|
||||
return myInterface.hasBooks(SerializerUtil.serialize(new Query(filter, 1)));
|
||||
} catch (RemoteException e) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ public class LibraryService extends Service {
|
|||
}
|
||||
|
||||
public boolean hasBooks(String query) {
|
||||
return myCollection.hasBooks(SerializerUtil.deserializeQuery(query));
|
||||
return myCollection.hasBooks(SerializerUtil.deserializeQuery(query).Filter);
|
||||
}
|
||||
|
||||
public List<String> recentBooks() {
|
||||
|
|
|
@ -230,25 +230,17 @@ public class BookCollection extends AbstractBookCollection {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean hasBooks(Query query) {
|
||||
public boolean hasBooks(Filter filter) {
|
||||
final List<Book> allBooks;
|
||||
synchronized (myBooksByFile) {
|
||||
allBooks = new ArrayList<Book>(myBooksByFile.values());
|
||||
}
|
||||
final int start = query.Page * query.Limit;
|
||||
if (query.Filter instanceof Filter.Empty) {
|
||||
return allBooks.size() > 0;
|
||||
} else {
|
||||
int count = 0;
|
||||
final List<Book> filtered = new ArrayList<Book>(query.Limit);
|
||||
for (Book b : allBooks) {
|
||||
if (query.Filter.matches(b) && count >= start) {
|
||||
return true;
|
||||
}
|
||||
++count;
|
||||
for (Book b : allBooks) {
|
||||
if (filter.matches(b)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<String> titles(Query query) {
|
||||
|
|
|
@ -52,7 +52,7 @@ public interface IBookCollection {
|
|||
int size();
|
||||
|
||||
List<Book> books(Query query);
|
||||
boolean hasBooks(Query query);
|
||||
boolean hasBooks(Filter filter);
|
||||
List<String> titles(Query query);
|
||||
|
||||
List<Book> recentBooks();
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
package org.geometerplus.fbreader.book;
|
||||
|
||||
public class Query {
|
||||
final Filter Filter;
|
||||
final int Limit;
|
||||
final int Page;
|
||||
public final Filter Filter;
|
||||
public final int Limit;
|
||||
public final int Page;
|
||||
|
||||
public Query(Filter filter, int limit) {
|
||||
this(filter, limit, 0);
|
||||
|
|
|
@ -58,10 +58,9 @@ public class FavoritesTree extends FilteredTree {
|
|||
|
||||
@Override
|
||||
public Status getOpeningStatus() {
|
||||
if (!Collection.labels().contains(Book.FAVORITE_LABEL)) {
|
||||
return Status.CANNOT_OPEN;
|
||||
}
|
||||
return Status.ALWAYS_RELOAD_BEFORE_OPENING;
|
||||
return Collection.hasBooks(new Filter.ByLabel(Book.FAVORITE_LABEL))
|
||||
? Status.ALWAYS_RELOAD_BEFORE_OPENING
|
||||
: Status.CANNOT_OPEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue