1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 19:42:17 +02:00
This commit is contained in:
lidoxod 2013-07-27 21:13:20 +04:00
parent f47a6ddf46
commit 5c006fa0c8
5 changed files with 71 additions and 71 deletions

View file

@ -383,6 +383,19 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
}
}
@Override
public synchronized boolean saveCover(Book book, String url) {
if (myInterface == null) {
return false;
}
try {
return myInterface.saveCover(SerializerUtil.serialize(book), url);
} catch (RemoteException e) {
e.printStackTrace();
return false;
}
}
public synchronized List<Bookmark> bookmarks(BookmarkQuery query) {
if (myInterface == null) {
return Collections.emptyList();
@ -464,17 +477,4 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
// method from ServiceConnection interface
public synchronized void onServiceDisconnected(ComponentName name) {
}
@Override
public synchronized boolean saveCover(Book book, String url) {
if (myInterface == null) {
return false;
}
try {
return myInterface.saveCover(SerializerUtil.serialize(book), url);
} catch (RemoteException e) {
e.printStackTrace();
return false;
}
}
}

View file

@ -41,6 +41,8 @@ interface LibraryInterface {
boolean isHyperlinkVisited(in String book, in String linkId);
void markHyperlinkAsVisited(in String book, in String linkId);
boolean saveCover(in String book, in String url);
List<String> bookmarks(in String query);
String saveBookmark(in String bookmark);
void deleteBookmark(in String bookmark);
@ -48,6 +50,4 @@ interface LibraryInterface {
String getHighlightingStyle(in int styleId);
List<String> highlightingStyles();
void saveHighlightingStyle(in String style);
boolean saveCover(in String book, in String url);
}

View file

@ -246,6 +246,11 @@ public class LibraryService extends Service {
myCollection.markHyperlinkAsVisited(SerializerUtil.deserializeBook(book), linkId);
}
@Override
public boolean saveCover(String book, String url) {
return myCollection.saveCover(SerializerUtil.deserializeBook(book), url);
}
public List<String> bookmarks(String query) {
return SerializerUtil.serializeBookmarkList(myCollection.bookmarks(
SerializerUtil.deserializeBookmarkQuery(query)
@ -273,11 +278,6 @@ public class LibraryService extends Service {
public void saveHighlightingStyle(String style) {
myCollection.saveHighlightingStyle(SerializerUtil.deserializeStyle(style));
}
@Override
public boolean saveCover(String book, String url) {
return myCollection.saveCover(SerializerUtil.deserializeBook(book), url);
}
}
private volatile LibraryImplementation myLibrary;

View file

@ -615,6 +615,55 @@ public class BookCollection extends AbstractBookCollection {
}
}
@Override
public boolean saveCover(Book book, String url) {
if (getBookById(book.getId()) == null) {
return false;
}
final ZLImage image = BookUtil.getCover(book);
if (image == null) {
return false;
}
if (image instanceof ZLLoadableImage) {
final ZLLoadableImage loadableImage = (ZLLoadableImage)image;
if (!loadableImage.isSynchronized()) {
loadableImage.synchronize();
}
}
final ZLAndroidImageData data =
((ZLAndroidImageManager)ZLAndroidImageManager.Instance()).getImageData(image);
if (data == null) {
return false;
}
final Bitmap coverBitmap = data.getFullSizeBitmap();
if (coverBitmap == null) {
return false;
}
OutputStream outputStream = null;
final File file = new File(url);
final File parent = file.getParentFile();
parent.mkdirs();
try {
outputStream = new FileOutputStream(file);
coverBitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return true;
}
public List<Bookmark> bookmarks(BookmarkQuery query) {
return myDatabase.loadBookmarks(query);
}
@ -686,53 +735,4 @@ public class BookCollection extends AbstractBookCollection {
myDatabase.saveStyle(style);
fireBookEvent(BookEvent.BookmarkStyleChanged, null);
}
@Override
public boolean saveCover(Book book, String url) {
if (getBookById(book.getId()) == null) {
return false;
}
final ZLImage image = BookUtil.getCover(book);
if (image == null) {
return false;
}
if (image instanceof ZLLoadableImage) {
final ZLLoadableImage loadableImage = (ZLLoadableImage)image;
if (!loadableImage.isSynchronized()) {
loadableImage.synchronize();
}
}
final ZLAndroidImageData data =
((ZLAndroidImageManager)ZLAndroidImageManager.Instance()).getImageData(image);
if (data == null) {
return false;
}
final Bitmap coverBitmap = data.getFullSizeBitmap();
if (coverBitmap == null) {
return false;
}
OutputStream outputStream = null;
final File file = new File(url);
final File parent = file.getParentFile();
parent.mkdirs();
try {
outputStream = new FileOutputStream(file);
coverBitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return true;
}
}

View file

@ -79,6 +79,8 @@ public interface IBookCollection {
boolean isHyperlinkVisited(Book book, String linkId);
void markHyperlinkAsVisited(Book book, String linkId);
boolean saveCover(Book book, String url);
List<Bookmark> bookmarks(BookmarkQuery query);
void saveBookmark(Bookmark bookmark);
void deleteBookmark(Bookmark bookmark);
@ -86,6 +88,4 @@ public interface IBookCollection {
HighlightingStyle getHighlightingStyle(int styleId);
List<HighlightingStyle> highlightingStyles();
void saveHighlightingStyle(HighlightingStyle style);
boolean saveCover(Book book, String url);
}