Merge remote-tracking branch 'inorichi/master'
This commit is contained in:
commit
3d5c8c992f
@ -188,6 +188,10 @@ public class DatabaseHelper {
|
||||
}
|
||||
|
||||
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()
|
||||
.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<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()
|
||||
.listOfObjects(Chapter.class)
|
||||
.withQuery(Query.builder()
|
||||
@ -210,7 +218,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 + " DESC")
|
||||
.limit(1)
|
||||
.build())
|
||||
|
@ -159,7 +159,7 @@ public abstract class Source extends BaseSource {
|
||||
mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages);
|
||||
}
|
||||
|
||||
private List<Page> convertToPages(List<String> pageUrls) {
|
||||
protected List<Page> convertToPages(List<String> pageUrls) {
|
||||
List<Page> 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<Page> getFirstImageFromPageUrls(List<String> pageUrls, String unparsedHtml) {
|
||||
protected List<Page> getFirstImageFromPageUrls(List<String> pageUrls, String unparsedHtml) {
|
||||
List<Page> pages = convertToPages(pageUrls);
|
||||
String firstImage = parseHtmlToImageUrl(unparsedHtml);
|
||||
pages.get(0).setImageUrl(firstImage);
|
||||
|
@ -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<String> pageUrlList = new ArrayList<>();
|
||||
|
||||
Elements pageUrlElements = parsedDocument.getElementById("page_select").getElementsByTag("option");
|
||||
for (Element pageUrlElement : pageUrlElements) {
|
||||
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<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
|
||||
protected String parseHtmlToImageUrl(String unparsedHtml) {
|
||||
int beginIndex = unparsedHtml.indexOf("<img id=\"comic_page\"");
|
||||
|
@ -85,6 +85,7 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
readerMenu.destroy();
|
||||
if (viewer != null)
|
||||
viewer.destroy();
|
||||
super.onDestroy();
|
||||
}
|
||||
@ -97,6 +98,7 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
if (viewer != null)
|
||||
getPresenter().setCurrentPage(viewer.getCurrentPosition());
|
||||
super.onPause();
|
||||
}
|
||||
|
@ -183,7 +183,9 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||
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())
|
||||
|
Loading…
Reference in New Issue
Block a user