Skip to content

Commit cba85bb

Browse files
authored
Merge branch 'master' into feature_attachments
2 parents ccacc51 + 1485960 commit cba85bb

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import android.graphics.Color
66
import android.graphics.Typeface
77
import android.graphics.drawable.ColorDrawable
88
import android.graphics.drawable.Drawable
9+
import android.net.Uri
10+
import android.util.Size
911
import android.util.TypedValue
1012
import android.view.Menu
1113
import 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

Comments
 (0)