From 0e7596e0aa96beef2398c213f4e2df71d0d4eeac Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 29 Jan 2019 14:39:23 +0100 Subject: [PATCH] Room list : add basic notifications count on category item. Need to add business logic later. --- .../home/room/list/RoomCategoryItem.kt | 4 +++ .../home/room/list/RoomSummaryController.kt | 33 ++++++++++++------- app/src/main/res/layout/item_room.xml | 6 ++-- .../main/res/layout/item_room_category.xml | 23 +++++++++++-- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/list/RoomCategoryItem.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/list/RoomCategoryItem.kt index c5d3044d..7fcc0210 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/list/RoomCategoryItem.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/list/RoomCategoryItem.kt @@ -26,9 +26,12 @@ import im.vector.riotredesign.core.epoxy.KotlinModel data class RoomCategoryItem( val title: CharSequence, val isExpanded: Boolean, + val unreadCount: Int, + val showHighlighted: Boolean, val listener: (() -> Unit)? = null ) : KotlinModel(R.layout.item_room_category) { + private val unreadCounterBadgeView by bind(R.id.roomCategoryUnreadCounterBadgeView) private val titleView by bind(R.id.roomCategoryTitleView) private val rootView by bind(R.id.roomCategoryRootView) @@ -41,6 +44,7 @@ data class RoomCategoryItem( val expandedArrowDrawable = ContextCompat.getDrawable(rootView.context, expandedArrowDrawableRes)?.also { DrawableCompat.setTint(it, tintColor) } + unreadCounterBadgeView.render(unreadCount, showHighlighted) titleView.setCompoundDrawablesWithIntrinsicBounds(expandedArrowDrawable, null, null, null) titleView.text = title rootView.setOnClickListener { listener?.invoke() } diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/list/RoomSummaryController.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/list/RoomSummaryController.kt index 4a6c8a7b..931a0f6c 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/list/RoomSummaryController.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/list/RoomSummaryController.kt @@ -35,48 +35,57 @@ class RoomSummaryController(private val stringProvider: StringProvider override fun buildModels(viewState: RoomListViewState) { val roomSummaries = viewState.asyncRooms() - - buildRoomCategory(viewState, R.string.room_list_favourites, isFavoriteRoomsExpanded) { + val favourites = roomSummaries?.favourites ?: emptyList() + buildRoomCategory(viewState, favourites, R.string.room_list_favourites, isFavoriteRoomsExpanded) { isFavoriteRoomsExpanded = !isFavoriteRoomsExpanded } if (isFavoriteRoomsExpanded) { - buildRoomModels(roomSummaries?.favourites ?: emptyList(), viewState.selectedRoomId) + buildRoomModels(favourites, viewState.selectedRoomId) } - buildRoomCategory(viewState, R.string.room_list_direct, isDirectRoomsExpanded) { + val directRooms = roomSummaries?.directRooms ?: emptyList() + buildRoomCategory(viewState, directRooms, R.string.room_list_direct, isDirectRoomsExpanded) { isDirectRoomsExpanded = !isDirectRoomsExpanded } if (isDirectRoomsExpanded) { - buildRoomModels(roomSummaries?.directRooms ?: emptyList(), viewState.selectedRoomId) + buildRoomModels(directRooms, viewState.selectedRoomId) } - buildRoomCategory(viewState, R.string.room_list_group, isGroupRoomsExpanded) { + val groupRooms = roomSummaries?.groupRooms ?: emptyList() + buildRoomCategory(viewState, groupRooms, R.string.room_list_group, isGroupRoomsExpanded) { isGroupRoomsExpanded = !isGroupRoomsExpanded } if (isGroupRoomsExpanded) { - buildRoomModels(roomSummaries?.groupRooms ?: emptyList(), viewState.selectedRoomId) + buildRoomModels(groupRooms, viewState.selectedRoomId) } - buildRoomCategory(viewState, R.string.room_list_low_priority, isLowPriorityRoomsExpanded) { + val lowPriorities = roomSummaries?.lowPriorities ?: emptyList() + buildRoomCategory(viewState, lowPriorities, R.string.room_list_low_priority, isLowPriorityRoomsExpanded) { isLowPriorityRoomsExpanded = !isLowPriorityRoomsExpanded } if (isLowPriorityRoomsExpanded) { - buildRoomModels(roomSummaries?.lowPriorities ?: emptyList(), viewState.selectedRoomId) + buildRoomModels(lowPriorities, viewState.selectedRoomId) } - buildRoomCategory(viewState, R.string.room_list_system_alert, isServerNoticeRoomsExpanded) { + val serverNotices = roomSummaries?.serverNotices ?: emptyList() + buildRoomCategory(viewState, serverNotices, R.string.room_list_system_alert, isServerNoticeRoomsExpanded) { isServerNoticeRoomsExpanded = !isServerNoticeRoomsExpanded } if (isServerNoticeRoomsExpanded) { - buildRoomModels(roomSummaries?.serverNotices ?: emptyList(), viewState.selectedRoomId) + buildRoomModels(serverNotices, viewState.selectedRoomId) } } - private fun buildRoomCategory(viewState: RoomListViewState, @StringRes titleRes: Int, isExpanded: Boolean, mutateExpandedState: () -> Unit) { + private fun buildRoomCategory(viewState: RoomListViewState, summaries: List, @StringRes titleRes: Int, isExpanded: Boolean, mutateExpandedState: () -> Unit) { + //TODO should add some business logic later + val unreadCount = summaries.map { it.notificationCount }.reduce { acc, i -> acc + i } + val showHighlighted = summaries.any { it.highlightCount > 0 } RoomCategoryItem( title = stringProvider.getString(titleRes).toUpperCase(), isExpanded = isExpanded, + unreadCount = unreadCount, + showHighlighted = showHighlighted, listener = { mutateExpandedState() setData(viewState) diff --git a/app/src/main/res/layout/item_room.xml b/app/src/main/res/layout/item_room.xml index c0148ee7..c07164d1 100644 --- a/app/src/main/res/layout/item_room.xml +++ b/app/src/main/res/layout/item_room.xml @@ -47,10 +47,12 @@ + +