Adding number of items (UI part)

This commit is contained in:
Maxime Naturel 2022-02-03 16:47:17 +01:00
parent 70481e3ba3
commit b1d1090d1d
2 changed files with 27 additions and 17 deletions

View File

@ -18,14 +18,10 @@ package im.vector.app.features.home.room.list
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.recyclerview.widget.RecyclerView
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.onClick
import im.vector.app.databinding.ItemRoomCategoryBinding
import im.vector.app.features.themes.ThemeUtils
class SectionHeaderAdapter constructor(
private val onClickAction: ClickListener
@ -33,6 +29,7 @@ class SectionHeaderAdapter constructor(
data class RoomsSectionData(
val name: String,
val itemCount: Int = 0,
val isExpanded: Boolean = true,
val notificationCount: Int = 0,
val isHighlighted: Boolean = false,
@ -79,14 +76,17 @@ class SectionHeaderAdapter constructor(
}
fun bind(roomsSectionData: RoomsSectionData) {
binding.roomCategoryTitleView.text = roomsSectionData.name
val tintColor = ThemeUtils.getColor(binding.root.context, R.attr.vctr_content_secondary)
val expandedArrowDrawableRes = if (roomsSectionData.isExpanded) R.drawable.ic_expand_more else R.drawable.ic_expand_less
val expandedArrowDrawable = ContextCompat.getDrawable(binding.root.context, expandedArrowDrawableRes)?.also {
DrawableCompat.setTint(it, tintColor)
with(binding) {
roomCategoryTitleView.text = roomsSectionData.name
val tintColor = ThemeUtils.getColor(root.context, R.attr.vctr_content_secondary)
val expandedArrowDrawableRes = if (roomsSectionData.isExpanded) R.drawable.ic_expand_more else R.drawable.ic_expand_less
val expandedArrowDrawable = ContextCompat.getDrawable(root.context, expandedArrowDrawableRes)?.also {
DrawableCompat.setTint(it, tintColor)
}
roomCategoryCounterView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null)
roomCategoryCounterView.text = roomsSectionData.itemCount.toString()
roomCategoryUnreadCounterBadgeView.render(UnreadCounterBadgeView.State(roomsSectionData.notificationCount, roomsSectionData.isHighlighted))
}
binding.roomCategoryUnreadCounterBadgeView.render(UnreadCounterBadgeView.State(roomsSectionData.notificationCount, roomsSectionData.isHighlighted))
binding.roomCategoryTitleView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null)
}
companion object {

View File

@ -11,8 +11,8 @@
android:foreground="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingVertical="8dp"
android:paddingStart="16dp"
android:paddingEnd="@dimen/layout_horizontal_margin">
<TextView
@ -24,15 +24,25 @@
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:textColor="?vctr_content_primary"
android:textAllCaps="true"
android:textColor="?vctr_content_primary"
android:textStyle="normal"
app:drawableTint="?vctr_content_secondary"
android:drawablePadding="8dp"
tools:drawableEnd="@drawable/ic_expand_more"
tools:text="@string/room_participants_header_direct_chats" />
<!-- TODO add item counter text with the expand drawable + bind data into viewState and adapter -->
<TextView
android:id="@+id/roomCategoryCounterView"
style="@style/Widget.Vector.TextView.Subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:drawablePadding="2dp"
android:gravity="center_vertical"
android:maxLines="1"
android:textColor="?vctr_content_secondary"
android:textStyle="normal"
app:drawableTint="?vctr_content_secondary"
tools:drawableEnd="@drawable/ic_expand_more"
tools:text="14" />
<im.vector.app.features.home.room.list.UnreadCounterBadgeView
android:id="@+id/roomCategoryUnreadCounterBadgeView"