Media messages send status implementation.

This commit is contained in:
Onuray Sahin 2021-02-25 18:24:23 +03:00 committed by Benoit Marty
parent c741916d9f
commit 0b98dfc976
8 changed files with 47 additions and 62 deletions

View file

@ -33,7 +33,12 @@ import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.ReferencesAggregatedContent
import org.matrix.android.sdk.api.session.room.model.message.MessageAudioContent
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
import org.matrix.android.sdk.api.session.room.model.message.MessageFileContent
import org.matrix.android.sdk.api.session.room.model.message.MessageImageContent
import org.matrix.android.sdk.api.session.room.model.message.MessageVerificationRequestContent
import org.matrix.android.sdk.api.session.room.model.message.MessageVideoContent
import org.matrix.android.sdk.api.session.room.send.SendState
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
@ -73,7 +78,14 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses
val isSentByMe = event.root.senderId == session.myUserId
val sendStateDecoration = if (isSentByMe) {
getSendStateDecoration(event.root.sendState, prevEvent?.root?.sendState, event.readReceipts.any { it.user.userId != session.myUserId })
val isMedia = when (event.root.content?.toModel<MessageContent>()) {
is MessageImageContent,
is MessageVideoContent,
is MessageAudioContent,
is MessageFileContent -> true
else -> false
}
getSendStateDecoration(event.root.sendState, prevEvent?.root?.sendState, event.readReceipts.any { it.user.userId != session.myUserId }, isMedia)
} else {
SendStateDecoration.NONE
}
@ -124,9 +136,9 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses
)
}
private fun getSendStateDecoration(eventSendState: SendState, prevEventSendState: SendState?, anyReadReceipts: Boolean): SendStateDecoration {
private fun getSendStateDecoration(eventSendState: SendState, prevEventSendState: SendState?, anyReadReceipts: Boolean, isMedia: Boolean): SendStateDecoration {
return if (eventSendState.isSending()) {
SendStateDecoration.SENDING
if (isMedia) SendStateDecoration.SENDING_MEDIA else SendStateDecoration.SENDING_NON_MEDIA
} else if (eventSendState.hasFailed()) {
SendStateDecoration.FAILED
} else if (eventSendState.isSent() && !prevEventSendState?.isSent().orFalse() && !anyReadReceipts) {

View file

@ -19,6 +19,7 @@ package im.vector.app.features.home.room.detail.timeline.item
import android.graphics.Typeface
import android.view.View
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.annotation.IdRes
import androidx.core.view.isInvisible
@ -85,23 +86,28 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
// Render send state indicator
holder.sendStateImageView.isVisible = true
holder.eventSendingIndicator.isVisible = false
when (attributes.informationData.sendStateDecoration) {
SendStateDecoration.SENDING -> {
SendStateDecoration.SENDING_NON_MEDIA -> {
holder.sendStateImageView
.apply { setImageResource(R.drawable.ic_sending_message) }
.apply { contentDescription = context.getString(R.string.event_status_a11y_sending) }
}
SendStateDecoration.SENT -> {
SendStateDecoration.SENT -> {
holder.sendStateImageView
.apply { setImageResource(R.drawable.ic_message_sent) }
.apply { contentDescription = context.getString(R.string.event_status_a11y_sent) }
}
SendStateDecoration.FAILED -> {
SendStateDecoration.FAILED -> {
holder.sendStateImageView
.apply { setImageResource(R.drawable.ic_sending_message_failed) }
.apply { contentDescription = context.getString(R.string.event_status_a11y_failed) }
}
SendStateDecoration.NONE -> holder.sendStateImageView.isVisible = false
SendStateDecoration.SENDING_MEDIA -> {
holder.sendStateImageView.isVisible = false
holder.eventSendingIndicator.isVisible = true
}
SendStateDecoration.NONE -> holder.sendStateImageView.isVisible = false
}
}
@ -121,6 +127,7 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
val memberNameView by bind<TextView>(R.id.messageMemberNameView)
val timeView by bind<TextView>(R.id.messageTimeView)
val sendStateImageView by bind<ImageView>(R.id.messageSendStateImageView)
val eventSendingIndicator by bind<ProgressBar>(R.id.eventSendingIndicator)
}
/**

View file

@ -87,13 +87,6 @@ abstract class MessageFileItem : AbsMessageItem<MessageFileItem.Holder>() {
holder.fileImageWrapper.setOnClickListener(attributes.itemClickListener)
holder.fileImageWrapper.setOnLongClickListener(attributes.itemLongClickListener)
holder.filenameView.paintFlags = (holder.filenameView.paintFlags or Paint.UNDERLINE_TEXT_FLAG)
holder.eventSendingIndicator.isVisible = when (attributes.informationData.sendState) {
SendState.UNSENT,
SendState.ENCRYPTING,
SendState.SENDING -> true
else -> false
}
}
override fun unbind(holder: Holder) {
@ -111,7 +104,6 @@ abstract class MessageFileItem : AbsMessageItem<MessageFileItem.Holder>() {
val fileImageWrapper by bind<ViewGroup>(R.id.messageFileImageView)
val fileDownloadProgress by bind<ProgressBar>(R.id.messageFileProgressbar)
val filenameView by bind<TextView>(R.id.messageFilenameView)
val eventSendingIndicator by bind<ProgressBar>(R.id.eventSendingIndicator)
}
companion object {

View file

@ -69,16 +69,7 @@ abstract class MessageImageVideoItem : AbsMessageItem<MessageImageVideoItem.Hold
ViewCompat.setTransitionName(holder.imageView, "imagePreview_${id()}")
holder.mediaContentView.setOnClickListener(attributes.itemClickListener)
holder.mediaContentView.setOnLongClickListener(attributes.itemLongClickListener)
// The sending state color will be apply to the progress text
renderSendState(holder.imageView, null, holder.failedToSendIndicator)
holder.playContentView.visibility = if (playable) View.VISIBLE else View.GONE
holder.eventSendingIndicator.isVisible = when (attributes.informationData.sendState) {
SendState.UNSENT,
SendState.ENCRYPTING,
SendState.SENDING -> true
else -> false
}
}
override fun unbind(holder: Holder) {
@ -96,10 +87,7 @@ abstract class MessageImageVideoItem : AbsMessageItem<MessageImageVideoItem.Hold
val progressLayout by bind<ViewGroup>(R.id.messageMediaUploadProgressLayout)
val imageView by bind<ImageView>(R.id.messageThumbnailView)
val playContentView by bind<ImageView>(R.id.messageMediaPlayView)
val mediaContentView by bind<ViewGroup>(R.id.messageContentMedia)
val failedToSendIndicator by bind<ImageView>(R.id.messageFailToSendIndicator)
val eventSendingIndicator by bind<ProgressBar>(R.id.eventSendingIndicator)
}
companion object {

View file

@ -87,7 +87,8 @@ enum class E2EDecoration {
enum class SendStateDecoration {
NONE,
SENDING,
SENDING_NON_MEDIA,
SENDING_MEDIA,
SENT,
FAILED
}

View file

@ -80,8 +80,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/messageMemberNameView"
android:layout_toEndOf="@id/messageStartGuideline"
android:layout_toStartOf="@id/messageSendStateImageView"
android:layout_toEndOf="@id/messageStartGuideline"
android:addStatesFromChildren="true">
<ViewStub
@ -138,12 +138,28 @@
android:id="@+id/messageSendStateImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_sending_message"
android:layout_alignBottom="@+id/viewStubContainer"
android:layout_alignParentEnd="true"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:contentDescription="@string/event_status_a11y_sending" />
android:layout_marginBottom="4dp"
android:contentDescription="@string/event_status_a11y_sending"
android:src="@drawable/ic_sending_message"
android:visibility="gone"
tools:visibility="visible" />
<ProgressBar
android:id="@+id/eventSendingIndicator"
style="?android:attr/progressBarStyleSmall"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignBottom="@+id/viewStubContainer"
android:layout_alignParentEnd="true"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:visibility="gone"
tools:visibility="visible" />
<LinearLayout
android:id="@+id/informationBottom"

View file

@ -55,16 +55,6 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="A filename here" />
<ProgressBar
android:id="@+id/eventSendingIndicator"
style="?android:attr/progressBarStyleSmall"
android:layout_width="16dp"
android:layout_height="16dp"
android:visibility="gone"
app:layout_constraintStart_toEndOf="@id/messageFilenameView"
app:layout_constraintTop_toTopOf="@id/messageFilenameView"
tools:visibility="visible" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/horizontalBarrier"

View file

@ -18,27 +18,6 @@
tools:layout_height="300dp"
tools:src="@tools:sample/backgrounds/scenic" />
<ImageView
android:id="@+id/messageFailToSendIndicator"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_marginStart="2dp"
android:contentDescription="@string/a11y_error_message_not_sent"
android:src="@drawable/ic_warning_badge"
android:visibility="gone"
app:layout_constraintStart_toEndOf="@id/messageThumbnailView"
app:layout_constraintTop_toTopOf="@id/messageThumbnailView"
tools:visibility="visible" />
<ProgressBar
android:id="@+id/eventSendingIndicator"
style="?android:attr/progressBarStyleSmall"
android:layout_width="16dp"
android:layout_height="16dp"
android:visibility="gone"
app:layout_constraintStart_toEndOf="@id/messageThumbnailView"
app:layout_constraintTop_toBottomOf="@id/messageFailToSendIndicator" />
<ImageView
android:id="@+id/messageMediaPlayView"
android:layout_width="40dp"