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(
|
data class RoomCategoryItem(
|
||||||
val title: CharSequence,
|
val title: CharSequence,
|
||||||
val isExpanded: Boolean,
|
val isExpanded: Boolean,
|
||||||
|
val unreadCount: Int,
|
||||||
|
val showHighlighted: Boolean,
|
||||||
val listener: (() -> Unit)? = null
|
val listener: (() -> Unit)? = null
|
||||||
) : KotlinModel(R.layout.item_room_category) {
|
) : 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 titleView by bind<TextView>(R.id.roomCategoryTitleView)
|
||||||
private val rootView by bind<ViewGroup>(R.id.roomCategoryRootView)
|
private val rootView by bind<ViewGroup>(R.id.roomCategoryRootView)
|
||||||
|
|
||||||
@ -41,6 +44,7 @@ data class RoomCategoryItem(
|
|||||||
val expandedArrowDrawable = ContextCompat.getDrawable(rootView.context, expandedArrowDrawableRes)?.also {
|
val expandedArrowDrawable = ContextCompat.getDrawable(rootView.context, expandedArrowDrawableRes)?.also {
|
||||||
DrawableCompat.setTint(it, tintColor)
|
DrawableCompat.setTint(it, tintColor)
|
||||||
}
|
}
|
||||||
|
unreadCounterBadgeView.render(unreadCount, showHighlighted)
|
||||||
titleView.setCompoundDrawablesWithIntrinsicBounds(expandedArrowDrawable, null, null, null)
|
titleView.setCompoundDrawablesWithIntrinsicBounds(expandedArrowDrawable, null, null, null)
|
||||||
titleView.text = title
|
titleView.text = title
|
||||||
rootView.setOnClickListener { listener?.invoke() }
|
rootView.setOnClickListener { listener?.invoke() }
|
||||||
|
@ -35,48 +35,57 @@ class RoomSummaryController(private val stringProvider: StringProvider
|
|||||||
|
|
||||||
override fun buildModels(viewState: RoomListViewState) {
|
override fun buildModels(viewState: RoomListViewState) {
|
||||||
val roomSummaries = viewState.asyncRooms()
|
val roomSummaries = viewState.asyncRooms()
|
||||||
|
val favourites = roomSummaries?.favourites ?: emptyList()
|
||||||
buildRoomCategory(viewState, R.string.room_list_favourites, isFavoriteRoomsExpanded) {
|
buildRoomCategory(viewState, favourites, R.string.room_list_favourites, isFavoriteRoomsExpanded) {
|
||||||
isFavoriteRoomsExpanded = !isFavoriteRoomsExpanded
|
isFavoriteRoomsExpanded = !isFavoriteRoomsExpanded
|
||||||
}
|
}
|
||||||
if (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
|
isDirectRoomsExpanded = !isDirectRoomsExpanded
|
||||||
}
|
}
|
||||||
if (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
|
isGroupRoomsExpanded = !isGroupRoomsExpanded
|
||||||
}
|
}
|
||||||
if (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
|
isLowPriorityRoomsExpanded = !isLowPriorityRoomsExpanded
|
||||||
}
|
}
|
||||||
if (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
|
isServerNoticeRoomsExpanded = !isServerNoticeRoomsExpanded
|
||||||
}
|
}
|
||||||
if (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(
|
RoomCategoryItem(
|
||||||
title = stringProvider.getString(titleRes).toUpperCase(),
|
title = stringProvider.getString(titleRes).toUpperCase(),
|
||||||
isExpanded = isExpanded,
|
isExpanded = isExpanded,
|
||||||
|
unreadCount = unreadCount,
|
||||||
|
showHighlighted = showHighlighted,
|
||||||
listener = {
|
listener = {
|
||||||
mutateExpandedState()
|
mutateExpandedState()
|
||||||
setData(viewState)
|
setData(viewState)
|
||||||
|
@ -47,10 +47,12 @@
|
|||||||
<im.vector.riotredesign.features.home.room.list.UnreadCounterBadgeView
|
<im.vector.riotredesign.features.home.room.list.UnreadCounterBadgeView
|
||||||
android:id="@+id/roomUnreadCounterBadgeView"
|
android:id="@+id/roomUnreadCounterBadgeView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="0dp"
|
android:layout_height="wrap_content"
|
||||||
android:padding="4dp"
|
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:minWidth="24dp"
|
android:minWidth="24dp"
|
||||||
|
android:minHeight="24dp"
|
||||||
|
android:paddingLeft="4dp"
|
||||||
|
android:paddingRight="4dp"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
@ -26,15 +26,32 @@
|
|||||||
android:text="DIRECT MESSAGES"
|
android:text="DIRECT MESSAGES"
|
||||||
android:textColor="@color/bluey_grey_two"
|
android:textColor="@color/bluey_grey_two"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
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_constraintHorizontal_bias="0.0"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="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
|
<ImageView
|
||||||
android:id="@+id/roomCategoryAddButton"
|
android:id="@+id/roomCategoryAddButton"
|
||||||
android:layout_width="32dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="32dp"
|
android:layout_height="40dp"
|
||||||
android:scaleType="centerInside"
|
android:scaleType="centerInside"
|
||||||
android:src="@drawable/ic_add_circle_white"
|
android:src="@drawable/ic_add_circle_white"
|
||||||
android:tint="@color/bluey_grey_two"
|
android:tint="@color/bluey_grey_two"
|
||||||
|
Loading…
Reference in New Issue
Block a user