-
Notifications
You must be signed in to change notification settings - Fork 683
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
Callback support for animated drawables #676
Callback support for animated drawables #676
Conversation
sagar-viradiya
commented
Feb 21, 2021
•
edited
Loading
edited
- Fixes Provide callback when animated GIF is done playing #606
- Add start and end callback support for animated drawables.
- Add getter and setter extension for start and end callbacks on ImageRequest.Builder. - Apply start and end callbacks through Animatable2.AnimationCallback and Animatable2Compat.AnimationCallback in the ImageDecoderDecoder.kt and GifDecoder.kt respectively.
- Fix import order - Fix code formatting issue
- Remove super call from Animation callbacks. - Minor code enhancements.
…nhancement/gif-callback
…nhancement/gif-callback
- Instrumentation testing on callback for animated drawables - Moved only decoding part to interruptible source in ImageDecoderDecoder.kt
.data("${ContentResolver.SCHEME_FILE}:///android_asset/animated.gif") | ||
.build() | ||
imageLoader.enqueue(imageRequest) | ||
delay(5000) |
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.
delay
could make the test flaky if the emulator is slow. I'd recommend converting isStartCalled
and isEndCalled
to MutableStateFlow(false)
. Then you can start the image request and await them being set to true like here.
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 have made the suggested changes. I have one concern here though. What if in the future due to some changes callback won't get triggered, Wouldn't it lead to suspension forever?
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.
Yep! We could probably add a listener for onSuccess/onError/onCancel
, but it awaiting forever is ok too. After ~25 minutes the tests will timeout. By migrating to use the state flow we guarantee that the test will only fail/stall if it's been broken.
- Replace delay in the AnimationCallbacksTest.kt with StateFlow to avoid flaky test. - Fix typo in the GifDecoder.kt
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.
Great work, thanks 🙏
Thanks again for this @sagar-viradiya. Works like a charm! |
* Support for start and end callbacks for animated drawables - Add getter and setter extension for start and end callbacks on ImageRequest.Builder. - Apply start and end callbacks through Animatable2.AnimationCallback and Animatable2Compat.AnimationCallback in the ImageDecoderDecoder.kt and GifDecoder.kt respectively. * Minor code refactoring - Fix import order - Fix code formatting issue * API dump. * PR review changes. - Remove super call from Animation callbacks. - Minor code enhancements. * Testing and decoder changes - Instrumentation testing on callback for animated drawables - Moved only decoding part to interruptible source in ImageDecoderDecoder.kt * PR review changes - Replace delay in the AnimationCallbacksTest.kt with StateFlow to avoid flaky test. - Fix typo in the GifDecoder.kt