mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
Library extends AbstractLibrary
This commit is contained in:
parent
d65cb92f08
commit
9a6f8b2acc
2 changed files with 10 additions and 42 deletions
|
@ -32,19 +32,7 @@ import org.geometerplus.fbreader.formats.FormatPlugin;
|
|||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
import org.geometerplus.fbreader.Paths;
|
||||
|
||||
public final class Library {
|
||||
public interface ChangeListener {
|
||||
public enum Code {
|
||||
BookAdded,
|
||||
BookRemoved,
|
||||
StatusChanged,
|
||||
Found,
|
||||
NotFound
|
||||
}
|
||||
|
||||
void onLibraryChanged(Code code);
|
||||
}
|
||||
|
||||
public final class Library extends AbstractLibrary {
|
||||
public static final String ROOT_FOUND = "found";
|
||||
public static final String ROOT_FAVORITES = "favorites";
|
||||
public static final String ROOT_RECENT = "recent";
|
||||
|
@ -70,8 +58,6 @@ public final class Library {
|
|||
private final RootTree myRootTree = new RootTree(this);
|
||||
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_SEARCHING = 2;
|
||||
private volatile int myStatusMask = 0;
|
||||
|
@ -98,14 +84,6 @@ public final class Library {
|
|||
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) {
|
||||
if (key == 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) {
|
||||
final FirstLevelTree tree = getFirstLevelTree(rootId);
|
||||
if (tree != null) {
|
||||
|
@ -458,6 +428,7 @@ public final class Library {
|
|||
builder.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpToDate() {
|
||||
return myStatusMask == 0;
|
||||
}
|
||||
|
@ -472,6 +443,7 @@ public final class Library {
|
|||
return recentIds.size() > 1 ? Book.getById(recentIds.get(1)) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startBookSearch(final String pattern) {
|
||||
setStatus(myStatusMask | STATUS_SEARCHING);
|
||||
final Thread searcher = new Thread("Library.searchBooks") {
|
||||
|
@ -538,6 +510,7 @@ public final class Library {
|
|||
db.saveRecentBookIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBookInFavorites(Book book) {
|
||||
if (book == null) {
|
||||
return false;
|
||||
|
@ -551,6 +524,7 @@ public final class Library {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBookToFavorites(Book book) {
|
||||
if (isBookInFavorites(book)) {
|
||||
return;
|
||||
|
@ -560,6 +534,7 @@ public final class Library {
|
|||
BooksDatabase.Instance().addToFavorites(book.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBookFromFavorites(Book book) {
|
||||
if (getFirstLevelTree(ROOT_FAVORITES).removeBook(book, false)) {
|
||||
BooksDatabase.Instance().removeFromFavorites(book.getId());
|
||||
|
@ -567,16 +542,8 @@ public final class Library {
|
|||
}
|
||||
}
|
||||
|
||||
public static final int REMOVE_DONT_REMOVE = 0x00;
|
||||
public static final int REMOVE_FROM_LIBRARY = 0x01;
|
||||
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) {
|
||||
@Override
|
||||
public boolean canRemoveBookFile(Book book) {
|
||||
ZLFile file = book.File;
|
||||
if (file.getPhysicalFile() == null) {
|
||||
return false;
|
||||
|
@ -590,6 +557,7 @@ public final class Library {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBook(Book book, int removeMode) {
|
||||
if (removeMode == REMOVE_DONT_REMOVE) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue