diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/MangaChaptersPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/MangaChaptersPresenter.java index 90c59577e..3c802bb28 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/MangaChaptersPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/MangaChaptersPresenter.java @@ -140,7 +140,6 @@ public class MangaChaptersPresenter extends BasePresenter remove(downloadSubscription); add(downloadSubscription = selectedChapters - .subscribeOn(Schedulers.io()) .subscribe(chapter -> { EventBus.getDefault().post( new DownloadChapterEvent(manga, chapter)); diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java index 53921a45a..a6869c7f7 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java @@ -38,7 +38,6 @@ public class ReaderPresenter extends BasePresenter { private static final int GET_PAGE_LIST = 1; private static final int GET_PAGE_IMAGES = 2; - private static final int GET_LOCAL_IMAGES = 3; @Override protected void onCreate(Bundle savedState) { @@ -47,7 +46,7 @@ public class ReaderPresenter extends BasePresenter { restartableLatestCache(GET_PAGE_LIST, () -> getPageListObservable() .doOnNext(pages -> pageList = pages) - .doOnCompleted(this::prepareChapter), + .doOnCompleted( () -> start(GET_PAGE_IMAGES) ), (view, pages) -> { view.onPageListReady(pages); if (currentPage != 0) @@ -62,9 +61,6 @@ public class ReaderPresenter extends BasePresenter { }, (view, error) -> Timber.e("An error occurred while downloading an image")); - restartableReplay(GET_LOCAL_IMAGES, - this::getLocalImagesObservable, - (view, page) -> {}); } @Override @@ -100,26 +96,31 @@ public class ReaderPresenter extends BasePresenter { } private Observable> getPageListObservable() { - return source.pullPageListFromNetwork(chapter.url) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()); + if (chapter.downloaded != Chapter.DOWNLOADED) + return source.pullPageListFromNetwork(chapter.url) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()); + else + return Observable.just(downloadManager.getSavedPageList(source, manga, chapter)); } private Observable getPageImagesObservable() { - return Observable.merge( - Observable.from(pageList).filter(page -> page.getImageUrl() != null), - source.getRemainingImageUrlsFromPageList(pageList) - ) - .flatMap(source::getCachedImage) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()); - } + Observable pages; - private Observable getLocalImagesObservable() { - File chapterDir = downloadManager.getAbsoluteChapterDirectory(source, manga, chapter); + if (chapter.downloaded != Chapter.DOWNLOADED) { + pages = Observable + .merge(Observable.from(pageList).filter(page -> page.getImageUrl() != null), + source.getRemainingImageUrlsFromPageList(pageList)) + .flatMap(source::getCachedImage); + } else { + File chapterDir = downloadManager.getAbsoluteChapterDirectory(source, manga, chapter); - return Observable.from(pageList) - .flatMap(page -> downloadManager.getDownloadedImage(page, source, chapterDir)) + pages = Observable.from(pageList) + .flatMap(page -> downloadManager.getDownloadedImage(page, source, chapterDir)) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()); + } + return pages .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); } @@ -128,13 +129,6 @@ public class ReaderPresenter extends BasePresenter { this.currentPage = currentPage; } - private void prepareChapter() { - if (chapter.downloaded != Chapter.DOWNLOADED) - start(GET_PAGE_IMAGES); - else - start(GET_LOCAL_IMAGES); - } - private void saveChapter() { chapter.last_page_read = currentPage; if (currentPage == pageList.size() - 1) { diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaChaptersFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaChaptersFragment.java index cdaae91e6..9645423c6 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaChaptersFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaChaptersFragment.java @@ -142,6 +142,7 @@ public class MangaChaptersFragment extends BaseRxFragment \ No newline at end of file