add handling for multiple attachments in one mms

This commit is contained in:
tibbi 2020-04-12 19:30:03 +02:00
parent a5d8633593
commit cc6dcafa88
4 changed files with 54 additions and 41 deletions

View File

@ -30,6 +30,7 @@ import com.simplemobiletools.smsmessenger.models.Message
import com.simplemobiletools.smsmessenger.models.ThreadDateTime import com.simplemobiletools.smsmessenger.models.ThreadDateTime
import com.simplemobiletools.smsmessenger.models.ThreadError import com.simplemobiletools.smsmessenger.models.ThreadError
import com.simplemobiletools.smsmessenger.models.ThreadItem 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_message.view.*
import kotlinx.android.synthetic.main.item_thread_date_time.view.* import kotlinx.android.synthetic.main.item_thread_date_time.view.*
@ -187,8 +188,13 @@ class ThreadAdapter(
thread_message_body.setTextColor(background.getContrastColor()) thread_message_body.setTextColor(background.getContrastColor())
} }
thread_mesage_attachments_holder.removeAllViews()
if (message.attachment?.attachments?.isNotEmpty() == true) { if (message.attachment?.attachments?.isNotEmpty() == true) {
val attachment = message.attachment.attachments.first() message.attachment.attachments.forEach {
val attachment = it
val imageView = layoutInflater.inflate(R.layout.item_attachment_image, null)
thread_mesage_attachments_holder.addView(imageView)
val type = attachment.type val type = attachment.type
if (type.startsWith("image/") || type.startsWith("video/")) { if (type.startsWith("image/") || type.startsWith("video/")) {
val uri = attachment.uri val uri = attachment.uri
@ -203,15 +209,17 @@ class ThreadAdapter(
.listener(object : RequestListener<Drawable> { .listener(object : RequestListener<Drawable> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean { override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
thread_message_play_outline.beGone() thread_message_play_outline.beGone()
thread_mesage_attachments_holder.removeView(imageView)
return false return false
} }
override fun onResourceReady(dr: Drawable?, a: Any?, t: Target<Drawable>?, d: DataSource?, i: Boolean) = false override fun onResourceReady(dr: Drawable?, a: Any?, t: Target<Drawable>?, d: DataSource?, i: Boolean) =
false
}) })
.into(thread_message_image) .into(imageView.attachment_image)
thread_message_image.setOnClickListener { attachment_image.setOnClickListener {
Intent().apply { Intent().apply {
action = Intent.ACTION_VIEW action = Intent.ACTION_VIEW
setDataAndType(uri, type) setDataAndType(uri, type)
@ -225,6 +233,7 @@ class ThreadAdapter(
} }
} }
} }
}
private fun setupDateTime(view: View, dateTime: ThreadDateTime) { private fun setupDateTime(view: View, dateTime: ThreadDateTime) {
view.apply { view.apply {

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/attachment_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:paddingBottom="@dimen/medium_margin" />

View File

@ -26,13 +26,11 @@
android:layout_marginEnd="@dimen/medium_margin" android:layout_marginEnd="@dimen/medium_margin"
android:visibility="gone" /> android:visibility="gone" />
<ImageView <LinearLayout
android:id="@+id/thread_message_image" android:id="@+id/thread_mesage_attachments_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/medium_margin" android:orientation="vertical" />
android:layout_toEndOf="@+id/thread_message_photo"
android:adjustViewBounds="true" />
<ImageView <ImageView
android:id="@+id/thread_message_play_outline" android:id="@+id/thread_message_play_outline"

View File

@ -17,19 +17,18 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.7"> app:layout_constraintWidth_percent="0.7">
<ImageView <LinearLayout
android:id="@+id/thread_message_image" android:id="@+id/thread_mesage_attachments_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/medium_margin" android:orientation="vertical" />
android:adjustViewBounds="true" />
<ImageView <ImageView
android:id="@+id/thread_message_play_outline" android:id="@+id/thread_message_play_outline"
android:layout_width="@dimen/play_outline_size" android:layout_width="@dimen/play_outline_size"
android:layout_height="@dimen/play_outline_size" android:layout_height="@dimen/play_outline_size"
android:layout_alignEnd="@+id/thread_message_image" android:layout_alignEnd="@+id/thread_mesage_attachments_holder"
android:layout_alignBottom="@+id/thread_message_image" android:layout_alignBottom="@+id/thread_mesage_attachments_holder"
android:layout_margin="@dimen/medium_margin" android:layout_margin="@dimen/medium_margin"
android:src="@drawable/ic_play_outline" android:src="@drawable/ic_play_outline"
android:visibility="gone" /> android:visibility="gone" />
@ -38,7 +37,7 @@
android:id="@+id/thread_message_body" android:id="@+id/thread_message_body"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/thread_message_image" android:layout_below="@+id/thread_mesage_attachments_holder"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:background="@drawable/item_sent_background" android:background="@drawable/item_sent_background"
android:padding="@dimen/normal_margin" android:padding="@dimen/normal_margin"