Removing some with() code pattern

This commit is contained in:
Maxime Naturel 2022-02-17 17:22:18 +01:00
parent a826a50c10
commit 0942c6d648
2 changed files with 10 additions and 14 deletions

View file

@ -48,10 +48,8 @@ abstract class RoomCategoryItem : VectorEpoxyModel<RoomCategoryItem.Holder>() {
}
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted))
holder.titleView.text = title
with(holder.counterView) {
text = itemCount.takeIf { it > 0 }?.toString().orEmpty()
setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null)
}
holder.counterView.text = itemCount.takeIf { it > 0 }?.toString().orEmpty()
holder.counterView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null)
holder.rootView.onClick(listener)
}

View file

@ -80,17 +80,15 @@ class SectionHeaderAdapter constructor(
}
fun bind(roomsSectionData: RoomsSectionData) {
with(binding) {
roomCategoryTitleView.text = roomsSectionData.name
val tintColor = ThemeUtils.getColor(root.context, R.attr.vctr_content_secondary)
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(root.context, expandedArrowDrawableRes)?.also {
val expandedArrowDrawable = ContextCompat.getDrawable(binding.root.context, expandedArrowDrawableRes)?.also {
DrawableCompat.setTint(it, tintColor)
}
roomCategoryCounterView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null)
roomCategoryCounterView.text = roomsSectionData.itemCount.takeIf { it > 0 }?.toString().orEmpty()
roomCategoryUnreadCounterBadgeView.render(UnreadCounterBadgeView.State(roomsSectionData.notificationCount, roomsSectionData.isHighlighted))
}
binding.roomCategoryCounterView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null)
binding.roomCategoryCounterView.text = roomsSectionData.itemCount.takeIf { it > 0 }?.toString().orEmpty()
binding.roomCategoryUnreadCounterBadgeView.render(UnreadCounterBadgeView.State(roomsSectionData.notificationCount, roomsSectionData.isHighlighted))
}
companion object {