Skip to content

Commit

Permalink
Fix #259: update cover thumbnail handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Nandaka committed Nov 1, 2016
1 parent 42f3b34 commit 1a4c017
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ private void setupCoverImage(View synopsis) {
ImageView ImageViewCover = (ImageView) synopsis.findViewById(R.id.cover);
if (novelCol.getCoverBitmap() == null) {
// IN app test, is returning empty bitmap
Toast.makeText(getActivity(), getResources().getString(R.string.toast_err_bitmap_empty), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), getResources().getString(R.string.toast_err_bitmap_empty, novelCol.getCover()), Toast.LENGTH_LONG).show();
} else {
ImageViewCover.setOnClickListener(new OnClickListener() {

Expand Down
24 changes: 13 additions & 11 deletions app/src/main/java/com/erakk/lnreader/dao/NovelsDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,19 @@ public NovelCollectionModel getNovelDetailsFromInternet(PageModel page, ICallbac
if (novel != null) {
page = updateNovelDetailsPageModel(page, notifier, novel);

// download cover image
if (novel.getCoverUrl() != null) {
if (notifier != null) {
String message = context.getResources().getString(R.string.load_novel_cover_image);
notifier.onProgressCallback(new CallbackEventData(message, TAG));
}
DownloadFileTask task = new DownloadFileTask(novel.getCoverUrl(), page.getPage(), notifier);
ImageModel image = task.downloadImage();
Log.d(TAG, "Cover Image: " + image.toString() + " path: " + image.getPath());
// update cover filepath
novel.setCover(image.getName());
}

synchronized (dbh) {
// insert to DB and get saved value
SQLiteDatabase db = dbh.getWritableDatabase();
Expand Down Expand Up @@ -962,17 +975,6 @@ public NovelCollectionModel getNovelDetailsFromInternet(PageModel page, ICallbac
pageModel = updatePageModel(pageModel);
}

// download cover image
if (novel.getCoverUrl() != null) {
if (notifier != null) {
String message = context.getResources().getString(R.string.load_novel_cover_image);
notifier.onProgressCallback(new CallbackEventData(message, TAG));
}
DownloadFileTask task = new DownloadFileTask(novel.getCoverUrl(), page.getPage(), notifier);
ImageModel image = task.downloadImage();
Log.d(TAG, "Cover Image: " + image.toString());
}

Log.d(TAG, "Complete getting Novel Details from internet: " + page.getPage());
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public void setBookCollections(ArrayList<BookModel> bookCollections) {
public URL getCoverUrl() {
if (this.coverUrl == null && this.cover != null && this.cover.length() > 0) {
try {
if(this.cover.startsWith("/")) {
this.cover = "file://" + this.cover;
}
this.coverUrl = new URL(this.cover);
} catch (MalformedURLException e) {
Log.e(TAG, "Invalid url: " + this.cover, e);
Expand All @@ -94,13 +97,12 @@ public Bitmap getCoverBitmap() {
try {
// TODO: maybe it is better to use ImageModel
if (getCoverUrl() != null) {
@SuppressWarnings("deprecation")
String filepath = UIHelper.getImageRoot(LNReaderApplication.getInstance().getApplicationContext()) + Util.sanitizeFilename(URLDecoder.decode(getCoverUrl().getFile()));
Log.d("GetCover", filepath);
Log.d(TAG, "Cover: " + filepath);
this.coverBitmap = BitmapFactory.decodeFile(filepath);
}
} catch (Exception e) {
Log.e("GetCover", e.getClass().toString() + ": " + e.getMessage(), e);
Log.e(TAG, e.getClass().toString() + ": " + e.getMessage(), e);
}
}
// Redimension image so they all have a constant size
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/erakk/lnreader/parser/CommonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public static String sanitize(String title, boolean isAggresive) {
.replaceAll("\\(PDF\\)", "") // Strip (PDF)
.replaceAll("\\(Full Text.*\\)| - Full Text", ""); // strip (Full Text)
title = title.trim();
if(title.endsWith("-")){
title = title.substring(0, title.length()-1);
if (title.endsWith("-")) {
title = title.substring(0, title.length() - 1);
title = title.trim();
}
Log.v(TAG, "After: " + title);
Expand Down Expand Up @@ -338,6 +338,11 @@ public static String getImageFilePageFromImageUrl(String imageUrl) {
if (imageUrl.contains("/thumb/")) {
// from thumbnail
pageUrl = tokens[8];
} else if (imageUrl.contains("/thumbs/")) {
// from new thumbnail
// /storage/emulated/0/.bakareaderex2/project/thumbs/S/Survey_cover-300px.jpg
pageUrl = tokens[tokens.length-1];
pageUrl = pageUrl.replaceAll("-\\d+px","");
} else if (imageUrl.contains("/thumb.php?")) {
String[] temp = imageUrl.split("f=");
temp = temp[1].split("&");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public ImageModel downloadImage(URL imageUrl, String parent) throws Exception {
}

ImageModel image = new ImageModel();
image.setName(imageUrl.getFile());
image.setName(filename);
image.setUrl(imageUrl);
image.setPath(filepath);
image.setLastCheck(new Date());
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
<string name="toast_download_finish_with_error">%1$s %2$s\'s download finished with error(s)!</string>
<string name="toast_add_watch">Added to watch list: %1$s</string>
<string name="toast_remove_watch">Removed from watch list: %1$s</string>
<string name="toast_err_bitmap_empty">Bitmap empty</string>
<string name="toast_err_bitmap_empty">Bitmap empty %s</string>
<string name="error_setting_chapter_list">Error when setting up chapter list: %1$s</string>
<string name="error_empty_download_array">No item to be added into Download List</string>
<string name="hide_empty_volume_title">Hide Empty Volume</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
<string name="toast_download_finish_with_error">%1$s %2$s\'s download finished with error(s)!</string>
<string name="toast_add_watch">Added to watch list: %1$s</string>
<string name="toast_remove_watch">Removed from watch list: %1$s</string>
<string name="toast_err_bitmap_empty">Bitmap empty</string>
<string name="toast_err_bitmap_empty">Bitmap empty: %s</string>
<string name="error_setting_chapter_list">Error when setting up chapter list: %1$s</string>
<string name="error_empty_download_array">No item to be added into Download List</string>
<string name="hide_empty_volume_title">Hide Empty Volume</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
<string name="toast_download_finish_with_error">%1$s %2$s\'s download finished with error(s)!</string>
<string name="toast_add_watch">Added to watch list: %1$s</string>
<string name="toast_remove_watch">Removed from watch list: %1$s</string>
<string name="toast_err_bitmap_empty">Bitmap empty</string>
<string name="toast_err_bitmap_empty">Bitmap empty: %s</string>
<string name="error_setting_chapter_list">Error when setting up chapter list: %1$s</string>
<string name="error_empty_download_array">No item to be added into Download List</string>
<string name="hide_empty_volume_title">Hide Empty Volume</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
<string name="toast_download_finish_with_error">%1$s %2$s\ Pobierań zakończonych z błędami!</string>
<string name="toast_add_watch">Dodano do Obserwowanych: %1$s</string>
<string name="toast_remove_watch">Usunięto z Obserwowanych: %1$s</string>
<string name="toast_err_bitmap_empty">Pusta Bitmapa</string>
<string name="toast_err_bitmap_empty">Pusta Bitmapa %s</string>
<string name="error_setting_chapter_list">Błąd przy pobieraniu listy rozdziałów: %1$s</string>
<string name="error_empty_download_array">Brak materiałów do Pobierania</string>
<string name="hide_empty_volume_title">Ukryj puste tomy</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<string name="toast_download_finish_with_error">%1$s %2$s\'s download finished with error(s)!</string>
<string name="toast_add_watch">Added to watch list: %1$s</string>
<string name="toast_remove_watch">Removed from watch list: %1$s</string>
<string name="toast_err_bitmap_empty">Bitmap empty</string>
<string name="toast_err_bitmap_empty">Bitmap empty: %s</string>
<string name="error_setting_chapter_list">Error when setting up chapter list: %1$s</string>
<string name="error_empty_download_array">No item to be added into Download List</string>
<string name="hide_empty_volume_title">Hide Empty Volume</string>
Expand Down

0 comments on commit 1a4c017

Please sign in to comment.