Adds centering of items with no subtitles

This commit is contained in:
ericdecanini 2022-05-16 10:26:28 +02:00
parent 50839c206b
commit 7c1d1c3464
2 changed files with 21 additions and 22 deletions

View File

@ -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<RoomSummaryItem.Holder>() {
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<RoomSummaryItem.Holder>() {
val roomAvatarFailSendingImageView by bind<ImageView>(R.id.roomAvatarFailSendingImageView)
val roomAvatarPresenceImageView by bind<PresenceStateImageView>(R.id.roomAvatarPresenceImageView)
val rootView by bind<ConstraintLayout>(R.id.itemRoomLayout)
val centerTitleSpace by bind<Space>(R.id.centerTitleSpace)
}
}

View File

@ -112,13 +112,27 @@
app:layout_constraintTop_toBottomOf="@id/roomAvatarContainer"
tools:layout_marginStart="20dp" />
<Space
android:id="@+id/topMarginSpace"
android:layout_width="0dp"
android:layout_height="12dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Space
android:id="@+id/centerTitleSpace"
android:layout_width="match_parent"
android:layout_height="15dp"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/topMarginSpace" />
<TextView
android:id="@+id/roomNameView"
style="@style/Widget.Vector.TextView.Subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/layout_horizontal_margin"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:duplicateParentState="true"
android:ellipsize="end"
@ -130,7 +144,7 @@
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="@id/roomAvatarContainer"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/centerTitleSpace"
tools:text="@sample/users.json/data/displayName" />
<ImageView