mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-04 07:25:25 +01:00
Fix potential glide lifecycle issue with transition animation.
This commit is contained in:
@@ -90,7 +90,7 @@ class MediaPreviewV2Activity : PassphraseRequiredActivity(), VoiceNoteMediaContr
|
||||
setContentView(R.layout.activity_mediapreview_v2)
|
||||
|
||||
transitionImageView = findViewById(R.id.transition_image_view)
|
||||
val cacheDrawable = MediaPreviewCache.drawable
|
||||
val cacheDrawable = MediaPreviewCache.drawable?.let { RecycledBitmapGuardDrawable(it) }
|
||||
if (cacheDrawable != null && !args.skipSharedElementTransition) {
|
||||
val bounds = cacheDrawable.bounds
|
||||
val aspectRatio = bounds.width().toFloat() / bounds.height()
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.thoughtcrime.securesms.mediapreview
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.DrawableWrapper
|
||||
|
||||
/**
|
||||
* A wrapper that skips drawing upon failure. This is to guard against situations where we may
|
||||
* be using a bitmap from Glide that could be recycled at a time outside our control
|
||||
*
|
||||
* If you ever truly need the bitmap in this case, you should save it yourself. But there are situations
|
||||
* (like transition animations) where having a bitmap isn't strictly necessary, and we'd rather
|
||||
* show nothing than crash or have to manage the bitmap lifecycle ourselves.
|
||||
*/
|
||||
class RecycledBitmapGuardDrawable(drawable: Drawable) : DrawableWrapper(drawable) {
|
||||
override fun draw(canvas: Canvas) {
|
||||
try {
|
||||
super.draw(canvas)
|
||||
} catch (_: RuntimeException) {
|
||||
// Bitmap was recycled — nothing to draw.
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user