1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 18:29:23 +02:00

Book.save() is not public now

This commit is contained in:
Nikolay Pultsin 2013-01-13 08:31:54 +04:00
parent 8a78a11bd8
commit bb451e9467
10 changed files with 38 additions and 25 deletions

View file

@ -389,7 +389,7 @@ public final class FBReader extends ZLAndroidActivity {
private void onPreferencesUpdate(int resultCode, Book book) {
if (book != null) {
book.save(true);
getCollection().saveBook(book, true);
}
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
switch (resultCode) {

View file

@ -149,6 +149,17 @@ public class BookCollectionShadow implements IBookCollection, ServiceConnection
}
}
public synchronized boolean saveBook(Book book, boolean force) {
if (myInterface == null) {
return false;
}
try {
return myInterface.saveBook(SerializerUtil.serialize(book), force);
} catch (RemoteException e) {
return false;
}
}
public synchronized void removeBook(Book book, boolean deleteFromDisk) {
if (myInterface != null) {
try {

View file

@ -15,6 +15,7 @@ interface LibraryInterface {
String getBookById(in long id);
String getRecentBook(in int index);
boolean saveBook(in String book, in boolean force);
void removeBook(in String book, in boolean deleteFromDisk);
void addBookToRecentList(in String book);
void setBookFavorite(in String book, in boolean favorite);

View file

@ -151,6 +151,10 @@ public class LibraryService extends Service {
return SerializerUtil.serialize(myCollection.getBookById(id));
}
public boolean saveBook(String book, boolean force) {
return myCollection.saveBook(SerializerUtil.deserializeBook(book), force);
}
public void removeBook(String book, boolean deleteFromDisk) {
myCollection.removeBook(SerializerUtil.deserializeBook(book), deleteFromDisk);
}

View file

@ -328,15 +328,11 @@ public class Book {
return false;
}
public boolean save() {
return save(false);
}
public boolean save(boolean force) {
boolean save(final BooksDatabase database, boolean force) {
if (!force && myIsSaved) {
return false;
}
final BooksDatabase database = BooksDatabase.Instance();
database.executeAsATransaction(new Runnable() {
public void run() {
if (myId >= 0) {
@ -344,7 +340,11 @@ public class Book {
database.updateBookInfo(myId, fileInfos.getId(File), myEncoding, myLanguage, myTitle);
} else {
myId = database.insertBookInfo(File, myEncoding, myLanguage, myTitle);
storeAllVisitedHyperinks();
if (myId != -1 && myVisitedHyperlinks != null) {
for (String linkId : myVisitedHyperlinks) {
database.addVisitedHyperlink(myId, linkId);
}
}
}
long index = 0;
@ -399,14 +399,6 @@ public class Book {
}
}
private void storeAllVisitedHyperinks() {
if (myId != -1 && myVisitedHyperlinks != null) {
for (String linkId : myVisitedHyperlinks) {
BooksDatabase.Instance().addVisitedHyperlink(myId, linkId);
}
}
}
public String getContentHashCode() {
InputStream stream = null;

View file

@ -89,7 +89,7 @@ public class BookCollection implements IBookCollection {
final FileInfoSet fileInfos = new FileInfoSet(bookFile);
book = BooksDatabase.Instance().loadBookByFile(fileInfos.getId(bookFile), bookFile);
book = myDatabase.loadBookByFile(fileInfos.getId(bookFile), bookFile);
if (book != null) {
book.loadLists();
}
@ -110,7 +110,7 @@ public class BookCollection implements IBookCollection {
return null;
}
book.save();
saveBook(book, false);
addBook(book);
return book;
}
@ -121,7 +121,7 @@ public class BookCollection implements IBookCollection {
return book;
}
book = BooksDatabase.Instance().loadBook(id);
book = myDatabase.loadBook(id);
if (book == null) {
return null;
}
@ -171,6 +171,10 @@ public class BookCollection implements IBookCollection {
}
}
public boolean saveBook(Book book, boolean force) {
return book.save(myDatabase, force);
}
public void removeBook(Book book, boolean deleteFromDisk) {
synchronized (myBooksByFile) {
myBooksByFile.remove(book.File);
@ -320,7 +324,7 @@ public class BookCollection implements IBookCollection {
if (!fileInfos.check(file, true)) {
try {
book.readMetaInfo();
book.save();
saveBook(book, false);
} catch (BookReadingException e) {
doAdd = false;
}
@ -374,7 +378,7 @@ public class BookCollection implements IBookCollection {
myDatabase.executeAsATransaction(new Runnable() {
public void run() {
for (Book book : newBooks) {
book.save();
saveBook(book, false);
addBookById(book);
}
}
@ -469,13 +473,13 @@ public class BookCollection implements IBookCollection {
public void saveBookmark(Bookmark bookmark) {
if (bookmark != null) {
bookmark.setId(BooksDatabase.Instance().saveBookmark(bookmark));
bookmark.setId(myDatabase.saveBookmark(bookmark));
}
}
public void deleteBookmark(Bookmark bookmark) {
if (bookmark != null && bookmark.getId() != -1) {
BooksDatabase.Instance().deleteBookmark(bookmark);
myDatabase.deleteBookmark(bookmark);
}
}

View file

@ -54,6 +54,7 @@ public interface IBookCollection {
Book getBookById(long id);
Book getRecentBook(int index);
boolean saveBook(Book book, boolean force);
void removeBook(Book book, boolean deleteFromDisk);
void addBookToRecentList(Book book);
void setBookFavorite(Book book, boolean favorite);

View file

@ -258,6 +258,7 @@ public final class FBReaderApp extends ZLApplication {
System.gc();
try {
Model = BookModel.createModel(book);
Collection.saveBook(book, false);
ZLTextHyphenator.Instance().load(book.getLanguage());
BookTextView.setModel(Model.getTextModel());
BookTextView.gotoPosition(book.getStoredPosition());

View file

@ -58,7 +58,6 @@ public class NativeFormatPlugin extends FormatPlugin {
@Override
public void detectLanguageAndEncoding(Book book) {
detectLanguageAndEncodingNative(book);
book.save(false);
}
public native void detectLanguageAndEncodingNative(Book book);

View file

@ -243,7 +243,7 @@ public final class Library {
return;
}
book.save(true);
myCollection.saveBook(book, true);
refreshInTree(ROOT_FAVORITES, book);
refreshInTree(ROOT_RECENT, book);
removeFromTree(ROOT_FOUND, book);