From 5dcaeffa0ba23a032ae0ac7a2ba7f17689b0f3bf Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 28 Nov 2015 19:01:26 +0100 Subject: [PATCH 1/3] Fix an issue where the next chapter was the same as the current. Fix a NPE when page list throws --- .../mangafeed/data/database/DatabaseHelper.java | 12 ++++++++++-- .../kanade/mangafeed/ui/reader/ReaderActivity.java | 6 ++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java index 54d4ff1cd..b05e3c792 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java @@ -188,6 +188,10 @@ public class DatabaseHelper { } public PreparedGetListOfObjects getNextChapter(Chapter chapter) { + // Add a delta to the chapter number, because binary decimal representation + // can retrieve the same chapter again + double chapterNumber = chapter.chapter_number + 0.00001; + return db.get() .listOfObjects(Chapter.class) .withQuery(Query.builder() @@ -195,7 +199,7 @@ public class DatabaseHelper { .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + ChapterTable.COLUMN_CHAPTER_NUMBER + ">? AND " + ChapterTable.COLUMN_CHAPTER_NUMBER + "<=?") - .whereArgs(chapter.manga_id, chapter.chapter_number, chapter.chapter_number + 1) + .whereArgs(chapter.manga_id, chapterNumber, chapterNumber + 1) .orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER) .limit(1) .build()) @@ -203,6 +207,10 @@ public class DatabaseHelper { } public PreparedGetListOfObjects getPreviousChapter(Chapter chapter) { + // Add a delta to the chapter number, because binary decimal representation + // can retrieve the same chapter again + double chapterNumber = chapter.chapter_number - 0.00001; + return db.get() .listOfObjects(Chapter.class) .withQuery(Query.builder() @@ -210,7 +218,7 @@ public class DatabaseHelper { .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + ChapterTable.COLUMN_CHAPTER_NUMBER + "=?") - .whereArgs(chapter.manga_id, chapter.chapter_number, chapter.chapter_number - 1) + .whereArgs(chapter.manga_id, chapterNumber, chapterNumber - 1) .orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER + " DESC") .limit(1) .build()) diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java index acfa8f21e..9a9c84331 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java @@ -85,7 +85,8 @@ public class ReaderActivity extends BaseRxActivity { @Override protected void onDestroy() { readerMenu.destroy(); - viewer.destroy(); + if (viewer != null) + viewer.destroy(); super.onDestroy(); } @@ -97,7 +98,8 @@ public class ReaderActivity extends BaseRxActivity { @Override protected void onPause() { - getPresenter().setCurrentPage(viewer.getCurrentPosition()); + if (viewer != null) + getPresenter().setCurrentPage(viewer.getCurrentPosition()); super.onPause(); } From 34201bece1a837ddae62774032d33cb16b653c2e Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 28 Nov 2015 20:02:30 +0100 Subject: [PATCH 2/3] Support Batoto webtoons --- .../mangafeed/data/source/base/Source.java | 4 +- .../data/source/online/english/Batoto.java | 38 +++++++++++++++++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java b/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java index fd139584f..3e25bcf87 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java @@ -159,7 +159,7 @@ public abstract class Source extends BaseSource { mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages); } - private List convertToPages(List pageUrls) { + protected List convertToPages(List pageUrls) { List pages = new ArrayList<>(); for (int i = 0; i < pageUrls.size(); i++) { pages.add(new Page(i, pageUrls.get(i))); @@ -167,7 +167,7 @@ public abstract class Source extends BaseSource { return pages; } - private List getFirstImageFromPageUrls(List pageUrls, String unparsedHtml) { + protected List getFirstImageFromPageUrls(List pageUrls, String unparsedHtml) { List pages = convertToPages(pageUrls); String firstImage = parseHtmlToImageUrl(unparsedHtml); pages.get(0).setImageUrl(firstImage); diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java index 45e849c18..55a4cea44 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java @@ -21,11 +21,12 @@ import java.util.Date; import java.util.List; import java.util.Locale; -import eu.kanade.mangafeed.data.source.SourceManager; import eu.kanade.mangafeed.data.database.models.Chapter; import eu.kanade.mangafeed.data.database.models.Manga; +import eu.kanade.mangafeed.data.source.SourceManager; import eu.kanade.mangafeed.data.source.base.Source; import eu.kanade.mangafeed.data.source.model.MangasPage; +import eu.kanade.mangafeed.data.source.model.Page; import rx.Observable; public class Batoto extends Source { @@ -348,14 +349,43 @@ public class Batoto extends Source { List pageUrlList = new ArrayList<>(); - Elements pageUrlElements = parsedDocument.getElementById("page_select").getElementsByTag("option"); - for (Element pageUrlElement : pageUrlElements) { - pageUrlList.add(pageUrlElement.attr("value")); + Element selectElement = parsedDocument.select("#page_select").first(); + + if (selectElement != null) { + for (Element pageUrlElement : selectElement.select("option")) { + pageUrlList.add(pageUrlElement.attr("value")); + } + } else { + // For webtoons in one page + Element page = parsedDocument.select("div > a").first(); + String url = page.attr("href"); + url = BASE_URL + "/reader" + url.substring(0, url.length() - 1) + "f"; + + for (int i = 0; i < parsedDocument.select("div > img").size(); i++) { + pageUrlList.add(url); + } } return pageUrlList; } + @Override + protected List getFirstImageFromPageUrls(List pageUrls, String unparsedHtml) { + List pages = convertToPages(pageUrls); + if (!unparsedHtml.contains("Want to see this chapter per page instead?")) { + String firstImage = parseHtmlToImageUrl(unparsedHtml); + pages.get(0).setImageUrl(firstImage); + } else { + // For webtoons in one page + Document parsedDocument = Jsoup.parse(unparsedHtml); + Elements imageUrls = parsedDocument.select("div > img"); + for (int i = 0; i < pages.size(); i++) { + pages.get(i).setImageUrl(imageUrls.get(i).attr("src")); + } + } + return pages; + } + @Override protected String parseHtmlToImageUrl(String unparsedHtml) { int beginIndex = unparsedHtml.indexOf(" Date: Sat, 28 Nov 2015 20:11:56 +0100 Subject: [PATCH 3/3] Only preload pages without the image url --- .../java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java index 04de6ee1c..5cbe422c5 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java @@ -183,7 +183,9 @@ public class ReaderPresenter extends BasePresenter { int pagesToPreload = Math.min(pages.size(), 5); return Observable.from(pages) .take(pagesToPreload) - .concatMap(source::getImageUrlFromPage) + .concatMap(page -> page.getImageUrl() == null ? + source.getImageUrlFromPage(page) : + Observable.just(page)) .doOnCompleted(this::stopPreloadingNextChapter); }) .subscribeOn(Schedulers.io())