From 59bedb33ff59ad5db1df2e93567a2266fb63eacc Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Mon, 18 Mar 2024 23:01:23 +0600 Subject: [PATCH] Fix regression from coil3 migration Fixes #495 Co-authored-by: jobobby04 <17078382+jobobby04@users.noreply.github.com> --- .../ui/reader/viewer/ReaderPageImageView.kt | 5 +++-- .../tachiyomi/core/common/util/system/ImageUtil.kt | 13 +++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt index fbb1302e8..2cd0f2840 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderPageImageView.kt @@ -349,8 +349,9 @@ open class ReaderPageImageView @JvmOverloads constructor( .diskCachePolicy(CachePolicy.DISABLED) .target( onSuccess = { result -> - setImageDrawable(result.asDrawable(context.resources)) - (result as? Animatable)?.start() + val drawable = result.asDrawable(context.resources) + setImageDrawable(drawable) + (drawable as? Animatable)?.start() isVisible = true this@ReaderPageImageView.onImageLoaded() }, diff --git a/core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt b/core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt index b01f4e882..03a2f2d60 100644 --- a/core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt +++ b/core/common/src/main/kotlin/tachiyomi/core/common/util/system/ImageUtil.kt @@ -77,19 +77,20 @@ object ImageUtil { } fun isAnimatedAndSupported(stream: InputStream): Boolean { - try { + return try { val type = getImageType(stream) ?: return false - return when (type.format) { + // https://coil-kt.github.io/coil/getting_started/#supported-image-formats + when (type.format) { Format.Gif -> true - // Coil supports animated WebP on Android 9.0+ - // https://coil-kt.github.io/coil/getting_started/#supported-image-formats + // Animated WebP on Android 9+ Format.Webp -> type.isAnimated && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P + // Animated Heif on Android 11+ + Format.Heif -> type.isAnimated && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R else -> false } } catch (e: Exception) { - /* Do Nothing */ + false } - return false } private fun getImageType(stream: InputStream): tachiyomi.decoder.ImageType? {