mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
synchronization with library-service branch
This commit is contained in:
parent
8b9530c36b
commit
42b9345d5a
3 changed files with 30 additions and 32 deletions
|
@ -70,13 +70,11 @@ public class LibraryService extends Service implements Library.ChangeListener {
|
||||||
System.err.println("LibraryService.onCreate()");
|
System.err.println("LibraryService.onCreate()");
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
myLibrary = new LibraryImplementation();
|
myLibrary = new LibraryImplementation();
|
||||||
myLibrary.myBaseLibrary.addChangeListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
System.err.println("LibraryService.onDestroy()");
|
System.err.println("LibraryService.onDestroy()");
|
||||||
myLibrary.myBaseLibrary.removeChangeListener(this);
|
|
||||||
myLibrary = null;
|
myLibrary = null;
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,36 +22,6 @@ package org.geometerplus.fbreader.library;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public abstract class AbstractLibrary {
|
public abstract class AbstractLibrary {
|
||||||
private final List<ChangeListener> myListeners = Collections.synchronizedList(new LinkedList<ChangeListener>());
|
|
||||||
|
|
||||||
public interface ChangeListener {
|
|
||||||
public enum Code {
|
|
||||||
BookAdded,
|
|
||||||
BookRemoved,
|
|
||||||
StatusChanged,
|
|
||||||
Found,
|
|
||||||
NotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
void onLibraryChanged(Code code);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addChangeListener(ChangeListener listener) {
|
|
||||||
myListeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeChangeListener(ChangeListener listener) {
|
|
||||||
myListeners.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void fireModelChangedEvent(ChangeListener.Code code) {
|
|
||||||
synchronized (myListeners) {
|
|
||||||
for (ChangeListener l : myListeners) {
|
|
||||||
l.onLibraryChanged(code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract boolean isUpToDate();
|
public abstract boolean isUpToDate();
|
||||||
|
|
||||||
public static final int REMOVE_DONT_REMOVE = 0x00;
|
public static final int REMOVE_DONT_REMOVE = 0x00;
|
||||||
|
|
|
@ -52,6 +52,36 @@ public final class Library extends AbstractLibrary {
|
||||||
return ourInstance;
|
return ourInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final List<ChangeListener> myListeners = Collections.synchronizedList(new LinkedList<ChangeListener>());
|
||||||
|
|
||||||
|
public interface ChangeListener {
|
||||||
|
public enum Code {
|
||||||
|
BookAdded,
|
||||||
|
BookRemoved,
|
||||||
|
StatusChanged,
|
||||||
|
Found,
|
||||||
|
NotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
void onLibraryChanged(Code code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addChangeListener(ChangeListener listener) {
|
||||||
|
myListeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeChangeListener(ChangeListener listener) {
|
||||||
|
myListeners.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fireModelChangedEvent(ChangeListener.Code code) {
|
||||||
|
synchronized (myListeners) {
|
||||||
|
for (ChangeListener l : myListeners) {
|
||||||
|
l.onLibraryChanged(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final BooksDatabase myDatabase;
|
private final BooksDatabase myDatabase;
|
||||||
|
|
||||||
private final Map<ZLFile,Book> myBooks =
|
private final Map<ZLFile,Book> myBooks =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue