@@ -6,6 +6,8 @@ import android.graphics.Color
66import android.graphics.Typeface
77import android.graphics.drawable.ColorDrawable
88import android.graphics.drawable.Drawable
9+ import android.net.Uri
10+ import android.util.Size
911import android.util.TypedValue
1012import android.view.Menu
1113import android.view.View
@@ -54,6 +56,7 @@ class ThreadAdapter(
5456
5557 @SuppressLint(" MissingPermission" )
5658 private val hasMultipleSIMCards = (activity.subscriptionManagerCompat().activeSubscriptionInfoList?.size ? : 0 ) > 1
59+ private val maxChatBubbleWidth = activity.usableScreenSize.x * 0.8f
5760
5861 init {
5962 setupDragListener(true )
@@ -366,14 +369,20 @@ class ThreadAdapter(
366369 return false
367370 }
368371
369- override fun onResourceReady (dr : Drawable ? , a : Any? , t : Target <Drawable >? , d : DataSource ? , i : Boolean ) =
370- false
372+ override fun onResourceReady (dr : Drawable ? , a : Any? , t : Target <Drawable >? , d : DataSource ? , i : Boolean ) = false
371373 })
372374
375+ // limit attachment sizes to avoid causing OOM
376+ var wantedAttachmentSize = Size (attachment.width, attachment.height)
377+ if (wantedAttachmentSize.width > maxChatBubbleWidth) {
378+ val newHeight = wantedAttachmentSize.height / (wantedAttachmentSize.width / maxChatBubbleWidth)
379+ wantedAttachmentSize = Size (maxChatBubbleWidth.toInt(), newHeight.toInt())
380+ }
381+
373382 builder = if (isTallImage) {
374- builder.override (attachment .width, attachment .width)
383+ builder.override (wantedAttachmentSize .width, wantedAttachmentSize .width)
375384 } else {
376- builder.override (attachment .width, attachment .height)
385+ builder.override (wantedAttachmentSize .width, wantedAttachmentSize .height)
377386 }
378387
379388 try {
0 commit comments