diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/CaptionDialog.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/CaptionDialog.kt index d78009a497..abb905bcea 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/CaptionDialog.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/CaptionDialog.kt @@ -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? ) { + 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) }