From 7c1d1c34647e6a860b68adc7913a63a8574159a4 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 16 May 2022 10:26:28 +0200 Subject: [PATCH] Adds centering of items with no subtitles --- .../home/room/list/RoomSummaryItem.kt | 25 ++++--------------- vector/src/main/res/layout/item_room.xml | 18 +++++++++++-- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItem.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItem.kt index 0a97518cf1..abcfe0d5d8 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItem.kt @@ -19,9 +19,9 @@ package im.vector.app.features.home.room.list import android.view.HapticFeedbackConstants import android.view.View import android.widget.ImageView +import android.widget.Space import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout -import androidx.constraintlayout.widget.ConstraintSet import androidx.core.view.isInvisible import androidx.core.view.isVisible import com.airbnb.epoxy.EpoxyAttribute @@ -141,27 +141,11 @@ abstract class RoomSummaryItem : VectorEpoxyModel() { private fun renderForFilteredDisplayMode(holder: Holder) { holder.subtitleView.text = subtitle - if (subtitle.isEmpty()) { - holder.centerTitleVertically() - } + holder.centerTitle(shouldCenter = subtitle.isEmpty()) } - private fun Holder.centerTitleVertically() { - removeTitleTopMargin() - constrainTitleToParentBottom() - } - - private fun Holder.removeTitleTopMargin() { - val layoutParams = titleView.layoutParams as ConstraintLayout.LayoutParams - layoutParams.topMargin = 0 - titleView.layoutParams = layoutParams - } - - private fun Holder.constrainTitleToParentBottom() { - val constraintSet = ConstraintSet() - constraintSet.clone(rootView) - constraintSet.connect(titleView.id, ConstraintSet.BOTTOM, rootView.id, ConstraintSet.BOTTOM) - constraintSet.applyTo(rootView) + private fun Holder.centerTitle(shouldCenter: Boolean) { + centerTitleSpace.isVisible = shouldCenter } override fun unbind(holder: Holder) { @@ -198,5 +182,6 @@ abstract class RoomSummaryItem : VectorEpoxyModel() { val roomAvatarFailSendingImageView by bind(R.id.roomAvatarFailSendingImageView) val roomAvatarPresenceImageView by bind(R.id.roomAvatarPresenceImageView) val rootView by bind(R.id.itemRoomLayout) + val centerTitleSpace by bind(R.id.centerTitleSpace) } } diff --git a/vector/src/main/res/layout/item_room.xml b/vector/src/main/res/layout/item_room.xml index ab0af18acb..ac028ccb08 100644 --- a/vector/src/main/res/layout/item_room.xml +++ b/vector/src/main/res/layout/item_room.xml @@ -112,13 +112,27 @@ app:layout_constraintTop_toBottomOf="@id/roomAvatarContainer" tools:layout_marginStart="20dp" /> + + + +