Group/Room list : show filtered room when a group is selected

This commit is contained in:
ganfra 2018-11-07 12:17:10 +01:00
parent 3028710122
commit cd25232572
12 changed files with 61 additions and 16 deletions

View File

@ -48,6 +48,8 @@ class HomeViewModel(initialState: HomeViewState, private val session: Session) :
withState { state -> withState { state ->
if (state.selectedGroup?.groupId != action.groupSummary.groupId) { if (state.selectedGroup?.groupId != action.groupSummary.groupId) {
setState { copy(selectedGroup = action.groupSummary) } setState { copy(selectedGroup = action.groupSummary) }
} else {
setState { copy(selectedGroup = null) }
} }
} }
} }
@ -56,6 +58,7 @@ class HomeViewModel(initialState: HomeViewState, private val session: Session) :
session session
.rx().liveRoomSummaries() .rx().liveRoomSummaries()
.execute { async -> .execute { async ->

val summaries = async() val summaries = async()
val directRooms = summaries?.filter { it.isDirect } ?: emptyList() val directRooms = summaries?.filter { it.isDirect } ?: emptyList()
val groupRooms = summaries?.filter { !it.isDirect } ?: emptyList() val groupRooms = summaries?.filter { !it.isDirect } ?: emptyList()

View File

@ -3,6 +3,7 @@ package im.vector.riotredesign.features.home.group
import android.widget.ImageView import android.widget.ImageView
import im.vector.riotredesign.R import im.vector.riotredesign.R
import im.vector.riotredesign.core.epoxy.KotlinModel import im.vector.riotredesign.core.epoxy.KotlinModel
import im.vector.riotredesign.core.platform.CheckableFrameLayout
import im.vector.riotredesign.features.home.AvatarRenderer import im.vector.riotredesign.features.home.AvatarRenderer




@ -14,9 +15,11 @@ data class GroupSummaryItem(
) : KotlinModel(R.layout.item_group) { ) : KotlinModel(R.layout.item_group) {


private val avatarImageView by bind<ImageView>(R.id.groupAvatarImageView) private val avatarImageView by bind<ImageView>(R.id.groupAvatarImageView)
private val rootView by bind<CheckableFrameLayout>(R.id.itemGroupLayout)


override fun bind() { override fun bind() {
avatarImageView.setOnClickListener { listener?.invoke() } rootView.isSelected = isSelected
rootView.setOnClickListener { listener?.invoke() }
AvatarRenderer.render(avatarUrl, groupName.toString(), avatarImageView) AvatarRenderer.render(avatarUrl, groupName.toString(), avatarImageView)
} }
} }

View File

@ -25,7 +25,16 @@ class RoomSummaryController(private val callback: Callback? = null
.addTo(this) .addTo(this)


if (isDirectRoomsExpanded) { if (isDirectRoomsExpanded) {
buildRoomModels(viewState.directRooms, viewState.selectedRoom) val filteredDirectRooms = viewState.directRooms.filter {
if (viewState.selectedGroup == null) {
true
} else {
it.otherMemberIds
.intersect(viewState.selectedGroup.userIds)
.isNotEmpty()
}
}
buildRoomModels(filteredDirectRooms, viewState.selectedRoom)
} }


RoomCategoryItem( RoomCategoryItem(
@ -40,7 +49,10 @@ class RoomSummaryController(private val callback: Callback? = null
.addTo(this) .addTo(this)


if (isGroupRoomsExpanded) { if (isGroupRoomsExpanded) {
buildRoomModels(viewState.groupRooms, viewState.selectedRoom) val filteredGroupRooms = viewState.groupRooms.filter {
viewState.selectedGroup?.roomIds?.contains(it.roomId) ?: true
}
buildRoomModels(filteredGroupRooms, viewState.selectedRoom)
} }


} }

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_selected="true">
<shape android:shape="oval">
<solid android:color="@android:color/transparent" />
<stroke android:width="2dp" android:color="@color/pale_teal" />
</shape>

</item>
<item android:drawable="@android:color/transparent" />

</selector>

View File

@ -7,7 +7,7 @@


<FrameLayout <FrameLayout
android:id="@+id/groupListFragmentContainer" android:id="@+id/groupListFragmentContainer"
android:layout_width="56dp" android:layout_width="64dp"
android:layout_height="match_parent" /> android:layout_height="match_parent" />


<FrameLayout <FrameLayout

View File

@ -12,9 +12,11 @@


<ImageView <ImageView
android:id="@+id/groupAvatarImageView" android:id="@+id/groupAvatarImageView"
android:layout_width="40dp" android:layout_width="48dp"
android:layout_height="40dp" android:layout_height="48dp"
android:layout_gravity="center" android:layout_gravity="center"
android:duplicateParentState="true"
android:foreground="@drawable/fg_group_item"
tools:src="@tools:sample/avatars" /> tools:src="@tools:sample/avatars" />


</im.vector.riotredesign.core.platform.CheckableFrameLayout> </im.vector.riotredesign.core.platform.CheckableFrameLayout>

View File

@ -2,15 +2,17 @@
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/roomCategoryRootView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:id="@+id/roomCategoryRootView"
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="24dp" android:paddingLeft="16dp"
android:padding="16dp" android:paddingTop="8dp"
android:background="?attr/selectableItemBackground" android:paddingRight="16dp"
android:paddingBottom="8dp"
tools:background="@color/pale_grey"> tools:background="@color/pale_grey">


<TextView <TextView

View File

@ -5,5 +5,6 @@ data class RoomSummary(
val displayName: String = "", val displayName: String = "",
val topic: String = "", val topic: String = "",
val avatarUrl: String = "", val avatarUrl: String = "",
val isDirect: Boolean val isDirect: Boolean,
val otherMemberIds: List<String> = emptyList()
) )

View File

@ -12,7 +12,8 @@ object RoomSummaryMapper {
roomSummaryEntity.displayName ?: "", roomSummaryEntity.displayName ?: "",
roomSummaryEntity.topic ?: "", roomSummaryEntity.topic ?: "",
roomSummaryEntity.avatarUrl ?: "", roomSummaryEntity.avatarUrl ?: "",
roomSummaryEntity.isDirect roomSummaryEntity.isDirect,
roomSummaryEntity.otherMemberIds.toList()
) )
} }
} }

View File

@ -13,7 +13,8 @@ open class RoomSummaryEntity(@PrimaryKey var roomId: String = "",
var joinedMembersCount: Int? = 0, var joinedMembersCount: Int? = 0,
var invitedMembersCount: Int? = 0, var invitedMembersCount: Int? = 0,
var isDirect: Boolean = false, var isDirect: Boolean = false,
var isLatestSelected: Boolean = false var isLatestSelected: Boolean = false,
var otherMemberIds: RealmList<String> = RealmList()
) : RealmObject() { ) : RealmObject() {


companion object companion object

View File

@ -54,7 +54,7 @@ class SessionModule(private val sessionParams: SessionParams) : Module {
} }


scope(DefaultSession.SCOPE) { scope(DefaultSession.SCOPE) {
RoomSummaryUpdater(get(), get(), get(), get()) RoomSummaryUpdater(get(), get(), get(), get(), sessionParams.credentials)
} }


scope(DefaultSession.SCOPE) { scope(DefaultSession.SCOPE) {

View File

@ -6,6 +6,7 @@ import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.room.Room import im.vector.matrix.android.api.session.room.Room
import im.vector.matrix.android.api.session.room.model.RoomTopicContent import im.vector.matrix.android.api.session.room.model.RoomTopicContent
import im.vector.matrix.android.internal.auth.data.Credentials
import im.vector.matrix.android.internal.database.mapper.asDomain import im.vector.matrix.android.internal.database.mapper.asDomain
import im.vector.matrix.android.internal.database.model.EventEntity import im.vector.matrix.android.internal.database.model.EventEntity
import im.vector.matrix.android.internal.database.model.RoomEntity import im.vector.matrix.android.internal.database.model.RoomEntity
@ -13,6 +14,7 @@ import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
import im.vector.matrix.android.internal.database.query.last import im.vector.matrix.android.internal.database.query.last
import im.vector.matrix.android.internal.database.query.where import im.vector.matrix.android.internal.database.query.where
import im.vector.matrix.android.internal.session.room.members.RoomDisplayNameResolver import im.vector.matrix.android.internal.session.room.members.RoomDisplayNameResolver
import im.vector.matrix.android.internal.session.room.members.RoomMembers
import io.realm.Realm import io.realm.Realm
import io.realm.kotlin.createObject import io.realm.kotlin.createObject
import timber.log.Timber import timber.log.Timber
@ -21,7 +23,8 @@ import java.util.concurrent.atomic.AtomicBoolean
internal class RoomSummaryUpdater(private val monarchy: Monarchy, internal class RoomSummaryUpdater(private val monarchy: Monarchy,
private val roomDisplayNameResolver: RoomDisplayNameResolver, private val roomDisplayNameResolver: RoomDisplayNameResolver,
private val roomAvatarResolver: RoomAvatarResolver, private val roomAvatarResolver: RoomAvatarResolver,
private val context: Context private val context: Context,
private val credentials: Credentials
) : Observer<Monarchy.ManagedChangeSet<RoomEntity>> { ) : Observer<Monarchy.ManagedChangeSet<RoomEntity>> {


private var isStarted = AtomicBoolean(false) private var isStarted = AtomicBoolean(false)
@ -69,15 +72,19 @@ internal class RoomSummaryUpdater(private val monarchy: Monarchy,
return return
} }
val roomSummary = RoomSummaryEntity.where(realm, room.roomId).findFirst() val roomSummary = RoomSummaryEntity.where(realm, room.roomId).findFirst()
?: realm.createObject(room.roomId) ?: realm.createObject(room.roomId)


val lastMessageEvent = EventEntity.where(realm, room.roomId, EventType.MESSAGE).last() val lastMessageEvent = EventEntity.where(realm, room.roomId, EventType.MESSAGE).last()
val lastTopicEvent = EventEntity.where(realm, room.roomId, EventType.STATE_ROOM_TOPIC).last()?.asDomain() val lastTopicEvent = EventEntity.where(realm, room.roomId, EventType.STATE_ROOM_TOPIC).last()?.asDomain()


val otherRoomMembers = RoomMembers(realm, room.roomId).getLoaded().filterKeys { it != credentials.userId }

roomSummary.displayName = roomDisplayNameResolver.resolve(context, room).toString() roomSummary.displayName = roomDisplayNameResolver.resolve(context, room).toString()
roomSummary.avatarUrl = roomAvatarResolver.resolve(room) roomSummary.avatarUrl = roomAvatarResolver.resolve(room)
roomSummary.topic = lastTopicEvent?.content<RoomTopicContent>()?.topic roomSummary.topic = lastTopicEvent?.content<RoomTopicContent>()?.topic
roomSummary.lastMessage = lastMessageEvent roomSummary.lastMessage = lastMessageEvent
roomSummary.otherMemberIds.clear()
roomSummary.otherMemberIds.addAll(otherRoomMembers.keys)
} }


} }