From 7cc79fef0faa72b764efdfedc97957e312f2a522 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Fri, 29 Apr 2022 12:37:19 +0200 Subject: [PATCH] Refactors RoomSummaryItem --- .../home/room/list/RoomSummaryItem.kt | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 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 aa459afd3b..4cea812775 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 @@ -105,14 +105,14 @@ abstract class RoomSummaryItem : VectorEpoxyModel() { 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,22 +122,24 @@ abstract class RoomSummaryItem : VectorEpoxyModel() { holder.roomAvatarFailSendingImageView.isVisible = hasFailedSending renderSelection(holder, showSelected) holder.roomAvatarPresenceImageView.render(showPresence, userPresence) - showTypingViewIfNecessary(holder) } - private fun showTypingViewIfNecessary(holder: Holder) { - if (displayMode != RoomListDisplayMode.FILTERED) { - holder.typingView.setTextOrHide(typingMessage) - holder.subtitleView.isInvisible = holder.typingView.isVisible - } + private fun renderDisplayMode(holder: Holder) = when (displayMode) { + RoomListDisplayMode.ROOMS, + RoomListDisplayMode.PEOPLE, + RoomListDisplayMode.NOTIFICATIONS -> renderForDefaultDisplayMode(holder) + RoomListDisplayMode.FILTERED -> renderForFilteredDisplayMode(holder) } - private fun getTextForLastEventView(): CharSequence { - return if (displayMode == RoomListDisplayMode.FILTERED) { - subtitle - } else { - lastFormattedEvent.charSequence - } + 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 } override fun unbind(holder: Holder) {