Some cleanup

This commit is contained in:
Benoit Marty 2021-03-09 16:56:31 +01:00 committed by Benoit Marty
parent f64086a25f
commit 3ca25f9006
7 changed files with 154 additions and 112 deletions

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.core.ui.views
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.view.isVisible
import im.vector.app.R
import im.vector.app.features.home.room.detail.timeline.item.SendStateDecoration
class SendStateImageView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr) {
init {
if (isInEditMode) {
render(SendStateDecoration.SENT)
}
}
fun render(sendState: SendStateDecoration) {
isVisible = when (sendState) {
SendStateDecoration.SENDING_NON_MEDIA -> {
setImageResource(R.drawable.ic_sending_message)
contentDescription = context.getString(R.string.event_status_a11y_sending)
true
}
SendStateDecoration.SENT -> {
setImageResource(R.drawable.ic_message_sent)
contentDescription = context.getString(R.string.event_status_a11y_sent)
true
}
SendStateDecoration.FAILED -> {
setImageResource(R.drawable.ic_sending_message_failed)
contentDescription = context.getString(R.string.event_status_a11y_failed)
true
}
SendStateDecoration.SENDING_MEDIA,
SendStateDecoration.NONE -> {
false
}
}
}
}

View File

@ -1441,7 +1441,10 @@ class RoomDetailViewModel @AssistedInject constructor(
roomSummariesHolder.set(summary)
setState {
val typingMessage = typingHelper.getTypingMessage(summary.typingUsers)
copy(typingMessage = typingMessage, hasFailedSending = summary.hasFailedSending)
copy(
typingMessage = typingMessage,
hasFailedSending = summary.hasFailedSending
)
}
if (summary.membership == Membership.INVITE) {
summary.inviterId?.let { inviterId ->

View File

@ -79,7 +79,6 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses
// SendState Decoration
val isSentByMe = event.root.senderId == session.myUserId
val isLocalEcho = LocalEcho.isLocalEchoId(event.eventId)
val sendStateDecoration = if (isSentByMe) {
val isMedia = when (event.root.content?.toModel<MessageContent>()) {
is MessageImageContent,
@ -93,7 +92,8 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses
prevEventSendState = prevEvent?.root?.sendState,
anyReadReceipts = event.readReceipts.any { it.user.userId != session.myUserId },
isMedia = isMedia,
isLocalEcho = isLocalEcho)
isLocalEcho = LocalEcho.isLocalEchoId(event.eventId)
)
} else {
SendStateDecoration.NONE
}

View File

@ -26,6 +26,7 @@ import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import im.vector.app.R
import im.vector.app.core.ui.views.SendStateImageView
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.detail.timeline.MessageColorProvider
@ -85,30 +86,8 @@ 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_NON_MEDIA -> {
holder.sendStateImageView
.apply { setImageResource(R.drawable.ic_sending_message) }
.apply { contentDescription = context.getString(R.string.event_status_a11y_sending) }
}
SendStateDecoration.SENT -> {
holder.sendStateImageView
.apply { setImageResource(R.drawable.ic_message_sent) }
.apply { contentDescription = context.getString(R.string.event_status_a11y_sent) }
}
SendStateDecoration.FAILED -> {
holder.sendStateImageView
.apply { setImageResource(R.drawable.ic_sending_message_failed) }
.apply { contentDescription = context.getString(R.string.event_status_a11y_failed) }
}
SendStateDecoration.SENDING_MEDIA -> {
holder.sendStateImageView.isVisible = false
holder.eventSendingIndicator.isVisible = true
}
SendStateDecoration.NONE -> holder.sendStateImageView.isVisible = false
}
holder.sendStateImageView.render(attributes.informationData.sendStateDecoration)
holder.eventSendingIndicator.isVisible = attributes.informationData.sendStateDecoration == SendStateDecoration.SENDING_MEDIA
}
override fun unbind(holder: H) {
@ -126,7 +105,7 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
val avatarImageView by bind<ImageView>(R.id.messageAvatarImageView)
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 sendStateImageView by bind<SendStateImageView>(R.id.messageSendStateImageView)
val eventSendingIndicator by bind<ProgressBar>(R.id.eventSendingIndicator)
}

View File

@ -86,7 +86,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="top"
app:constraint_referenced_ids="composerLayout,notificationAreaView, failedMessagesWarningView" />
app:constraint_referenced_ids="composerLayout,notificationAreaView,failedMessagesWarningView" />
<im.vector.app.features.sync.widget.SyncStateView
android:id="@+id/syncStateView"

View File

@ -134,7 +134,7 @@
</FrameLayout>
<ImageView
<im.vector.app.core.ui.views.SendStateImageView
android:id="@+id/messageSendStateImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -1,40 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<View
android:id="@+id/failedMessagesWarningDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="@dimen/layout_horizontal_margin"
android:layout_marginTop="8dp"
android:layout_marginEnd="@dimen/layout_horizontal_margin"
android:background="?attr/vctr_list_divider_color"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/failedMessageWarningImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/event_status_a11y_failed"
android:src="@drawable/ic_sending_message_failed"
app:layout_constraintBottom_toBottomOf="@id/failedMessagesRetryButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/failedMessagesRetryButton" />
<TextView
android:id="@+id/failedMessagesWarningTextView"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginStart="@dimen/layout_horizontal_margin"
android:layout_marginEnd="8dp"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:text="@string/event_status_failed_messages_warning"
android:textColor="?riotx_text_primary"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="@id/failedMessageWarningImageView"
app:layout_constraintStart_toEndOf="@id/failedMessageWarningImageView"
app:layout_constraintTop_toTopOf="@id/failedMessageWarningImageView" />
app:drawableStartCompat="@drawable/ic_sending_message_failed"
app:layout_constraintBottom_toBottomOf="@id/failedMessagesRetryButton"
app:layout_constraintEnd_toStartOf="@+id/failedMessagesDeleteAllButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/failedMessagesRetryButton" />
<ImageButton
android:id="@+id/failedMessagesDeleteAllButton"
@ -53,7 +52,7 @@
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp"
android:layout_marginEnd="@dimen/layout_horizontal_margin"
android:text="@string/global_retry"
android:textSize="14sp"
app:icon="@drawable/ic_retry_sending_messages"
@ -62,4 +61,4 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/failedMessagesWarningDivider" />
</androidx.constraintlayout.widget.ConstraintLayout>
</merge>