From bd033db84c5b7fe2dbb01886f99c0df456b8f930 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Wed, 1 Sep 2021 04:43:29 +0700 Subject: [PATCH] Fix animated image detection (#5826) --- .../ui/reader/viewer/pager/PagerPageHolder.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt index 6a5ac26fdc..bd071660f0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt @@ -264,17 +264,17 @@ class PagerPageHolder( .fromCallable { val stream = streamFn().buffered(16) val itemStream = process(item, stream) + val bais = ByteArrayInputStream(itemStream.readBytes()) try { - val streamBytes = itemStream.readBytes() - val isAnimated = ImageUtil.isAnimatedAndSupported(stream) + val isAnimated = ImageUtil.isAnimatedAndSupported(bais) + bais.reset() val background = if (!isAnimated && viewer.config.automaticBackground) { - ByteArrayInputStream(streamBytes).use { bais -> - ImageUtil.chooseBackground(context, bais) - } + ImageUtil.chooseBackground(context, bais) } else { null } - Triple(streamBytes, isAnimated, background) + bais.reset() + Triple(bais, isAnimated, background) } finally { stream.close() itemStream.close() @@ -282,15 +282,15 @@ class PagerPageHolder( } .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .doOnNext { (streamBytes, isAnimated, background) -> - ByteArrayInputStream(streamBytes).use { bais -> + .doOnNext { (bais, isAnimated, background) -> + bais.use { if (!isAnimated) { this.background = background initSubsamplingImageView().apply { - setImage(ImageSource.inputStream(bais)) + setImage(ImageSource.inputStream(it)) } } else { - initImageView().setImage(bais) + initImageView().setImage(it) } } }