Merge remote-tracking branch 'inorichi/master'

This commit is contained in:
Yuri Revich 2015-11-28 22:12:39 +03:00
commit 3d5c8c992f
5 changed files with 53 additions and 11 deletions

View file

@ -188,6 +188,10 @@ public class DatabaseHelper {
} }
public PreparedGetListOfObjects<Chapter> getNextChapter(Chapter chapter) { public PreparedGetListOfObjects<Chapter> 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() return db.get()
.listOfObjects(Chapter.class) .listOfObjects(Chapter.class)
.withQuery(Query.builder() .withQuery(Query.builder()
@ -195,7 +199,7 @@ public class DatabaseHelper {
.where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " +
ChapterTable.COLUMN_CHAPTER_NUMBER + ">? AND " + ChapterTable.COLUMN_CHAPTER_NUMBER + ">? AND " +
ChapterTable.COLUMN_CHAPTER_NUMBER + "<=?") 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) .orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER)
.limit(1) .limit(1)
.build()) .build())
@ -203,6 +207,10 @@ public class DatabaseHelper {
} }
public PreparedGetListOfObjects<Chapter> getPreviousChapter(Chapter chapter) { public PreparedGetListOfObjects<Chapter> 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() return db.get()
.listOfObjects(Chapter.class) .listOfObjects(Chapter.class)
.withQuery(Query.builder() .withQuery(Query.builder()
@ -210,7 +218,7 @@ public class DatabaseHelper {
.where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " +
ChapterTable.COLUMN_CHAPTER_NUMBER + "<? AND " + ChapterTable.COLUMN_CHAPTER_NUMBER + "<? AND " +
ChapterTable.COLUMN_CHAPTER_NUMBER + ">=?") 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") .orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER + " DESC")
.limit(1) .limit(1)
.build()) .build())

View file

@ -159,7 +159,7 @@ public abstract class Source extends BaseSource {
mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages); mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages);
} }
private List<Page> convertToPages(List<String> pageUrls) { protected List<Page> convertToPages(List<String> pageUrls) {
List<Page> pages = new ArrayList<>(); List<Page> pages = new ArrayList<>();
for (int i = 0; i < pageUrls.size(); i++) { for (int i = 0; i < pageUrls.size(); i++) {
pages.add(new Page(i, pageUrls.get(i))); pages.add(new Page(i, pageUrls.get(i)));
@ -167,7 +167,7 @@ public abstract class Source extends BaseSource {
return pages; return pages;
} }
private List<Page> getFirstImageFromPageUrls(List<String> pageUrls, String unparsedHtml) { protected List<Page> getFirstImageFromPageUrls(List<String> pageUrls, String unparsedHtml) {
List<Page> pages = convertToPages(pageUrls); List<Page> pages = convertToPages(pageUrls);
String firstImage = parseHtmlToImageUrl(unparsedHtml); String firstImage = parseHtmlToImageUrl(unparsedHtml);
pages.get(0).setImageUrl(firstImage); pages.get(0).setImageUrl(firstImage);

View file

@ -21,11 +21,12 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; 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.Chapter;
import eu.kanade.mangafeed.data.database.models.Manga; 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.base.Source;
import eu.kanade.mangafeed.data.source.model.MangasPage; import eu.kanade.mangafeed.data.source.model.MangasPage;
import eu.kanade.mangafeed.data.source.model.Page;
import rx.Observable; import rx.Observable;
public class Batoto extends Source { public class Batoto extends Source {
@ -348,14 +349,43 @@ public class Batoto extends Source {
List<String> pageUrlList = new ArrayList<>(); List<String> pageUrlList = new ArrayList<>();
Elements pageUrlElements = parsedDocument.getElementById("page_select").getElementsByTag("option"); Element selectElement = parsedDocument.select("#page_select").first();
for (Element pageUrlElement : pageUrlElements) {
pageUrlList.add(pageUrlElement.attr("value")); 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; return pageUrlList;
} }
@Override
protected List<Page> getFirstImageFromPageUrls(List<String> pageUrls, String unparsedHtml) {
List<Page> 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 @Override
protected String parseHtmlToImageUrl(String unparsedHtml) { protected String parseHtmlToImageUrl(String unparsedHtml) {
int beginIndex = unparsedHtml.indexOf("<img id=\"comic_page\""); int beginIndex = unparsedHtml.indexOf("<img id=\"comic_page\"");

View file

@ -85,7 +85,8 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
readerMenu.destroy(); readerMenu.destroy();
viewer.destroy(); if (viewer != null)
viewer.destroy();
super.onDestroy(); super.onDestroy();
} }
@ -97,7 +98,8 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
@Override @Override
protected void onPause() { protected void onPause() {
getPresenter().setCurrentPage(viewer.getCurrentPosition()); if (viewer != null)
getPresenter().setCurrentPage(viewer.getCurrentPosition());
super.onPause(); super.onPause();
} }

View file

@ -183,7 +183,9 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
int pagesToPreload = Math.min(pages.size(), 5); int pagesToPreload = Math.min(pages.size(), 5);
return Observable.from(pages) return Observable.from(pages)
.take(pagesToPreload) .take(pagesToPreload)
.concatMap(source::getImageUrlFromPage) .concatMap(page -> page.getImageUrl() == null ?
source.getImageUrlFromPage(page) :
Observable.just(page))
.doOnCompleted(this::stopPreloadingNextChapter); .doOnCompleted(this::stopPreloadingNextChapter);
}) })
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())