Skip to content

Commit

Permalink
Remove unnecessary code and ENCODED_LOOP_COUNT not to be applied when…
Browse files Browse the repository at this point in the history
… using GifDecoder
  • Loading branch information
tgyuuAn committed Nov 11, 2024
1 parent 5b302b6 commit 7062567
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
10 changes: 9 additions & 1 deletion coil-gif/src/main/java/coil3/gif/AnimatedImageDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
6 changes: 5 additions & 1 deletion coil-gif/src/main/java/coil3/gif/GifDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ 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
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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 1 addition & 12 deletions coil-gif/src/main/java/coil3/gif/MovieDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
}
6 changes: 3 additions & 3 deletions coil-gif/src/main/java/coil3/gif/imageRequests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" }
Expand Down

0 comments on commit 7062567

Please sign in to comment.