Apply max mms size to entire message instead of every attachment

This commit is contained in:
Moez Bhatti
2018-02-27 22:31:58 -05:00
parent 00f163d4eb
commit 0450569617
@@ -55,9 +55,14 @@ class SendMessage @Inject constructor(
val settings = Settings()
val message = Message(body, addresses.toTypedArray())
attachments
.map { uri -> RxImageConverters.uriToBitmap(context, uri).blockingFirst() }
.map { bitmap -> shrink(bitmap, prefs.mmsSize.get() * 1024) }
val bitmaps = attachments.map { uri -> RxImageConverters.uriToBitmap(context, uri).blockingFirst() }
val totalBytes = bitmaps.sumBy { it.allocationByteCount }
bitmaps
.map { bitmap ->
val byteRatio = bitmap.allocationByteCount / totalBytes.toFloat()
shrink(bitmap, (prefs.mmsSize.get() * 1024 * byteRatio).toInt())
}
.forEach { bitmap -> message.addMedia(bitmap, "image/jpeg") }
val transaction = Transaction(context, settings)