From 0244fea222712b961fc84842b4c9954af6833918 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 10 Feb 2022 17:51:49 +0100 Subject: [PATCH] Reactions: more refinements --- .../ui-styles/src/main/res/values/dimens.xml | 3 ++- .../helper/MessageInformationDataFactory.kt | 4 +-- .../timeline/item/AbsBaseMessageItem.kt | 25 ++++++++++++------- .../reactions/widget/ReactionButton.kt | 1 + .../main/res/drawable/reaction_divider.xml | 4 +-- .../src/main/res/layout/reaction_button.xml | 9 +++---- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/library/ui-styles/src/main/res/values/dimens.xml b/library/ui-styles/src/main/res/values/dimens.xml index 9a3929094a..c8f1ec5c86 100644 --- a/library/ui-styles/src/main/res/values/dimens.xml +++ b/library/ui-styles/src/main/res/values/dimens.xml @@ -61,7 +61,8 @@ 300dp 12dp - 30dp + 28dp + 40dp 0.05 diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt index 2bd2257cf7..59b39d17ef 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt @@ -50,7 +50,7 @@ import javax.inject.Inject class MessageInformationDataFactory @Inject constructor(private val session: Session, private val dateFormatter: VectorDateFormatter, private val messageLayoutFactory: TimelineMessageLayoutFactory, - private val reactionListFactory: ReactionsSummaryFactory) { + private val reactionsSummaryFactory: ReactionsSummaryFactory) { fun create(params: TimelineItemFactoryParams): MessageInformationData { val event = params.event @@ -93,7 +93,7 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses avatarUrl = event.senderInfo.avatarUrl, memberName = event.senderInfo.disambiguatedDisplayName, messageLayout = messageLayout, - reactionsSummary = reactionListFactory.create(event, params.callback), + reactionsSummary = reactionsSummaryFactory.create(event, params.callback), pollResponseAggregatedSummary = event.annotations?.pollResponseSummary?.let { PollResponseData( myVote = it.aggregatedContent?.myVote, diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt index 6d0714e929..07fa4192c8 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt @@ -17,7 +17,6 @@ package im.vector.app.features.home.room.detail.timeline.item import android.annotation.SuppressLint -import android.content.Context import android.view.Gravity import android.view.View import android.view.ViewGroup @@ -30,6 +29,7 @@ import im.vector.app.R import im.vector.app.core.epoxy.ClickListener import im.vector.app.core.epoxy.onClick import im.vector.app.core.ui.views.ShieldImageView +import im.vector.app.core.utils.DimensionConverter import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.MessageColorProvider import im.vector.app.features.home.room.detail.timeline.TimelineEventController @@ -38,6 +38,9 @@ import im.vector.app.features.reactions.widget.ReactionButton import org.matrix.android.sdk.api.crypto.RoomEncryptionTrustLevel import org.matrix.android.sdk.api.session.room.send.SendState + +private const val MAX_REACTIONS_TO_SHOW = 8 + /** * Base timeline item with reactions and read receipts. * Manages associated click listeners and send status. @@ -99,7 +102,7 @@ abstract class AbsBaseMessageItem : BaseEventItem val reactionsToShow = if (reactionsSummary.showAll) { reactions } else { - reactions.take(8) + reactions.take(MAX_REACTIONS_TO_SHOW) } reactionsToShow.forEach { reaction -> val reactionButton = ReactionButton(holder.view.context) @@ -111,19 +114,19 @@ abstract class AbsBaseMessageItem : BaseEventItem reactionButton.isEnabled = reaction.synced holder.reactionsContainer.addView(reactionButton) } - if (reactions.count() > 8) { - val showReactionsTextView = createReactionTextView(holder.view.context) + if (reactions.count() > MAX_REACTIONS_TO_SHOW) { + val showReactionsTextView = createReactionTextView(holder, 6) if (reactionsSummary.showAll) { showReactionsTextView.setText(R.string.message_reaction_show_less) showReactionsTextView.onClick { reactionsSummary.onShowLessClicked() } } else { - val moreCount = reactions.count() - 8 + val moreCount = reactions.count() - MAX_REACTIONS_TO_SHOW showReactionsTextView.text = holder.view.resources.getString(R.string.message_reaction_show_more, moreCount) showReactionsTextView.onClick { reactionsSummary.onShowMoreClicked() } } holder.reactionsContainer.addView(showReactionsTextView) } - val addMoreReactionsTextView = createReactionTextView(holder.view.context) + val addMoreReactionsTextView = createReactionTextView(holder, 14) addMoreReactionsTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_add_reaction_small, 0, 0, 0) addMoreReactionsTextView.onClick { reactionsSummary.onAddMoreClicked() } holder.reactionsContainer.addView(addMoreReactionsTextView) @@ -131,13 +134,14 @@ abstract class AbsBaseMessageItem : BaseEventItem } } - private fun createReactionTextView(context: Context): TextView { - return TextView(context).apply { + private fun createReactionTextView(holder: H, horizontalPaddingDp: Int): TextView { + return TextView(holder.view.context).apply { textSize = 10f gravity = Gravity.CENTER minimumHeight = resources.getDimensionPixelSize(R.dimen.chat_reaction_min_height) + minimumWidth = resources.getDimensionPixelSize(R.dimen.chat_reaction_min_width) background = getDrawable(context, R.drawable.reaction_rounded_rect_shape_off) - val padding = resources.getDimensionPixelSize(R.dimen.layout_horizontal_margin) + val padding = holder.dimensionConverter.dpToPx(horizontalPaddingDp) setPadding(padding, 0, padding, 0) } } @@ -155,6 +159,9 @@ abstract class AbsBaseMessageItem : BaseEventItem } abstract class Holder(@IdRes stubId: Int) : BaseEventItem.BaseHolder(stubId) { + val dimensionConverter by lazy { + DimensionConverter(view.resources) + } val reactionsContainer by bind(R.id.reactionsContainer) val e2EDecorationView by bind(R.id.messageE2EDecoration) } diff --git a/vector/src/main/java/im/vector/app/features/reactions/widget/ReactionButton.kt b/vector/src/main/java/im/vector/app/features/reactions/widget/ReactionButton.kt index d307e1fd16..5553c1faab 100644 --- a/vector/src/main/java/im/vector/app/features/reactions/widget/ReactionButton.kt +++ b/vector/src/main/java/im/vector/app/features/reactions/widget/ReactionButton.kt @@ -69,6 +69,7 @@ class ReactionButton @JvmOverloads constructor(context: Context, inflate(context, R.layout.reaction_button, this) orientation = HORIZONTAL minimumHeight = resources.getDimensionPixelSize(R.dimen.chat_reaction_min_height) + minimumWidth = resources.getDimensionPixelSize(R.dimen.chat_reaction_min_width) gravity = Gravity.CENTER layoutDirection = View.LAYOUT_DIRECTION_LOCALE views = ReactionButtonBinding.bind(this) diff --git a/vector/src/main/res/drawable/reaction_divider.xml b/vector/src/main/res/drawable/reaction_divider.xml index d68b6a9094..1d7ee57084 100644 --- a/vector/src/main/res/drawable/reaction_divider.xml +++ b/vector/src/main/res/drawable/reaction_divider.xml @@ -2,7 +2,7 @@ + android:width="4dp" + android:height="4dp" /> \ No newline at end of file diff --git a/vector/src/main/res/layout/reaction_button.xml b/vector/src/main/res/layout/reaction_button.xml index a6d84407ce..f0a8011220 100644 --- a/vector/src/main/res/layout/reaction_button.xml +++ b/vector/src/main/res/layout/reaction_button.xml @@ -3,11 +3,11 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" - android:layout_height="26dp" + android:layout_height="@dimen/chat_reaction_min_height" android:background="@drawable/reaction_rounded_rect_shape" android:clipChildren="false" android:gravity="center" - android:minWidth="44dp" + android:minWidth="@dimen/chat_reaction_min_width" tools:parentTag="android.widget.LinearLayout"> @@ -20,12 +20,11 @@ android:id="@+id/reactionText" style="@style/Widget.Vector.TextView.Caption" android:layout_width="wrap_content" - android:layout_height="20dp" + android:layout_height="wrap_content" android:layout_marginStart="6dp" android:ellipsize="middle" android:gravity="center" android:maxEms="10" - android:minWidth="20dp" android:singleLine="true" android:textColor="@color/emoji_color" tools:text="* Party Parrot Again * 👀" /> @@ -36,7 +35,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="2dp" - android:layout_marginEnd="8dp" + android:layout_marginEnd="6dp" android:gravity="center" android:maxLines="1" android:textColor="?vctr_content_secondary"