Room list : handle direct rooms

This commit is contained in:
ganfra
2018-10-30 18:22:29 +01:00
parent ec27951850
commit bc8055c3cd
20 changed files with 351 additions and 43 deletions

View File

@ -1,16 +1,30 @@
package im.vector.riotredesign.features.home.room.list
import android.support.annotation.DrawableRes
import android.support.v4.content.ContextCompat
import android.view.ViewGroup
import android.widget.TextView
import im.vector.riotredesign.R
import im.vector.riotredesign.core.epoxy.KotlinModel
data class RoomCategoryItem(
val title: CharSequence,
@DrawableRes val expandDrawable: Int,
val isExpanded: Boolean,
val listener: (() -> Unit)? = null
) : KotlinModel(R.layout.item_room_category) {
override fun bind() {
private val titleView by bind<TextView>(R.id.roomCategoryTitleView)
private val rootView by bind<ViewGroup>(R.id.roomCategoryRootView)
private val tintColor by lazy {
ContextCompat.getColor(rootView.context, R.color.bluey_grey_two)
}
override fun bind() {
val expandedArrowDrawableRes = if (isExpanded) R.drawable.ic_expand_more_white else R.drawable.ic_expand_less_white
val expandedArrowDrawable = ContextCompat.getDrawable(rootView.context, expandedArrowDrawableRes)
expandedArrowDrawable?.setTint(tintColor)
titleView.setCompoundDrawablesWithIntrinsicBounds(expandedArrowDrawable, null, null, null)
titleView.text = title
rootView.setOnClickListener { listener?.invoke() }
}
}

View File

@ -10,15 +10,49 @@ class RoomSummaryController(private val context: Context,
private val callback: Callback? = null
) : Typed2EpoxyController<List<RoomSummary>, RoomSummary>() {
private var directRoomsExpanded = true
private var groupRoomsExpanded = true
override fun buildModels(summaries: List<RoomSummary>?, selected: RoomSummary?) {
val directRooms = summaries?.filter { it.isDirect } ?: emptyList()
val groupRooms = summaries?.filter { !it.isDirect } ?: emptyList()
RoomCategoryItem(
title = "DIRECT MESSAGES",
expandDrawable = R.drawable.ic_expand_more_white
isExpanded = directRoomsExpanded,
listener = {
directRoomsExpanded = !directRoomsExpanded
setData(summaries, selected)
}
)
.id("direct_messages")
.addTo(this)
summaries?.forEach {
if (directRoomsExpanded) {
buildRoomModels(directRooms, selected)
}
RoomCategoryItem(
title = "GROUPS",
isExpanded = groupRoomsExpanded,
listener = {
groupRoomsExpanded = !groupRoomsExpanded
setData(summaries, selected)
}
)
.id("group_messages")
.addTo(this)
if (groupRoomsExpanded) {
buildRoomModels(groupRooms, selected)
}
}
private fun buildRoomModels(summaries: List<RoomSummary>, selected: RoomSummary?) {
summaries.forEach {
val roomSummaryViewHelper = RoomSummaryViewHelper(it)
RoomSummaryItem(
title = it.displayName,

View File

@ -6,6 +6,7 @@
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:id="@+id/roomCategoryRootView"
android:gravity="center_vertical"
android:minHeight="24dp"
android:padding="16dp"