mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
Book.getByFile() => IBookCollection.getBookByFile()
This commit is contained in:
parent
2ec3c907af
commit
bc3976f5f6
12 changed files with 138 additions and 92 deletions
|
@ -26,6 +26,8 @@ import android.content.*;
|
|||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
|
||||
import org.geometerplus.fbreader.library.*;
|
||||
|
||||
public class BookCollectionShadow implements IBookCollection, ServiceConnection {
|
||||
|
@ -37,16 +39,21 @@ public class BookCollectionShadow implements IBookCollection, ServiceConnection
|
|||
myContext = context;
|
||||
}
|
||||
|
||||
public void bindToService(Runnable onBindAction) {
|
||||
public synchronized void bindToService(Runnable onBindAction) {
|
||||
if (myInterface != null) {
|
||||
return;
|
||||
if (onBindAction != null) {
|
||||
onBindAction.run();
|
||||
}
|
||||
} else {
|
||||
if (onBindAction != null) {
|
||||
myOnBindAction = onBindAction;
|
||||
}
|
||||
myContext.bindService(
|
||||
new Intent(myContext, LibraryService.class),
|
||||
this,
|
||||
LibraryService.BIND_AUTO_CREATE
|
||||
);
|
||||
}
|
||||
myOnBindAction = onBindAction;
|
||||
myContext.bindService(
|
||||
new Intent(myContext, LibraryService.class),
|
||||
this,
|
||||
LibraryService.BIND_AUTO_CREATE
|
||||
);
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
|
@ -120,6 +127,17 @@ public class BookCollectionShadow implements IBookCollection, ServiceConnection
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized Book getBookByFile(ZLFile file) {
|
||||
if (myInterface == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return SerializerUtil.deserializeBook(myInterface.getBookByFile(file.getPath()));
|
||||
} catch (RemoteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized Book getBookById(long id) {
|
||||
if (myInterface == null) {
|
||||
return null;
|
||||
|
@ -207,6 +225,7 @@ public class BookCollectionShadow implements IBookCollection, ServiceConnection
|
|||
myInterface = LibraryInterface.Stub.asInterface(service);
|
||||
if (myOnBindAction != null) {
|
||||
myOnBindAction.run();
|
||||
myOnBindAction = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ interface LibraryInterface {
|
|||
List<String> books(String pattern);
|
||||
List<String> recentBooks();
|
||||
List<String> favorites();
|
||||
String getBookByFile(in String file);
|
||||
String getBookById(in long id);
|
||||
String getRecentBook(in int index);
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ import android.content.Intent;
|
|||
import android.os.IBinder;
|
||||
import android.os.FileObserver;
|
||||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
|
||||
import org.geometerplus.fbreader.library.*;
|
||||
|
||||
import org.geometerplus.android.fbreader.library.SQLiteBooksDatabase;
|
||||
|
@ -141,6 +143,10 @@ public class LibraryService extends Service {
|
|||
return SerializerUtil.serialize(myCollection.getRecentBook(index));
|
||||
}
|
||||
|
||||
public String getBookByFile(String file) {
|
||||
return SerializerUtil.serialize(myCollection.getBookByFile(ZLFile.createFileByPath(file)));
|
||||
}
|
||||
|
||||
public String getBookById(long id) {
|
||||
return SerializerUtil.serialize(myCollection.getBookById(id));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue