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 cdd077c9..f5d43137 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt @@ -233,6 +233,9 @@ class ThreadAdapter( if (message.isReceivedMessage()) { val attachmentView = layoutInflater.inflate(R.layout.item_received_unknown_attachment, null).apply { thread_received_attachment_label.apply { + if (attachment.filename.isNotEmpty()) { + thread_received_attachment_label.text = attachment.filename + } setTextColor(textColor) setOnClickListener { launchViewIntent(uri, mimetype) } } @@ -244,6 +247,9 @@ class ThreadAdapter( thread_sent_attachment_label.apply { this.background.applyColorFilter(background.adjustAlpha(0.8f)) setTextColor(background.getContrastColor()) + if (attachment.filename.isNotEmpty()) { + thread_sent_attachment_label.text = attachment.filename + } setOnClickListener { launchViewIntent(uri, mimetype) } } } 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 e6c0b9f7..98adef5d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt @@ -222,17 +222,24 @@ fun Context.getMmsAttachment(id: Int): MessageAttachment? { val selectionArgs = arrayOf(id.toString()) val messageAttachment = MessageAttachment(id, "", arrayListOf()) + var attachmentName = "" queryCursor(uri, projection, selection, selectionArgs, showErrors = true) { cursor -> val partId = cursor.getStringValue(Mms._ID) val mimetype = cursor.getStringValue(Mms.Part.CONTENT_TYPE) if (mimetype == "text/plain") { messageAttachment.text = cursor.getStringValue(Mms.Part.TEXT) ?: "" } else if (mimetype.startsWith("image/") || mimetype.startsWith("video/")) { - val attachment = Attachment(Uri.withAppendedPath(uri, partId), mimetype, 0, 0) + val attachment = Attachment(Uri.withAppendedPath(uri, partId), mimetype, 0, 0, "") messageAttachment.attachments.add(attachment) } else if (mimetype != "application/smil") { - val attachment = Attachment(Uri.withAppendedPath(uri, partId), mimetype, 0, 0) + val attachment = Attachment(Uri.withAppendedPath(uri, partId), mimetype, 0, 0, attachmentName) messageAttachment.attachments.add(attachment) + } else { + val text = cursor.getStringValue(Mms.Part.TEXT) + val cutName = text.substringAfter("ref src=\"").substringBefore("\"") + if (cutName.isNotEmpty()) { + attachmentName = cutName + } } } 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 fb904f5b..f7f4ab7a 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 mimetype: String, var width: Int, var height: Int) +data class Attachment(var uri: Uri, var mimetype: String, var width: Int, var height: Int, var filename: String)