forked from GitHub-Mirror/riotX-android
Room list : add basic notifications count on category item. Need to add business logic later.
This commit is contained in:
parent
d3d536f4f0
commit
0e7596e0aa
@ -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<UnreadCounterBadgeView>(R.id.roomCategoryUnreadCounterBadgeView)
|
||||
private val titleView by bind<TextView>(R.id.roomCategoryTitleView)
|
||||
private val rootView by bind<ViewGroup>(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() }
|
||||
|
@ -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<RoomSummary>, @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)
|
||||
|
@ -47,10 +47,12 @@
|
||||
<im.vector.riotredesign.features.home.room.list.UnreadCounterBadgeView
|
||||
android:id="@+id/roomUnreadCounterBadgeView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:padding="4dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:minWidth="24dp"
|
||||
android:minHeight="24dp"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingRight="4dp"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="12sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
@ -26,15 +26,32 @@
|
||||
android:text="DIRECT MESSAGES"
|
||||
android:textColor="@color/bluey_grey_two"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/roomCategoryAddButton"
|
||||
app:layout_constraintEnd_toStartOf="@+id/roomCategoryUnreadCounterBadgeView"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<im.vector.riotredesign.features.home.room.list.UnreadCounterBadgeView
|
||||
android:id="@+id/roomCategoryUnreadCounterBadgeView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:minWidth="24dp"
|
||||
android:minHeight="24dp"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingRight="4dp"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="12sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/roomCategoryAddButton"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:background="@drawable/bg_unread_highlight"
|
||||
tools:text="4" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/roomCategoryAddButton"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/ic_add_circle_white"
|
||||
android:tint="@color/bluey_grey_two"
|
||||
|
Loading…
Reference in New Issue
Block a user