From 706256759ba000765f750d80ffe69e3372f4a479 Mon Sep 17 00:00:00 2001 From: tgyuuAn Date: Tue, 12 Nov 2024 00:39:09 +0900 Subject: [PATCH] Remove unnecessary code and ENCODED_LOOP_COUNT not to be applied when using GifDecoder --- .../src/main/java/coil3/gif/AnimatedImageDecoder.kt | 10 +++++++++- coil-gif/src/main/java/coil3/gif/GifDecoder.kt | 6 +++++- coil-gif/src/main/java/coil3/gif/MovieDrawable.kt | 13 +------------ coil-gif/src/main/java/coil3/gif/imageRequests.kt | 6 +++--- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/coil-gif/src/main/java/coil3/gif/AnimatedImageDecoder.kt b/coil-gif/src/main/java/coil3/gif/AnimatedImageDecoder.kt index c5a64c163a..7828e25a91 100644 --- a/coil-gif/src/main/java/coil3/gif/AnimatedImageDecoder.kt +++ b/coil-gif/src/main/java/coil3/gif/AnimatedImageDecoder.kt @@ -16,7 +16,6 @@ import coil3.decode.Decoder import coil3.decode.ImageSource import coil3.decode.toImageDecoderSourceOrNull import coil3.fetch.SourceFetchResult -import coil3.gif.MovieDrawable.Companion.ENCODED_LOOP_COUNT import coil3.gif.internal.animatable2CallbackOf import coil3.gif.internal.asPostProcessor import coil3.gif.internal.maybeWrapImageSourceToRewriteFrameDelay @@ -162,4 +161,13 @@ class AnimatedImageDecoder( (SDK_INT >= 30 && DecodeUtils.isAnimatedHeif(source)) } } + + companion object { + /** + * Pass this to [setRepeatCount] to repeat according to encoded LoopCount metadata. + * This only applies when using [AnimatedImageDecoder]. + */ + @RequiresApi(28) + const val ENCODED_LOOP_COUNT = -2 + } } diff --git a/coil-gif/src/main/java/coil3/gif/GifDecoder.kt b/coil-gif/src/main/java/coil3/gif/GifDecoder.kt index eb4704173d..28de76f08e 100644 --- a/coil-gif/src/main/java/coil3/gif/GifDecoder.kt +++ b/coil-gif/src/main/java/coil3/gif/GifDecoder.kt @@ -4,6 +4,7 @@ package coil3.gif import android.graphics.Bitmap import android.graphics.Movie +import android.os.Build import coil3.ImageLoader import coil3.asImage import coil3.decode.DecodeResult @@ -11,6 +12,7 @@ import coil3.decode.DecodeUtils import coil3.decode.Decoder import coil3.decode.ImageSource import coil3.fetch.SourceFetchResult +import coil3.gif.AnimatedImageDecoder.Companion.ENCODED_LOOP_COUNT import coil3.gif.internal.animatable2CompatCallbackOf import coil3.gif.internal.maybeWrapImageSourceToRewriteFrameDelay import coil3.request.Options @@ -49,7 +51,9 @@ class GifDecoder( scale = options.scale, ) - drawable.setRepeatCount(options.repeatCount) + if (options.repeatCount != ENCODED_LOOP_COUNT) { + drawable.setRepeatCount(options.repeatCount) + } // Set the start and end animation callbacks if any one is supplied through the request. val onStart = options.animationStartCallback diff --git a/coil-gif/src/main/java/coil3/gif/MovieDrawable.kt b/coil-gif/src/main/java/coil3/gif/MovieDrawable.kt index b2b716782e..c7bb5fb710 100644 --- a/coil-gif/src/main/java/coil3/gif/MovieDrawable.kt +++ b/coil-gif/src/main/java/coil3/gif/MovieDrawable.kt @@ -153,11 +153,7 @@ class MovieDrawable @JvmOverloads constructor( * Default: [REPEAT_INFINITE] */ fun setRepeatCount(repeatCount: Int) { - if (SDK_INT >= 28) { - require(repeatCount >= ENCODED_LOOP_COUNT) { "Invalid repeatCount: $repeatCount" } - } else { - require(repeatCount >= REPEAT_INFINITE) { "Invalid repeatCount: $repeatCount" } - } + require(repeatCount >= REPEAT_INFINITE) { "Invalid repeatCount: $repeatCount" } this.repeatCount = repeatCount } @@ -290,12 +286,5 @@ class MovieDrawable @JvmOverloads constructor( companion object { /** Pass this to [setRepeatCount] to repeat infinitely. */ const val REPEAT_INFINITE = -1 - - /** - * Pass this to [setRepeatCount] to repeat according to encoded LoopCount metadata. - * This only applies when using [AnimatedImageDecoder]. - */ - @RequiresApi(28) - const val ENCODED_LOOP_COUNT = -2 } } diff --git a/coil-gif/src/main/java/coil3/gif/imageRequests.kt b/coil-gif/src/main/java/coil3/gif/imageRequests.kt index 3265e5fa9d..17940a4e15 100644 --- a/coil-gif/src/main/java/coil3/gif/imageRequests.kt +++ b/coil-gif/src/main/java/coil3/gif/imageRequests.kt @@ -3,11 +3,11 @@ package coil3.gif import android.graphics.ImageDecoder import android.graphics.drawable.AnimatedImageDrawable import android.graphics.drawable.Drawable -import android.os.Build.VERSION.SDK_INT +import android.os.Build import coil3.Extras import coil3.annotation.ExperimentalCoilApi import coil3.getExtra -import coil3.gif.MovieDrawable.Companion.ENCODED_LOOP_COUNT +import coil3.gif.AnimatedImageDecoder.Companion.ENCODED_LOOP_COUNT import coil3.gif.MovieDrawable.Companion.REPEAT_INFINITE import coil3.request.ImageRequest import coil3.request.Options @@ -19,7 +19,7 @@ import coil3.request.Options * @see AnimatedImageDrawable.setRepeatCount */ fun ImageRequest.Builder.repeatCount(repeatCount: Int) = apply { - if (SDK_INT >= 28) { + if (Build.VERSION.SDK_INT >= 28) { require(repeatCount >= ENCODED_LOOP_COUNT) { "Invalid repeatCount: $repeatCount" } } else { require(repeatCount >= REPEAT_INFINITE) { "Invalid repeatCount: $repeatCount" }