From 6aa07dd17e8ab0b13fe61e42a2de161addb0bc93 Mon Sep 17 00:00:00 2001 From: inorichi Date: Wed, 3 Feb 2016 22:21:15 +0100 Subject: [PATCH] Download the first image of the next chapter --- .../tachiyomi/ui/reader/ReaderPresenter.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.java index e1a15d869a..013afe2f59 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.java @@ -30,6 +30,7 @@ import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; import rx.subjects.PublishSubject; +import timber.log.Timber; public class ReaderPresenter extends BasePresenter { @@ -70,9 +71,16 @@ public class ReaderPresenter extends BasePresenter { retryPageSubject = PublishSubject.create(); - startable(PRELOAD_NEXT_CHAPTER, this::getPreloadNextChapterObservable); - startable(GET_PAGE_IMAGES, this::getPageImagesObservable); + startable(PRELOAD_NEXT_CHAPTER, this::getPreloadNextChapterObservable, + next -> {}, + error -> Timber.e("Error preloading chapter")); + + startable(GET_PAGE_IMAGES, this::getPageImagesObservable, + next -> {}, + error -> Timber.e("Error fetching images")); + startable(GET_ADJACENT_CHAPTERS, this::getAdjacentChaptersObservable); + startable(RETRY_IMAGES, this::getRetryPageObservable); restartable(GET_MANGA_SYNC, () -> getMangaSyncObservable().subscribe()); @@ -151,8 +159,7 @@ public class ReaderPresenter extends BasePresenter { .doOnNext(pair -> { previousChapter = pair.first; nextChapter = pair.second; - }) - .observeOn(AndroidSchedulers.mainThread()); + }); } // Listen for retry page events @@ -162,8 +169,7 @@ public class ReaderPresenter extends BasePresenter { .flatMap(page -> page.getImageUrl() == null ? source.getImageUrlFromPage(page) : Observable.just(page)) - .flatMap(source::getCachedImage) - .observeOn(AndroidSchedulers.mainThread()); + .flatMap(source::getCachedImage); } // Preload the first pages of the next chapter @@ -175,9 +181,14 @@ public class ReaderPresenter extends BasePresenter { int pagesToPreload = Math.min(pages.size(), 5); return Observable.from(pages).take(pagesToPreload); }) + // Preload up to 5 images .concatMap(page -> page.getImageUrl() == null ? source.getImageUrlFromPage(page) : Observable.just(page)) + // Download the first image + .concatMap(page -> page.getPageNumber() == 0 ? + source.getCachedImage(page) : + Observable.just(page)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnCompleted(this::stopPreloadingNextChapter);