@@ -8,6 +8,7 @@ import android.graphics.Typeface
88import android.graphics.drawable.ColorDrawable
99import android.graphics.drawable.Drawable
1010import android.net.Uri
11+ import android.util.Size
1112import android.util.TypedValue
1213import android.view.Menu
1314import android.view.View
@@ -60,6 +61,7 @@ class ThreadAdapter(
6061
6162 @SuppressLint(" MissingPermission" )
6263 private val hasMultipleSIMCards = (activity.subscriptionManagerCompat().activeSubscriptionInfoList?.size ? : 0 ) > 1
64+ private val maxChatBubbleWidth = activity.usableScreenSize.x * 0.8f
6365
6466 init {
6567 setupDragListener(true )
@@ -374,14 +376,20 @@ class ThreadAdapter(
374376 return false
375377 }
376378
377- override fun onResourceReady (dr : Drawable ? , a : Any? , t : Target <Drawable >? , d : DataSource ? , i : Boolean ) =
378- false
379+ override fun onResourceReady (dr : Drawable ? , a : Any? , t : Target <Drawable >? , d : DataSource ? , i : Boolean ) = false
379380 })
380381
382+ // limit attachment sizes to avoid causing OOM
383+ var wantedAttachmentSize = Size (attachment.width, attachment.height)
384+ if (wantedAttachmentSize.width > maxChatBubbleWidth) {
385+ val newHeight = wantedAttachmentSize.height / (wantedAttachmentSize.width / maxChatBubbleWidth)
386+ wantedAttachmentSize = Size (maxChatBubbleWidth.toInt(), newHeight.toInt())
387+ }
388+
381389 builder = if (isTallImage) {
382- builder.override (attachment .width, attachment .width)
390+ builder.override (wantedAttachmentSize .width, wantedAttachmentSize .width)
383391 } else {
384- builder.override (attachment .width, attachment .height)
392+ builder.override (wantedAttachmentSize .width, wantedAttachmentSize .height)
385393 }
386394
387395 try {
0 commit comments