mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
BooksDatabase.Instance() should be never used
This commit is contained in:
parent
bb451e9467
commit
903ffec9d4
13 changed files with 150 additions and 49 deletions
|
@ -28,8 +28,13 @@ import android.os.RemoteException;
|
|||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
|
||||
import org.geometerplus.android.fbreader.api.TextPosition;
|
||||
|
||||
public class BookCollectionShadow implements IBookCollection, ServiceConnection {
|
||||
private final Context myContext;
|
||||
private volatile LibraryInterface myInterface;
|
||||
|
@ -187,6 +192,53 @@ public class BookCollectionShadow implements IBookCollection, ServiceConnection
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized ZLTextPosition getStoredPosition(long bookId) {
|
||||
if (myInterface == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
final TextPosition position = myInterface.getStoredPosition(bookId);
|
||||
return new ZLTextFixedPosition(
|
||||
position.ParagraphIndex, position.ElementIndex, position.CharIndex
|
||||
);
|
||||
} catch (RemoteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void storePosition(long bookId, ZLTextPosition position) {
|
||||
if (myInterface != null) {
|
||||
try {
|
||||
myInterface.storePosition(bookId, new TextPosition(
|
||||
position.getParagraphIndex(), position.getElementIndex(), position.getCharIndex()
|
||||
));
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean isHyperlinkVisited(Book book, String linkId) {
|
||||
if (myInterface == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return myInterface.isHyperlinkVisited(SerializerUtil.serialize(book), linkId);
|
||||
} catch (RemoteException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void markHyperlinkAsVisited(Book book, String linkId) {
|
||||
if (myInterface != null) {
|
||||
try {
|
||||
myInterface.markHyperlinkAsVisited(SerializerUtil.serialize(book), linkId);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized List<Bookmark> invisibleBookmarks(Book book) {
|
||||
if (myInterface == null) {
|
||||
return Collections.emptyList();
|
||||
|
|
|
@ -5,10 +5,11 @@
|
|||
package org.geometerplus.android.fbreader.libraryService;
|
||||
|
||||
import java.util.List;
|
||||
import org.geometerplus.android.fbreader.api.TextPosition;
|
||||
|
||||
interface LibraryInterface {
|
||||
int size();
|
||||
List<String> books(String pattern);
|
||||
List<String> books(in String pattern);
|
||||
List<String> recentBooks();
|
||||
List<String> favorites();
|
||||
String getBookByFile(in String file);
|
||||
|
@ -20,6 +21,12 @@ interface LibraryInterface {
|
|||
void addBookToRecentList(in String book);
|
||||
void setBookFavorite(in String book, in boolean favorite);
|
||||
|
||||
TextPosition getStoredPosition(in long bookId);
|
||||
void storePosition(in long bookId, in TextPosition position);
|
||||
|
||||
boolean isHyperlinkVisited(in String book, in String linkId);
|
||||
void markHyperlinkAsVisited(in String book, in String linkId);
|
||||
|
||||
List<String> invisibleBookmarks(in String book);
|
||||
List<String> allBookmarks();
|
||||
String saveBookmark(in String bookmark);
|
||||
|
|
|
@ -29,8 +29,12 @@ import android.os.FileObserver;
|
|||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
|
||||
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
|
||||
import org.geometerplus.android.fbreader.api.TextPosition;
|
||||
import org.geometerplus.android.fbreader.library.SQLiteBooksDatabase;
|
||||
|
||||
public class LibraryService extends Service {
|
||||
|
@ -167,6 +171,27 @@ public class LibraryService extends Service {
|
|||
myCollection.setBookFavorite(SerializerUtil.deserializeBook(book), favorite);
|
||||
}
|
||||
|
||||
public TextPosition getStoredPosition(long bookId) {
|
||||
final ZLTextPosition position = myCollection.getStoredPosition(bookId);
|
||||
return new TextPosition(
|
||||
position.getParagraphIndex(), position.getElementIndex(), position.getCharIndex()
|
||||
);
|
||||
}
|
||||
|
||||
public void storePosition(long bookId, TextPosition position) {
|
||||
myCollection.storePosition(bookId, new ZLTextFixedPosition(
|
||||
position.ParagraphIndex, position.ElementIndex, position.CharIndex
|
||||
));
|
||||
}
|
||||
|
||||
public boolean isHyperlinkVisited(String book, String linkId) {
|
||||
return myCollection.isHyperlinkVisited(SerializerUtil.deserializeBook(book), linkId);
|
||||
}
|
||||
|
||||
public void markHyperlinkAsVisited(String book, String linkId) {
|
||||
myCollection.markHyperlinkAsVisited(SerializerUtil.deserializeBook(book), linkId);
|
||||
}
|
||||
|
||||
public List<String> invisibleBookmarks(String book) {
|
||||
return SerializerUtil.serializeBookmarkList(
|
||||
myCollection.invisibleBookmarks(SerializerUtil.deserializeBook(book))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue