mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
Merge branch 'master' into library-service
Conflicts: src/org/geometerplus/fbreader/library/Library.java
This commit is contained in:
commit
40e98cd33c
12 changed files with 153 additions and 52 deletions
|
@ -75,23 +75,20 @@ class LibraryTreeAdapter extends TreeAdapter {
|
||||||
private int getCoverResourceId(LibraryTree tree) {
|
private int getCoverResourceId(LibraryTree tree) {
|
||||||
if (tree.getBook() != null) {
|
if (tree.getBook() != null) {
|
||||||
return R.drawable.ic_list_library_book;
|
return R.drawable.ic_list_library_book;
|
||||||
} else if (tree instanceof FirstLevelTree) {
|
} else if (tree instanceof FavoritesTree) {
|
||||||
final String id = tree.getUniqueKey().Id;
|
return R.drawable.ic_list_library_favorites;
|
||||||
if (LibraryTree.ROOT_FAVORITES.equals(id)) {
|
} else if (tree instanceof RecentBooksTree) {
|
||||||
return R.drawable.ic_list_library_favorites;
|
return R.drawable.ic_list_library_recent;
|
||||||
} else if (LibraryTree.ROOT_RECENT.equals(id)) {
|
} else if (tree instanceof AuthorListTree) {
|
||||||
return R.drawable.ic_list_library_recent;
|
return R.drawable.ic_list_library_authors;
|
||||||
} else if (LibraryTree.ROOT_BY_AUTHOR.equals(id)) {
|
} else if (tree instanceof TitleListTree) {
|
||||||
return R.drawable.ic_list_library_authors;
|
return R.drawable.ic_list_library_books;
|
||||||
} else if (LibraryTree.ROOT_BY_TITLE.equals(id)) {
|
} else if (tree instanceof TagListTree) {
|
||||||
return R.drawable.ic_list_library_books;
|
return R.drawable.ic_list_library_tags;
|
||||||
} else if (LibraryTree.ROOT_BY_TAG.equals(id)) {
|
} else if (tree instanceof FileFirstLevelTree) {
|
||||||
return R.drawable.ic_list_library_tags;
|
return R.drawable.ic_list_library_folder;
|
||||||
} else if (LibraryTree.ROOT_FILE_TREE.equals(id)) {
|
} else if (tree instanceof SearchResultsTree) {
|
||||||
return R.drawable.ic_list_library_folder;
|
return R.drawable.ic_list_library_search;
|
||||||
} else if (LibraryTree.ROOT_FOUND.equals(id)) {
|
|
||||||
return R.drawable.ic_list_library_search;
|
|
||||||
}
|
|
||||||
} else if (tree instanceof FileTree) {
|
} else if (tree instanceof FileTree) {
|
||||||
final ZLFile file = ((FileTree)tree).getFile();
|
final ZLFile file = ((FileTree)tree).getFile();
|
||||||
if (file.isArchive()) {
|
if (file.isArchive()) {
|
||||||
|
|
|
@ -288,6 +288,17 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized List<String> titles() {
|
||||||
|
if (myInterface == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return myInterface.titles();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized boolean saveBook(Book book, boolean force) {
|
public synchronized boolean saveBook(Book book, boolean force) {
|
||||||
if (myInterface == null) {
|
if (myInterface == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -25,6 +25,7 @@ interface LibraryInterface {
|
||||||
boolean hasSeries();
|
boolean hasSeries();
|
||||||
List<String> series();
|
List<String> series();
|
||||||
List<String> tags();
|
List<String> tags();
|
||||||
|
List<String> titles();
|
||||||
|
|
||||||
boolean saveBook(in String book, in boolean force);
|
boolean saveBook(in String book, in boolean force);
|
||||||
void removeBook(in String book, in boolean deleteFromDisk);
|
void removeBook(in String book, in boolean deleteFromDisk);
|
||||||
|
|
|
@ -190,6 +190,10 @@ public class LibraryService extends Service {
|
||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> titles() {
|
||||||
|
return myCollection.titles();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean saveBook(String book, boolean force) {
|
public boolean saveBook(String book, boolean force) {
|
||||||
return myCollection.saveBook(SerializerUtil.deserializeBook(book), force);
|
return myCollection.saveBook(SerializerUtil.deserializeBook(book), force);
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,6 +332,16 @@ public class BookCollection extends AbstractBookCollection {
|
||||||
return new ArrayList<String>(series);
|
return new ArrayList<String>(series);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> titles() {
|
||||||
|
synchronized (myBooksByFile) {
|
||||||
|
final List<String> titles = new ArrayList<String>(myBooksByFile.size());
|
||||||
|
for (Book book : myBooksByFile.values()) {
|
||||||
|
titles.add(book.getTitle());
|
||||||
|
}
|
||||||
|
return titles;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Book getRecentBook(int index) {
|
public Book getRecentBook(int index) {
|
||||||
List<Long> recentIds = myDatabase.loadRecentBookIds();
|
List<Long> recentIds = myDatabase.loadRecentBookIds();
|
||||||
return recentIds.size() > index ? getBookById(recentIds.get(index)) : null;
|
return recentIds.size() > index ? getBookById(recentIds.get(index)) : null;
|
||||||
|
|
|
@ -63,9 +63,10 @@ public interface IBookCollection {
|
||||||
Book getBookById(long id);
|
Book getBookById(long id);
|
||||||
|
|
||||||
List<Author> authors();
|
List<Author> authors();
|
||||||
List<Tag> tags();
|
|
||||||
boolean hasSeries();
|
boolean hasSeries();
|
||||||
List<String> series();
|
List<String> series();
|
||||||
|
List<Tag> tags();
|
||||||
|
List<String> titles();
|
||||||
|
|
||||||
boolean saveBook(Book book, boolean force);
|
boolean saveBook(Book book, boolean force);
|
||||||
void removeBook(Book book, boolean deleteFromDisk);
|
void removeBook(Book book, boolean deleteFromDisk);
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
public class FirstLevelTree extends LibraryTree {
|
abstract class FirstLevelTree extends LibraryTree {
|
||||||
private final String myId;
|
private final String myId;
|
||||||
private final ZLResource myResource;
|
private final ZLResource myResource;
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,6 @@ public final class Library {
|
||||||
private final Map<Long,Book> myBooks = Collections.synchronizedMap(new HashMap<Long,Book>());
|
private final Map<Long,Book> myBooks = Collections.synchronizedMap(new HashMap<Long,Book>());
|
||||||
|
|
||||||
private final RootTree myRootTree;
|
private final RootTree myRootTree;
|
||||||
private boolean myDoGroupTitlesByFirstLetter;
|
|
||||||
|
|
||||||
private final static int STATUS_LOADING = 1;
|
private final static int STATUS_LOADING = 1;
|
||||||
private final static int STATUS_SEARCHING = 2;
|
private final static int STATUS_SEARCHING = 2;
|
||||||
|
@ -95,7 +94,7 @@ public final class Library {
|
||||||
new FavoritesTree(myRootTree);
|
new FavoritesTree(myRootTree);
|
||||||
new RecentBooksTree(myRootTree);
|
new RecentBooksTree(myRootTree);
|
||||||
new AuthorListTree(myRootTree);
|
new AuthorListTree(myRootTree);
|
||||||
new FirstLevelTree(myRootTree, LibraryTree.ROOT_BY_TITLE);
|
new TitleListTree(myRootTree);
|
||||||
new SeriesListTree(myRootTree);
|
new SeriesListTree(myRootTree);
|
||||||
new TagListTree(myRootTree);
|
new TagListTree(myRootTree);
|
||||||
new FileFirstLevelTree(myRootTree);
|
new FileFirstLevelTree(myRootTree);
|
||||||
|
@ -177,17 +176,6 @@ public final class Library {
|
||||||
myBooks.put(book.getId(), book);
|
myBooks.put(book.getId(), book);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myDoGroupTitlesByFirstLetter) {
|
|
||||||
final String letter = TitleTree.firstTitleLetter(book);
|
|
||||||
if (letter != null) {
|
|
||||||
final TitleTree tree =
|
|
||||||
getFirstLevelTree(LibraryTree.ROOT_BY_TITLE).getTitleSubTree(letter);
|
|
||||||
tree.createBookWithAuthorsSubTree(book);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
getFirstLevelTree(LibraryTree.ROOT_BY_TITLE).createBookWithAuthorsSubTree(book);
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
final SearchResultsTree found = (SearchResultsTree)getFirstLevelTree(LibraryTree.ROOT_FOUND);
|
final SearchResultsTree found = (SearchResultsTree)getFirstLevelTree(LibraryTree.ROOT_FOUND);
|
||||||
if (found != null && book.matches(found.getPattern())) {
|
if (found != null && book.matches(found.getPattern())) {
|
||||||
|
@ -211,7 +199,6 @@ public final class Library {
|
||||||
Collection.saveBook(book, true);
|
Collection.saveBook(book, true);
|
||||||
myBooks.remove(book.getId());
|
myBooks.remove(book.getId());
|
||||||
removeFromTree(LibraryTree.ROOT_FOUND, book);
|
removeFromTree(LibraryTree.ROOT_FOUND, book);
|
||||||
removeFromTree(LibraryTree.ROOT_BY_TITLE, book);
|
|
||||||
addBookToLibrary(book);
|
addBookToLibrary(book);
|
||||||
fireModelChangedEvent(ChangeListener.Code.BookAdded);
|
fireModelChangedEvent(ChangeListener.Code.BookAdded);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,13 @@ import org.geometerplus.fbreader.tree.FBTree;
|
||||||
|
|
||||||
public abstract class LibraryTree extends FBTree {
|
public abstract class LibraryTree extends FBTree {
|
||||||
public static final String ROOT_FOUND = "found";
|
public static final String ROOT_FOUND = "found";
|
||||||
public static final String ROOT_FAVORITES = "favorites";
|
static final String ROOT_FAVORITES = "favorites";
|
||||||
public static final String ROOT_RECENT = "recent";
|
static final String ROOT_RECENT = "recent";
|
||||||
public static final String ROOT_BY_AUTHOR = "byAuthor";
|
static final String ROOT_BY_AUTHOR = "byAuthor";
|
||||||
public static final String ROOT_BY_TITLE = "byTitle";
|
static final String ROOT_BY_TITLE = "byTitle";
|
||||||
public static final String ROOT_BY_SERIES = "bySeries";
|
static final String ROOT_BY_SERIES = "bySeries";
|
||||||
public static final String ROOT_BY_TAG = "byTag";
|
static final String ROOT_BY_TAG = "byTag";
|
||||||
public static final String ROOT_FILE_TREE = "fileTree";
|
static final String ROOT_FILE_TREE = "fileTree";
|
||||||
|
|
||||||
public final IBookCollection Collection;
|
public final IBookCollection Collection;
|
||||||
|
|
||||||
|
@ -74,16 +74,6 @@ public abstract class LibraryTree extends FBTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TitleTree getTitleSubTree(String title) {
|
|
||||||
final TitleTree temp = new TitleTree(Collection, title);
|
|
||||||
int position = Collections.binarySearch(subTrees(), temp);
|
|
||||||
if (position >= 0) {
|
|
||||||
return (TitleTree)subTrees().get(position);
|
|
||||||
} else {
|
|
||||||
return new TitleTree(this, title, - position - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean createBookWithAuthorsSubTree(Book book) {
|
boolean createBookWithAuthorsSubTree(Book book) {
|
||||||
final BookWithAuthorsTree temp = new BookWithAuthorsTree(Collection, book);
|
final BookWithAuthorsTree temp = new BookWithAuthorsTree(Collection, book);
|
||||||
int position = Collections.binarySearch(subTrees(), temp);
|
int position = Collections.binarySearch(subTrees(), temp);
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.library;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
class SearchResultsTree extends FirstLevelTree {
|
public class SearchResultsTree extends FirstLevelTree {
|
||||||
private final String myPattern;
|
private final String myPattern;
|
||||||
|
|
||||||
SearchResultsTree(RootTree root, String id, String pattern) {
|
SearchResultsTree(RootTree root, String id, String pattern) {
|
||||||
|
|
97
src/org/geometerplus/fbreader/library/TitleListTree.java
Normal file
97
src/org/geometerplus/fbreader/library/TitleListTree.java
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
/*
|
||||||
|
* 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.*;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.book.Book;
|
||||||
|
import org.geometerplus.fbreader.book.BookEvent;
|
||||||
|
|
||||||
|
public class TitleListTree extends FirstLevelTree {
|
||||||
|
private boolean myDoGroupByFirstLetter;
|
||||||
|
|
||||||
|
TitleListTree(RootTree root) {
|
||||||
|
super(root, ROOT_BY_TITLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status getOpeningStatus() {
|
||||||
|
return Status.ALWAYS_RELOAD_BEFORE_OPENING;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void waitForOpening() {
|
||||||
|
clear();
|
||||||
|
|
||||||
|
myDoGroupByFirstLetter = false;
|
||||||
|
final TreeSet<String> letterSet = new TreeSet<String>();
|
||||||
|
final List<String> titles = Collection.titles();
|
||||||
|
if (titles.size() > 10) {
|
||||||
|
for (String t : titles) {
|
||||||
|
final String letter = TitleTree.firstTitleLetter(t);
|
||||||
|
if (letter != null) {
|
||||||
|
letterSet.add(letter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
myDoGroupByFirstLetter = titles.size() > letterSet.size() * 5 / 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (myDoGroupByFirstLetter) {
|
||||||
|
for (String letter : letterSet) {
|
||||||
|
createTitleSubTree(letter);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (Book b : Collection.books()) {
|
||||||
|
createBookWithAuthorsSubTree(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBookEvent(BookEvent event, Book book) {
|
||||||
|
switch (event) {
|
||||||
|
case Added:
|
||||||
|
if (myDoGroupByFirstLetter) {
|
||||||
|
final String letter = TitleTree.firstTitleLetter(book);
|
||||||
|
return letter != null && createTitleSubTree(letter);
|
||||||
|
} else {
|
||||||
|
return createBookWithAuthorsSubTree(book);
|
||||||
|
}
|
||||||
|
case Removed:
|
||||||
|
// TODO: implement
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
case Updated:
|
||||||
|
// TODO: implement
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean createTitleSubTree(String title) {
|
||||||
|
final TitleTree temp = new TitleTree(Collection, title);
|
||||||
|
int position = Collections.binarySearch(subTrees(), temp);
|
||||||
|
if (position >= 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
new TitleTree(this, title, - position - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,7 +27,10 @@ public final class TitleTree extends LibraryTree {
|
||||||
if (book == null) {
|
if (book == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String title = book.getTitle();
|
return firstTitleLetter(book.getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
static String firstTitleLetter(String title) {
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue