-
Notifications
You must be signed in to change notification settings - Fork 665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add constant to parse Gif Loop Count and apply to repeatCount #2654
base: main
Are you sure you want to change the base?
Changes from 2 commits
9b8b120
5b302b6
6ed462e
769d0b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,9 @@ import android.graphics.PorterDuff | |
import android.graphics.Rect | ||
import android.graphics.drawable.AnimatedImageDrawable | ||
import android.graphics.drawable.Drawable | ||
import android.os.Build.VERSION.SDK_INT | ||
import android.os.SystemClock | ||
import androidx.annotation.RequiresApi | ||
import androidx.core.graphics.createBitmap | ||
import androidx.core.graphics.withSave | ||
import androidx.vectordrawable.graphics.drawable.Animatable2Compat | ||
|
@@ -151,7 +153,11 @@ class MovieDrawable @JvmOverloads constructor( | |
* Default: [REPEAT_INFINITE] | ||
*/ | ||
fun setRepeatCount(repeatCount: Int) { | ||
require(repeatCount >= REPEAT_INFINITE) { "Invalid repeatCount: $repeatCount" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to leave this check as is. |
||
if (SDK_INT >= 28) { | ||
require(repeatCount >= ENCODED_LOOP_COUNT) { "Invalid repeatCount: $repeatCount" } | ||
} else { | ||
require(repeatCount >= REPEAT_INFINITE) { "Invalid repeatCount: $repeatCount" } | ||
} | ||
this.repeatCount = repeatCount | ||
} | ||
|
||
|
@@ -284,5 +290,12 @@ 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should move this constant to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thx, that's a really good idea. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +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 coil3.Extras | ||
import coil3.annotation.ExperimentalCoilApi | ||
import coil3.getExtra | ||
import coil3.gif.MovieDrawable.Companion.ENCODED_LOOP_COUNT | ||
import coil3.gif.MovieDrawable.Companion.REPEAT_INFINITE | ||
import coil3.request.ImageRequest | ||
import coil3.request.Options | ||
|
@@ -17,7 +19,11 @@ import coil3.request.Options | |
* @see AnimatedImageDrawable.setRepeatCount | ||
*/ | ||
fun ImageRequest.Builder.repeatCount(repeatCount: Int) = apply { | ||
require(repeatCount >= REPEAT_INFINITE) { "Invalid repeatCount: $repeatCount" } | ||
if (SDK_INT >= 28) { | ||
require(repeatCount >= ENCODED_LOOP_COUNT) { "Invalid repeatCount: $repeatCount" } | ||
} else { | ||
require(repeatCount >= REPEAT_INFINITE) { "Invalid repeatCount: $repeatCount" } | ||
} | ||
extras[repeatCountKey] = repeatCount | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this part, the lint was broken because the version branch for |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to add handling to
GifDecoder.Factory
to ensure we don't set the repeat count there either whenoptions.repeatCount == ENCODED_LOOP_COUNT
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to add check() to the Factory as shown below. What do you think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only want to guard against it here and ignore the parameter instead of throwing: https://github.com/coil-kt/coil/blob/main/coil-gif/src/main/java/coil3/gif/GifDecoder.kt#L52