show gifs in CaptionDialog (#4536)

closes #4528
This commit is contained in:
Konrad Pozniak 2024-06-30 16:52:11 +02:00 committed by GitHub
parent c0ad50b6e6
commit a371edbe87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 0 deletions

View File

@ -16,6 +16,7 @@
package com.keylesspalace.tusky.components.compose.dialog
import android.content.Context
import android.graphics.drawable.Animatable
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Bundle
@ -45,6 +46,8 @@ class CaptionDialog : DialogFragment() {
private val binding by viewBinding(DialogImageDescriptionBinding::bind)
private var animatable: Animatable? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.TuskyDialogFragmentStyle)
@ -97,6 +100,23 @@ class CaptionDialog : DialogFragment() {
resource: Drawable,
transition: Transition<in Drawable>?
) {
if (resource is Animatable) {
resource.callback = object : Drawable.Callback {
override fun invalidateDrawable(who: Drawable) {
view.invalidate()
}
override fun scheduleDrawable(who: Drawable, what: Runnable, `when`: Long) {
view.postDelayed(what, `when`)
}
override fun unscheduleDrawable(who: Drawable, what: Runnable) {
view.removeCallbacks(what)
}
}
resource.start()
animatable = resource
}
imageView.setImageDrawable(resource)
}
@ -128,6 +148,12 @@ class CaptionDialog : DialogFragment() {
listener = context as? Listener ?: error("Activity is not ComposeCaptionDialog.Listener")
}
override fun onDestroyView() {
super.onDestroyView()
animatable?.stop()
(animatable as? Drawable?)?.callback = null
}
interface Listener {
fun onUpdateDescription(localId: Int, description: String)
}