move mms attachment size checking to a separate function
This commit is contained in:
parent
6405b7431f
commit
f97e3b048c
|
@ -140,34 +140,7 @@ class ThreadActivity : SimpleActivity() {
|
||||||
participants.add(contact)
|
participants.add(contact)
|
||||||
}
|
}
|
||||||
|
|
||||||
messages.filter { it.attachment != null }.forEach {
|
setupAttachmentSizes()
|
||||||
it.attachment!!.attachments.forEach {
|
|
||||||
try {
|
|
||||||
if (it.mimetype.startsWith("image/")) {
|
|
||||||
val fileOptions = BitmapFactory.Options()
|
|
||||||
fileOptions.inJustDecodeBounds = true
|
|
||||||
BitmapFactory.decodeStream(contentResolver.openInputStream(it.getUri()), null, fileOptions)
|
|
||||||
it.width = fileOptions.outWidth
|
|
||||||
it.height = fileOptions.outHeight
|
|
||||||
} else if (it.mimetype.startsWith("video/")) {
|
|
||||||
val metaRetriever = MediaMetadataRetriever()
|
|
||||||
metaRetriever.setDataSource(this, it.getUri())
|
|
||||||
it.width = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)!!.toInt()
|
|
||||||
it.height = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)!!.toInt()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (it.width < 0) {
|
|
||||||
it.width = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if (it.height < 0) {
|
|
||||||
it.height = 0
|
|
||||||
}
|
|
||||||
} catch (ignored: Exception) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setupAdapter()
|
setupAdapter()
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
val threadTitle = participants.getThreadTitle()
|
val threadTitle = participants.getThreadTitle()
|
||||||
|
@ -315,6 +288,36 @@ class ThreadActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupAttachmentSizes() {
|
||||||
|
messages.filter { it.attachment != null }.forEach {
|
||||||
|
it.attachment!!.attachments.forEach {
|
||||||
|
try {
|
||||||
|
if (it.mimetype.startsWith("image/")) {
|
||||||
|
val fileOptions = BitmapFactory.Options()
|
||||||
|
fileOptions.inJustDecodeBounds = true
|
||||||
|
BitmapFactory.decodeStream(contentResolver.openInputStream(it.getUri()), null, fileOptions)
|
||||||
|
it.width = fileOptions.outWidth
|
||||||
|
it.height = fileOptions.outHeight
|
||||||
|
} else if (it.mimetype.startsWith("video/")) {
|
||||||
|
val metaRetriever = MediaMetadataRetriever()
|
||||||
|
metaRetriever.setDataSource(this, it.getUri())
|
||||||
|
it.width = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)!!.toInt()
|
||||||
|
it.height = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)!!.toInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it.width < 0) {
|
||||||
|
it.width = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it.height < 0) {
|
||||||
|
it.height = 0
|
||||||
|
}
|
||||||
|
} catch (ignored: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
private fun setupSIMSelector() {
|
private fun setupSIMSelector() {
|
||||||
val availableSIMs = SubscriptionManager.from(this).activeSubscriptionInfoList ?: return
|
val availableSIMs = SubscriptionManager.from(this).activeSubscriptionInfoList ?: return
|
||||||
|
|
Loading…
Reference in New Issue