From 8ef200861cbc9c0332fedf4622ee7cf9394230a8 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 2 Sep 2022 10:02:04 -0400 Subject: [PATCH] Fix webtoon viewer pages not loading Partial revert of fddca151823d066cad7f12da2e0b8d1c65f2b9d1 --- .../viewer/webtoon/WebtoonPageHolder.kt | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) 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 47d6b399d1..0d92d9890b 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,28 +246,30 @@ class WebtoonPageHolder( unsubscribeReadImageHeader() val streamFn = page?.stream ?: return + var openStream: InputStream? = null readImageHeaderSubscription = Observable .fromCallable { val stream = streamFn().buffered(16) - val imageStream = process(stream) - val isAnimated = ImageUtil.isAnimatedAndSupported(stream) - Pair(imageStream, isAnimated) + openStream = process(stream) + + ImageUtil.isAnimatedAndSupported(stream) } .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .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, - ), - ) - } + .doOnNext { isAnimated -> + frame.setImage( + openStream!!, + 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)