mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
Library extends AbstractLibrary
This commit is contained in:
parent
d65cb92f08
commit
9a6f8b2acc
2 changed files with 10 additions and 42 deletions
|
@ -188,7 +188,7 @@ public class LibraryActivity extends TreeActivity implements MenuItem.OnMenuItem
|
||||||
} else {
|
} else {
|
||||||
menu.add(0, ADD_TO_FAVORITES_ITEM_ID, 0, resource.getResource("addToFavorites").getValue());
|
menu.add(0, ADD_TO_FAVORITES_ITEM_ID, 0, resource.getResource("addToFavorites").getValue());
|
||||||
}
|
}
|
||||||
if ((myLibrary.getRemoveBookMode(book) & Library.REMOVE_FROM_DISK) != 0) {
|
if (myLibrary.canRemoveBookFile(book)) {
|
||||||
menu.add(0, DELETE_BOOK_ITEM_ID, 0, resource.getResource("deleteBook").getValue());
|
menu.add(0, DELETE_BOOK_ITEM_ID, 0, resource.getResource("deleteBook").getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,19 +32,7 @@ import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
import org.geometerplus.fbreader.Paths;
|
import org.geometerplus.fbreader.Paths;
|
||||||
|
|
||||||
public final class Library {
|
public final class Library extends AbstractLibrary {
|
||||||
public interface ChangeListener {
|
|
||||||
public enum Code {
|
|
||||||
BookAdded,
|
|
||||||
BookRemoved,
|
|
||||||
StatusChanged,
|
|
||||||
Found,
|
|
||||||
NotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
void onLibraryChanged(Code code);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String ROOT_FOUND = "found";
|
public static final String ROOT_FOUND = "found";
|
||||||
public static final String ROOT_FAVORITES = "favorites";
|
public static final String ROOT_FAVORITES = "favorites";
|
||||||
public static final String ROOT_RECENT = "recent";
|
public static final String ROOT_RECENT = "recent";
|
||||||
|
@ -70,8 +58,6 @@ public final class Library {
|
||||||
private final RootTree myRootTree = new RootTree(this);
|
private final RootTree myRootTree = new RootTree(this);
|
||||||
private boolean myDoGroupTitlesByFirstLetter;
|
private boolean myDoGroupTitlesByFirstLetter;
|
||||||
|
|
||||||
private final List<ChangeListener> myListeners = Collections.synchronizedList(new LinkedList<ChangeListener>());
|
|
||||||
|
|
||||||
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;
|
||||||
private volatile int myStatusMask = 0;
|
private volatile int myStatusMask = 0;
|
||||||
|
@ -98,14 +84,6 @@ public final class Library {
|
||||||
return (FirstLevelTree)myRootTree.getSubTree(key);
|
return (FirstLevelTree)myRootTree.getSubTree(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addChangeListener(ChangeListener listener) {
|
|
||||||
myListeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeChangeListener(ChangeListener listener) {
|
|
||||||
myListeners.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LibraryTree getLibraryTree(LibraryTree.Key key) {
|
public LibraryTree getLibraryTree(LibraryTree.Key key) {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -264,14 +242,6 @@ public final class Library {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireModelChangedEvent(ChangeListener.Code code) {
|
|
||||||
synchronized (myListeners) {
|
|
||||||
for (ChangeListener l : myListeners) {
|
|
||||||
l.onLibraryChanged(code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeFromTree(String rootId, Book book) {
|
private void removeFromTree(String rootId, Book book) {
|
||||||
final FirstLevelTree tree = getFirstLevelTree(rootId);
|
final FirstLevelTree tree = getFirstLevelTree(rootId);
|
||||||
if (tree != null) {
|
if (tree != null) {
|
||||||
|
@ -458,6 +428,7 @@ public final class Library {
|
||||||
builder.start();
|
builder.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isUpToDate() {
|
public boolean isUpToDate() {
|
||||||
return myStatusMask == 0;
|
return myStatusMask == 0;
|
||||||
}
|
}
|
||||||
|
@ -472,6 +443,7 @@ public final class Library {
|
||||||
return recentIds.size() > 1 ? Book.getById(recentIds.get(1)) : null;
|
return recentIds.size() > 1 ? Book.getById(recentIds.get(1)) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void startBookSearch(final String pattern) {
|
public void startBookSearch(final String pattern) {
|
||||||
setStatus(myStatusMask | STATUS_SEARCHING);
|
setStatus(myStatusMask | STATUS_SEARCHING);
|
||||||
final Thread searcher = new Thread("Library.searchBooks") {
|
final Thread searcher = new Thread("Library.searchBooks") {
|
||||||
|
@ -538,6 +510,7 @@ public final class Library {
|
||||||
db.saveRecentBookIds(ids);
|
db.saveRecentBookIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isBookInFavorites(Book book) {
|
public boolean isBookInFavorites(Book book) {
|
||||||
if (book == null) {
|
if (book == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -551,6 +524,7 @@ public final class Library {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addBookToFavorites(Book book) {
|
public void addBookToFavorites(Book book) {
|
||||||
if (isBookInFavorites(book)) {
|
if (isBookInFavorites(book)) {
|
||||||
return;
|
return;
|
||||||
|
@ -560,6 +534,7 @@ public final class Library {
|
||||||
BooksDatabase.Instance().addToFavorites(book.getId());
|
BooksDatabase.Instance().addToFavorites(book.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeBookFromFavorites(Book book) {
|
public void removeBookFromFavorites(Book book) {
|
||||||
if (getFirstLevelTree(ROOT_FAVORITES).removeBook(book, false)) {
|
if (getFirstLevelTree(ROOT_FAVORITES).removeBook(book, false)) {
|
||||||
BooksDatabase.Instance().removeFromFavorites(book.getId());
|
BooksDatabase.Instance().removeFromFavorites(book.getId());
|
||||||
|
@ -567,16 +542,8 @@ public final class Library {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int REMOVE_DONT_REMOVE = 0x00;
|
@Override
|
||||||
public static final int REMOVE_FROM_LIBRARY = 0x01;
|
public boolean canRemoveBookFile(Book book) {
|
||||||
public static final int REMOVE_FROM_DISK = 0x02;
|
|
||||||
public static final int REMOVE_FROM_LIBRARY_AND_DISK = REMOVE_FROM_LIBRARY | REMOVE_FROM_DISK;
|
|
||||||
|
|
||||||
public int getRemoveBookMode(Book book) {
|
|
||||||
return canDeleteBookFile(book) ? REMOVE_FROM_DISK : REMOVE_DONT_REMOVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canDeleteBookFile(Book book) {
|
|
||||||
ZLFile file = book.File;
|
ZLFile file = book.File;
|
||||||
if (file.getPhysicalFile() == null) {
|
if (file.getPhysicalFile() == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -590,6 +557,7 @@ public final class Library {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeBook(Book book, int removeMode) {
|
public void removeBook(Book book, int removeMode) {
|
||||||
if (removeMode == REMOVE_DONT_REMOVE) {
|
if (removeMode == REMOVE_DONT_REMOVE) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue