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 cace2918..06366948 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt @@ -44,13 +44,12 @@ import kotlinx.android.synthetic.main.item_received_message.view.thread_mesage_a import kotlinx.android.synthetic.main.item_received_message.view.thread_message_body import kotlinx.android.synthetic.main.item_received_message.view.thread_message_holder import kotlinx.android.synthetic.main.item_received_message.view.thread_message_play_outline -import kotlinx.android.synthetic.main.item_received_unknown_attachment.view.* import kotlinx.android.synthetic.main.item_sent_message.view.* -import kotlinx.android.synthetic.main.item_sent_unknown_attachment.view.* import kotlinx.android.synthetic.main.item_thread_date_time.view.* import kotlinx.android.synthetic.main.item_thread_error.view.* import kotlinx.android.synthetic.main.item_thread_sending.view.* import kotlinx.android.synthetic.main.item_thread_success.view.* +import kotlinx.android.synthetic.main.item_unknown_attachment.view.* import java.util.* class ThreadAdapter( @@ -286,12 +285,10 @@ class ThreadAdapter( if (message.attachment?.attachments?.isNotEmpty() == true) { for (attachment in message.attachment.attachments) { val mimetype = attachment.mimetype - if (mimetype.isImageMimeType() || mimetype.startsWith("video/")) { - setupImageView(holder, view, message, attachment) - } else if (mimetype.isVCardMimeType()) { - setupVCardView(holder, view, message, attachment) - } else { - setupFileView(holder, view, message, attachment) + when { + mimetype.isImageMimeType() || mimetype.isVideoMimeType() -> setupImageView(holder, view, message, attachment) + mimetype.isVCardMimeType() -> setupVCardView(holder, view, message, attachment) + else -> setupFileView(holder, view, message, attachment) } thread_message_play_outline.beVisibleIf(mimetype.startsWith("video/")) @@ -454,51 +451,41 @@ class ThreadAdapter( val mimetype = attachment.mimetype val uri = attachment.getUri() parent.apply { - 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 { - if (actModeCallback.isSelectable) { - holder.viewClicked(message) - } else { - launchViewIntent(uri, mimetype, attachment.filename) - } - } - setOnLongClickListener { - holder.viewLongClicked() - true - } + val attachmentView = layoutInflater.inflate(R.layout.item_unknown_attachment, null).apply { + if (attachment.filename.isNotEmpty()) { + filename.text = attachment.filename + } + + val size = context.contentResolver + .openInputStream(uri) + ?.use { it.readBytes() } + ?.size + + if (size != null) { + file_size.beVisible() + file_size.text = size.formatSize() + } else { + file_size.beGone() + } + + background.applyColorFilter(textColor) + filename.setTextColor(textColor) + file_size.setTextColor(textColor) + icon.background.setTint(properPrimaryColor) + + setOnClickListener { + if (actModeCallback.isSelectable) { + holder.viewClicked(message) + } else { + launchViewIntent(uri, mimetype, attachment.filename) } } - thread_mesage_attachments_holder.addView(attachmentView) - } else { - val background = context.getProperPrimaryColor() - val attachmentView = layoutInflater.inflate(R.layout.item_sent_unknown_attachment, null).apply { - thread_sent_attachment_label.apply { - this.background.applyColorFilter(background) - setTextColor(background.getContrastColor()) - if (attachment.filename.isNotEmpty()) { - thread_sent_attachment_label.text = attachment.filename - } - setOnClickListener { - if (actModeCallback.isSelectable) { - holder.viewClicked(message) - } else { - launchViewIntent(uri, mimetype, attachment.filename) - } - } - setOnLongClickListener { - holder.viewLongClicked() - true - } - } + setOnLongClickListener { + holder.viewLongClicked() + true } - thread_mesage_attachments_holder.addView(attachmentView) } + thread_mesage_attachments_holder.addView(attachmentView) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/String.kt index 89fb0f03..ac2b8948 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/String.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/String.kt @@ -15,6 +15,10 @@ fun String.isImageMimeType(): Boolean { return lowercase().startsWith("image") } +fun String.isVideoMimeType(): Boolean { + return lowercase().startsWith("video") +} + fun String.isVCardMimeType(): Boolean { val lowercase = lowercase() return lowercase.endsWith("x-vcard") || lowercase.endsWith("vcard") diff --git a/app/src/main/res/drawable/ic_document_vector.xml b/app/src/main/res/drawable/ic_document_vector.xml new file mode 100644 index 00000000..e7ef3d4b --- /dev/null +++ b/app/src/main/res/drawable/ic_document_vector.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/item_received_unknown_attachment.xml b/app/src/main/res/layout/item_received_unknown_attachment.xml deleted file mode 100644 index b56653ca..00000000 --- a/app/src/main/res/layout/item_received_unknown_attachment.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - diff --git a/app/src/main/res/layout/item_unknown_attachment.xml b/app/src/main/res/layout/item_unknown_attachment.xml new file mode 100644 index 00000000..8b884084 --- /dev/null +++ b/app/src/main/res/layout/item_unknown_attachment.xml @@ -0,0 +1,51 @@ + + + + + + + + + +