From fddca151823d066cad7f12da2e0b8d1c65f2b9d1 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Thu, 1 Sep 2022 01:09:21 +0600 Subject: [PATCH] Don't update page progress and allow preload when on StencilPage (#7899) Also cleanup a little in WebtoonPageHolder --- .../tachiyomi/ui/reader/ReaderPresenter.kt | 5 +-- .../viewer/webtoon/WebtoonPageHolder.kt | 32 +++++++++---------- .../ui/reader/viewer/webtoon/WebtoonViewer.kt | 5 +++ 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 5e65c9484e..415a498fd0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -39,6 +39,7 @@ import eu.kanade.tachiyomi.ui.reader.loader.HttpPageLoader import eu.kanade.tachiyomi.ui.reader.model.InsertPage import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderPage +import eu.kanade.tachiyomi.ui.reader.model.StencilPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType @@ -414,8 +415,8 @@ class ReaderPresenter( val selectedChapter = page.chapter - // Insert page doesn't change page progress - if (page is InsertPage) { + // InsertPage and StencilPage doesn't change page progress + if (page is InsertPage || page is StencilPage) { return } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt index 0d92d9890b..47d6b399d1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt @@ -246,30 +246,28 @@ class WebtoonPageHolder( unsubscribeReadImageHeader() val streamFn = page?.stream ?: return - var openStream: InputStream? = null readImageHeaderSubscription = Observable .fromCallable { val stream = streamFn().buffered(16) - openStream = process(stream) - - ImageUtil.isAnimatedAndSupported(stream) + val imageStream = process(stream) + val isAnimated = ImageUtil.isAnimatedAndSupported(stream) + Pair(imageStream, isAnimated) } .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .doOnNext { isAnimated -> - frame.setImage( - openStream!!, - isAnimated, - ReaderPageImageView.Config( - zoomDuration = viewer.config.doubleTapAnimDuration, - minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_FIT_WIDTH, - cropBorders = viewer.config.imageCropBorders, - ), - ) + .doOnNext { (imageStream, isAnimated) -> + imageStream.use { + frame.setImage( + it, + isAnimated, + ReaderPageImageView.Config( + zoomDuration = viewer.config.doubleTapAnimDuration, + minimumScaleType = SubsamplingScaleImageView.SCALE_TYPE_FIT_WIDTH, + cropBorders = viewer.config.imageCropBorders, + ), + ) + } } - // Keep the Rx stream alive to close the input stream only when unsubscribed - .flatMap { Observable.never() } - .doOnUnsubscribe { openStream?.close() } .subscribe({}, {}) addSubscription(readImageHeaderSubscription) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt index 60cda71e4e..8ad2ee574e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt @@ -210,6 +210,11 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr logcat { "onPageSelected: ${page.number}/${pages.size}" } activity.onPageSelected(page) + // Skip preload on StencilPage + if (page is StencilPage) { + return + } + // Preload next chapter once we're within the last 5 pages of the current chapter val inPreloadRange = pages.size - page.number < 5 if (inPreloadRange && allowPreload && page.chapter == adapter.currentChapter) {