From 87e740973cdf48f4507ad2197b4bd2238a931c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olive=CC=81r=20Falvai?= Date: Sat, 7 May 2022 20:06:03 +0200 Subject: [PATCH 1/3] Make read receipt avatar list compact --- .../app/core/ui/views/ReadReceiptsView.kt | 117 ++++++++---------- .../main/res/layout/view_read_receipts.xml | 30 ++--- vector/src/main/res/values/strings.xml | 2 +- 3 files changed, 60 insertions(+), 89 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/ui/views/ReadReceiptsView.kt b/vector/src/main/java/im/vector/app/core/ui/views/ReadReceiptsView.kt index 8477eddeea..2b7da49a71 100644 --- a/vector/src/main/java/im/vector/app/core/ui/views/ReadReceiptsView.kt +++ b/vector/src/main/java/im/vector/app/core/ui/views/ReadReceiptsView.kt @@ -28,8 +28,7 @@ import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.item.ReadReceiptData import im.vector.app.features.home.room.detail.timeline.item.toMatrixItem -private const val MAX_RECEIPT_DISPLAYED = 5 -private const val MAX_RECEIPT_DESCRIBED = 3 +private const val MAX_RECEIPT_DISPLAYED = 3 class ReadReceiptsView @JvmOverloads constructor( context: Context, @@ -45,13 +44,7 @@ class ReadReceiptsView @JvmOverloads constructor( } private val receiptAvatars: List by lazy { - listOf( - views.receiptAvatar1, - views.receiptAvatar2, - views.receiptAvatar3, - views.receiptAvatar4, - views.receiptAvatar5 - ) + listOf(views.receiptAvatar1, views.receiptAvatar2, views.receiptAvatar3) } private fun setupView() { @@ -60,66 +53,58 @@ class ReadReceiptsView @JvmOverloads constructor( } fun render(readReceipts: List, avatarRenderer: AvatarRenderer) { - if (readReceipts.isNotEmpty()) { - isVisible = true - for (index in 0 until MAX_RECEIPT_DISPLAYED) { - val receiptData = readReceipts.getOrNull(index) - if (receiptData == null) { - receiptAvatars[index].visibility = View.INVISIBLE - } else { - receiptAvatars[index].visibility = View.VISIBLE - avatarRenderer.render(receiptData.toMatrixItem(), receiptAvatars[index]) - } - } + receiptAvatars.forEach { it.isVisible = false } - val displayNames = readReceipts - .mapNotNull { it.displayName } - .filter { it.isNotBlank() } - .take(MAX_RECEIPT_DESCRIBED) + readReceipts.take(MAX_RECEIPT_DISPLAYED).forEachIndexed { index, receiptData -> + receiptAvatars[index].isVisible = true + avatarRenderer.render(receiptData.toMatrixItem(), receiptAvatars[index]) + } - if (readReceipts.size > MAX_RECEIPT_DISPLAYED) { - views.receiptMore.visibility = View.VISIBLE - views.receiptMore.text = context.getString( - R.string.x_plus, readReceipts.size - MAX_RECEIPT_DISPLAYED - ) - } else { - views.receiptMore.visibility = View.GONE - } - contentDescription = when (readReceipts.size) { - 1 -> - if (displayNames.size == 1) { - context.getString(R.string.one_user_read, displayNames[0]) - } else { - context.resources.getQuantityString(R.plurals.fallback_users_read, readReceipts.size) - } - 2 -> - if (displayNames.size == 2) { - context.getString(R.string.two_users_read, displayNames[0], displayNames[1]) - } else { - context.resources.getQuantityString(R.plurals.fallback_users_read, readReceipts.size) - } - 3 -> - if (displayNames.size == 3) { - context.getString(R.string.three_users_read, displayNames[0], displayNames[1], displayNames[2]) - } else { - context.resources.getQuantityString(R.plurals.fallback_users_read, readReceipts.size) - } - else -> - if (displayNames.size >= 2) { - val qty = readReceipts.size - 2 - context.resources.getQuantityString( - R.plurals.two_and_some_others_read, - qty, - displayNames[0], - displayNames[1], - qty - ) - } else { - context.resources.getQuantityString(R.plurals.fallback_users_read, readReceipts.size) - } - } + val displayNames = readReceipts + .mapNotNull { it.displayName } + .filter { it.isNotBlank() } + .take(MAX_RECEIPT_DISPLAYED) + + if (readReceipts.size > MAX_RECEIPT_DISPLAYED) { + views.receiptMore.visibility = View.VISIBLE + views.receiptMore.text = context.getString( + R.string.x_plus, readReceipts.size - MAX_RECEIPT_DISPLAYED + ) } else { - isVisible = false + views.receiptMore.visibility = View.GONE + } + contentDescription = when (readReceipts.size) { + 1 -> + if (displayNames.size == 1) { + context.getString(R.string.one_user_read, displayNames[0]) + } else { + context.resources.getQuantityString(R.plurals.fallback_users_read, readReceipts.size) + } + 2 -> + if (displayNames.size == 2) { + context.getString(R.string.two_users_read, displayNames[0], displayNames[1]) + } else { + context.resources.getQuantityString(R.plurals.fallback_users_read, readReceipts.size) + } + 3 -> + if (displayNames.size == 3) { + context.getString(R.string.three_users_read, displayNames[0], displayNames[1], displayNames[2]) + } else { + context.resources.getQuantityString(R.plurals.fallback_users_read, readReceipts.size) + } + else -> + if (displayNames.size >= 2) { + val qty = readReceipts.size - 2 + context.resources.getQuantityString( + R.plurals.two_and_some_others_read, + qty, + displayNames[0], + displayNames[1], + qty + ) + } else { + context.resources.getQuantityString(R.plurals.fallback_users_read, readReceipts.size) + } } } diff --git a/vector/src/main/res/layout/view_read_receipts.xml b/vector/src/main/res/layout/view_read_receipts.xml index 907f1ec0e3..dce46ec187 100644 --- a/vector/src/main/res/layout/view_read_receipts.xml +++ b/vector/src/main/res/layout/view_read_receipts.xml @@ -3,6 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:gravity="end" tools:parentTag="android.widget.LinearLayout"> - - - - @@ -52,9 +35,11 @@ android:id="@+id/receiptAvatar2" android:layout_width="@dimen/item_event_message_state_size" android:layout_height="@dimen/item_event_message_state_size" - android:layout_marginStart="2dp" + android:layout_marginEnd="-6dp" android:adjustViewBounds="true" + android:background="@drawable/pill_receipt" android:importantForAccessibility="no" + android:padding="1dp" android:scaleType="centerCrop" tools:src="@sample/user_round_avatars" /> @@ -62,9 +47,10 @@ android:id="@+id/receiptAvatar1" android:layout_width="@dimen/item_event_message_state_size" android:layout_height="@dimen/item_event_message_state_size" - android:layout_marginStart="2dp" android:adjustViewBounds="true" + android:background="@drawable/pill_receipt" android:importantForAccessibility="no" + android:padding="1dp" android:scaleType="centerCrop" tools:src="@sample/user_round_avatars" /> diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index d5bc322546..c16dd8b61a 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -1418,7 +1418,7 @@ collapse %1$s: %2$s - %d+ + +%d No valid Google Play Services APK found. Notifications may not work properly. From ed1179b15542eb339a2d7e176d5a7d9d7f62cb70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olive=CC=81r=20Falvai?= Date: Sat, 7 May 2022 20:44:58 +0200 Subject: [PATCH 2/3] Ignore lint warning about negative margin --- vector/src/main/res/layout/view_read_receipts.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vector/src/main/res/layout/view_read_receipts.xml b/vector/src/main/res/layout/view_read_receipts.xml index dce46ec187..0e8af014bd 100644 --- a/vector/src/main/res/layout/view_read_receipts.xml +++ b/vector/src/main/res/layout/view_read_receipts.xml @@ -29,6 +29,7 @@ android:importantForAccessibility="no" android:padding="1dp" android:scaleType="centerCrop" + tools:ignore="NegativeMargin" tools:src="@sample/user_round_avatars" /> Date: Tue, 31 May 2022 17:49:47 +0200 Subject: [PATCH 3/3] Add changelog entry --- changelog.d/5970.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5970.feature diff --git a/changelog.d/5970.feature b/changelog.d/5970.feature new file mode 100644 index 0000000000..b65decdd2d --- /dev/null +++ b/changelog.d/5970.feature @@ -0,0 +1 @@ +Make read receipt avatar list more compact