Skip to content
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

show gifs in CaptionDialog #4536

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down
Loading