Refactors RoomSummaryItem

This commit is contained in:
ericdecanini 2022-04-29 12:37:19 +02:00
parent 7e415e82b0
commit 7cc79fef0f
1 changed files with 16 additions and 14 deletions

View File

@ -105,14 +105,14 @@ abstract class RoomSummaryItem : VectorEpoxyModel<RoomSummaryItem.Holder>() {
override fun bind(holder: Holder) {
super.bind(holder)
renderDisplayMode(holder)
holder.rootView.onClick(itemClickListener)
holder.rootView.setOnLongClickListener {
it.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
itemLongClickListener?.onLongClick(it) ?: false
}
holder.titleView.text = matrixItem.getBestName()
holder.lastEventTimeView.text = lastEventTime
holder.subtitleView.text = getTextForLastEventView()
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted))
holder.unreadIndentIndicator.isVisible = hasUnreadMessage
holder.draftView.isVisible = hasDraft
@ -122,23 +122,25 @@ abstract class RoomSummaryItem : VectorEpoxyModel<RoomSummaryItem.Holder>() {
holder.roomAvatarFailSendingImageView.isVisible = hasFailedSending
renderSelection(holder, showSelected)
holder.roomAvatarPresenceImageView.render(showPresence, userPresence)
showTypingViewIfNecessary(holder)
}
private fun showTypingViewIfNecessary(holder: Holder) {
if (displayMode != RoomListDisplayMode.FILTERED) {
private fun renderDisplayMode(holder: Holder) = when (displayMode) {
RoomListDisplayMode.ROOMS,
RoomListDisplayMode.PEOPLE,
RoomListDisplayMode.NOTIFICATIONS -> renderForDefaultDisplayMode(holder)
RoomListDisplayMode.FILTERED -> renderForFilteredDisplayMode(holder)
}
private fun renderForDefaultDisplayMode(holder: Holder) {
holder.subtitleView.text = lastFormattedEvent.charSequence
holder.lastEventTimeView.text = lastEventTime
}
private fun renderForFilteredDisplayMode(holder: Holder) {
holder.subtitleView.text = subtitle
holder.typingView.setTextOrHide(typingMessage)
holder.subtitleView.isInvisible = holder.typingView.isVisible
}
}
private fun getTextForLastEventView(): CharSequence {
return if (displayMode == RoomListDisplayMode.FILTERED) {
subtitle
} else {
lastFormattedEvent.charSequence
}
}
override fun unbind(holder: Holder) {
holder.rootView.setOnClickListener(null)