diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index a7b0454b..6441eca6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -89,13 +89,13 @@ class ThreadActivity : SimpleActivity() { messages.filter { it.attachment != null }.forEach { it.attachment!!.attachments.forEach { try { - if (it.type.startsWith("image/")) { + if (it.mimetype.startsWith("image/")) { val fileOptions = BitmapFactory.Options() fileOptions.inJustDecodeBounds = true BitmapFactory.decodeStream(contentResolver.openInputStream(it.uri), null, fileOptions) it.width = fileOptions.outWidth it.height = fileOptions.outHeight - } else if (it.type.startsWith("video/")) { + } else if (it.mimetype.startsWith("video/")) { val metaRetriever = MediaMetadataRetriever() metaRetriever.setDataSource(this, it.uri) it.width = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH).toInt() diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt index 1c06781a..cdd077c9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt @@ -196,9 +196,9 @@ class ThreadAdapter( thread_mesage_attachments_holder.removeAllViews() if (message.attachment?.attachments?.isNotEmpty() == true) { for (attachment in message.attachment.attachments) { - val type = attachment.type + val mimetype = attachment.mimetype val uri = attachment.uri - if (type.startsWith("image/") || type.startsWith("video/")) { + if (mimetype.startsWith("image/") || mimetype.startsWith("video/")) { val imageView = layoutInflater.inflate(R.layout.item_attachment_image, null) thread_mesage_attachments_holder.addView(imageView) @@ -228,13 +228,13 @@ class ThreadAdapter( } builder.into(imageView.attachment_image) - imageView.attachment_image.setOnClickListener { launchViewIntent(uri, type) } + imageView.attachment_image.setOnClickListener { launchViewIntent(uri, mimetype) } } else { if (message.isReceivedMessage()) { val attachmentView = layoutInflater.inflate(R.layout.item_received_unknown_attachment, null).apply { thread_received_attachment_label.apply { setTextColor(textColor) - setOnClickListener { launchViewIntent(uri, type) } + setOnClickListener { launchViewIntent(uri, mimetype) } } } thread_mesage_attachments_holder.addView(attachmentView) @@ -244,23 +244,23 @@ class ThreadAdapter( thread_sent_attachment_label.apply { this.background.applyColorFilter(background.adjustAlpha(0.8f)) setTextColor(background.getContrastColor()) - setOnClickListener { launchViewIntent(uri, type) } + setOnClickListener { launchViewIntent(uri, mimetype) } } } thread_mesage_attachments_holder.addView(attachmentView) } } - thread_message_play_outline.beVisibleIf(type.startsWith("video/")) + thread_message_play_outline.beVisibleIf(mimetype.startsWith("video/")) } } } } - private fun launchViewIntent(uri: Uri, type: String) { + private fun launchViewIntent(uri: Uri, mimetype: String) { Intent().apply { action = Intent.ACTION_VIEW - setDataAndType(uri, type) + setDataAndType(uri, mimetype) addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) if (resolveActivity(activity.packageManager) != null) { diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt index 844900b8..e6c0b9f7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt @@ -224,14 +224,14 @@ fun Context.getMmsAttachment(id: Int): MessageAttachment? { queryCursor(uri, projection, selection, selectionArgs, showErrors = true) { cursor -> val partId = cursor.getStringValue(Mms._ID) - val type = cursor.getStringValue(Mms.Part.CONTENT_TYPE) - if (type == "text/plain") { + val mimetype = cursor.getStringValue(Mms.Part.CONTENT_TYPE) + if (mimetype == "text/plain") { messageAttachment.text = cursor.getStringValue(Mms.Part.TEXT) ?: "" - } else if (type.startsWith("image/") || type.startsWith("video/")) { - val attachment = Attachment(Uri.withAppendedPath(uri, partId), type, 0, 0) + } else if (mimetype.startsWith("image/") || mimetype.startsWith("video/")) { + val attachment = Attachment(Uri.withAppendedPath(uri, partId), mimetype, 0, 0) messageAttachment.attachments.add(attachment) - } else if (type != "application/smil") { - val attachment = Attachment(Uri.withAppendedPath(uri, partId), type, 0, 0) + } else if (mimetype != "application/smil") { + val attachment = Attachment(Uri.withAppendedPath(uri, partId), mimetype, 0, 0) messageAttachment.attachments.add(attachment) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/models/Attachment.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/models/Attachment.kt index d471413a..fb904f5b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/models/Attachment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/models/Attachment.kt @@ -2,4 +2,4 @@ package com.simplemobiletools.smsmessenger.models import android.net.Uri -data class Attachment(var uri: Uri, var type: String, var width: Int, var height: Int) +data class Attachment(var uri: Uri, var mimetype: String, var width: Int, var height: Int)