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 40906494..1c06781a 100644
--- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt
@@ -2,6 +2,7 @@ package com.simplemobiletools.smsmessenger.adapters
import android.content.Intent
import android.graphics.drawable.Drawable
+import android.net.Uri
import android.view.Menu
import android.view.View
import android.view.ViewGroup
@@ -33,6 +34,8 @@ import com.simplemobiletools.smsmessenger.models.ThreadError
import com.simplemobiletools.smsmessenger.models.ThreadItem
import kotlinx.android.synthetic.main.item_attachment_image.view.*
import kotlinx.android.synthetic.main.item_received_message.view.*
+import kotlinx.android.synthetic.main.item_received_unknown_attachment.view.*
+import kotlinx.android.synthetic.main.item_sent_unknown_attachment.view.*
import kotlinx.android.synthetic.main.item_thread_date_time.view.*
class ThreadAdapter(
@@ -177,6 +180,7 @@ class ThreadAdapter(
private fun setupView(view: View, message: Message) {
view.apply {
thread_message_body.text = message.body
+ thread_message_body.beVisibleIf(message.body.isNotEmpty())
if (message.isReceivedMessage()) {
thread_message_sender_photo.beVisible()
@@ -191,14 +195,13 @@ class ThreadAdapter(
thread_mesage_attachments_holder.removeAllViews()
if (message.attachment?.attachments?.isNotEmpty() == true) {
- message.attachment.attachments.forEach {
- val attachment = it
- val imageView = layoutInflater.inflate(R.layout.item_attachment_image, null)
- thread_mesage_attachments_holder.addView(imageView)
-
+ for (attachment in message.attachment.attachments) {
val type = attachment.type
+ val uri = attachment.uri
if (type.startsWith("image/") || type.startsWith("video/")) {
- val uri = attachment.uri
+ val imageView = layoutInflater.inflate(R.layout.item_attachment_image, null)
+ thread_mesage_attachments_holder.addView(imageView)
+
val isTallImage = attachment.height > attachment.width
val transformation = if (isTallImage) CenterCrop() else FitCenter()
val options = RequestOptions()
@@ -225,13 +228,26 @@ class ThreadAdapter(
}
builder.into(imageView.attachment_image)
- imageView.attachment_image.setOnClickListener {
- Intent().apply {
- action = Intent.ACTION_VIEW
- setDataAndType(uri, type)
- addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
- activity.startActivity(this)
+ imageView.attachment_image.setOnClickListener { launchViewIntent(uri, type) }
+ } 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) }
+ }
}
+ thread_mesage_attachments_holder.addView(attachmentView)
+ } else {
+ val background = context.getAdjustedPrimaryColor()
+ val attachmentView = layoutInflater.inflate(R.layout.item_sent_unknown_attachment, null).apply {
+ thread_sent_attachment_label.apply {
+ this.background.applyColorFilter(background.adjustAlpha(0.8f))
+ setTextColor(background.getContrastColor())
+ setOnClickListener { launchViewIntent(uri, type) }
+ }
+ }
+ thread_mesage_attachments_holder.addView(attachmentView)
}
}
@@ -241,6 +257,20 @@ class ThreadAdapter(
}
}
+ private fun launchViewIntent(uri: Uri, type: String) {
+ Intent().apply {
+ action = Intent.ACTION_VIEW
+ setDataAndType(uri, type)
+ addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
+
+ if (resolveActivity(activity.packageManager) != null) {
+ activity.startActivity(this)
+ } else {
+ activity.toast(R.string.no_app_found)
+ }
+ }
+ }
+
private fun setupDateTime(view: View, dateTime: ThreadDateTime) {
view.apply {
thread_date_time.text = dateTime.date.formatDateOrTime(context, false)
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 48c49921..844900b8 100644
--- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt
@@ -230,6 +230,9 @@ fun Context.getMmsAttachment(id: Int): MessageAttachment? {
} else if (type.startsWith("image/") || type.startsWith("video/")) {
val attachment = Attachment(Uri.withAppendedPath(uri, partId), type, 0, 0)
messageAttachment.attachments.add(attachment)
+ } else if (type != "application/smil") {
+ val attachment = Attachment(Uri.withAppendedPath(uri, partId), type, 0, 0)
+ messageAttachment.attachments.add(attachment)
}
}
diff --git a/app/src/main/res/layout/item_received_unknown_attachment.xml b/app/src/main/res/layout/item_received_unknown_attachment.xml
new file mode 100644
index 00000000..679fff86
--- /dev/null
+++ b/app/src/main/res/layout/item_received_unknown_attachment.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/item_sent_unknown_attachment.xml b/app/src/main/res/layout/item_sent_unknown_attachment.xml
new file mode 100644
index 00000000..4c7b3ea2
--- /dev/null
+++ b/app/src/main/res/layout/item_sent_unknown_attachment.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/strings.xml b/app/src/main/res/values-pt/strings.xml
similarity index 100%
rename from app/src/main/res/strings.xml
rename to app/src/main/res/values-pt/strings.xml
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index af7d9244..e204c9fe 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -4,6 +4,7 @@
Type a messageā¦
Message has not been sent.
Add Person
+ Attachment
Create new message