mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
file observer (in progress, works with file adding)
This commit is contained in:
parent
1e2f1642ae
commit
75943b17bb
4 changed files with 93 additions and 50 deletions
|
@ -44,8 +44,13 @@ public class LibraryService extends Service {
|
|||
private static final int MASK =
|
||||
MOVE_SELF | MOVED_TO | MOVED_FROM | DELETE_SELF | DELETE | CLOSE_WRITE | ATTRIB;
|
||||
|
||||
public Observer(String path) {
|
||||
private final String myPrefix;
|
||||
private final BookCollection myCollection;
|
||||
|
||||
public Observer(String path, BookCollection collection) {
|
||||
super(path, MASK);
|
||||
myPrefix = path + '/';
|
||||
myCollection = collection;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,21 +62,21 @@ public class LibraryService extends Service {
|
|||
// TODO: File(path) removed; stop watching (?)
|
||||
break;
|
||||
case MOVED_TO:
|
||||
// TODO: File(path) removed; File(path) added
|
||||
myCollection.rescan(myPrefix + path);
|
||||
break;
|
||||
case MOVED_FROM:
|
||||
case DELETE:
|
||||
// TODO: File(path) removed
|
||||
myCollection.rescan(myPrefix + path);
|
||||
break;
|
||||
case DELETE_SELF:
|
||||
// TODO: File(path) removed; watching is stopped automatically (?)
|
||||
break;
|
||||
case CLOSE_WRITE:
|
||||
case ATTRIB:
|
||||
// TODO: File(path) changed (added, removed?)
|
||||
myCollection.rescan(myPrefix + path);
|
||||
break;
|
||||
default:
|
||||
System.err.println("Unexpected event " + event + " on " + path);
|
||||
System.err.println("Unexpected event " + event + " on " + myPrefix + path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +89,7 @@ public class LibraryService extends Service {
|
|||
LibraryImplementation() {
|
||||
myCollection = new BookCollection(SQLiteBooksDatabase.Instance(LibraryService.this));
|
||||
for (String path : myCollection.bookDirectories()) {
|
||||
final Observer observer = new Observer(path);
|
||||
final Observer observer = new Observer(path, myCollection);
|
||||
observer.startWatching();
|
||||
myFileObservers.add(observer);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue