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

val summaries = async()
val directRooms = 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 im.vector.riotredesign.R
import im.vector.riotredesign.core.epoxy.KotlinModel
import im.vector.riotredesign.core.platform.CheckableFrameLayout
import im.vector.riotredesign.features.home.AvatarRenderer


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

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

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

View File

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

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(
@ -40,7 +49,10 @@ class RoomSummaryController(private val callback: Callback? = null
.addTo(this)

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
android:id="@+id/groupListFragmentContainer"
android:layout_width="56dp"
android:layout_width="64dp"
android:layout_height="match_parent" />

<FrameLayout

View File

@ -12,9 +12,11 @@

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

</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"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/roomCategoryRootView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:id="@+id/roomCategoryRootView"
android:gravity="center_vertical"
android:minHeight="24dp"
android:padding="16dp"
android:background="?attr/selectableItemBackground"
android:paddingLeft="16dp"
android:paddingTop="8dp"
android:paddingRight="16dp"
android:paddingBottom="8dp"
tools:background="@color/pale_grey">

<TextView

View File

@ -5,5 +5,6 @@ data class RoomSummary(
val displayName: String = "",
val topic: 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.topic ?: "",
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 invitedMembersCount: Int? = 0,
var isDirect: Boolean = false,
var isLatestSelected: Boolean = false
var isLatestSelected: Boolean = false,
var otherMemberIds: RealmList<String> = RealmList()
) : RealmObject() {

companion object

View File

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

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

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.room.Room
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.model.EventEntity
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.where
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.kotlin.createObject
import timber.log.Timber
@ -21,7 +23,8 @@ import java.util.concurrent.atomic.AtomicBoolean
internal class RoomSummaryUpdater(private val monarchy: Monarchy,
private val roomDisplayNameResolver: RoomDisplayNameResolver,
private val roomAvatarResolver: RoomAvatarResolver,
private val context: Context
private val context: Context,
private val credentials: Credentials
) : Observer<Monarchy.ManagedChangeSet<RoomEntity>> {

private var isStarted = AtomicBoolean(false)
@ -74,10 +77,14 @@ internal class RoomSummaryUpdater(private val monarchy: Monarchy,
val lastMessageEvent = EventEntity.where(realm, room.roomId, EventType.MESSAGE).last()
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.avatarUrl = roomAvatarResolver.resolve(room)
roomSummary.topic = lastTopicEvent?.content<RoomTopicContent>()?.topic
roomSummary.lastMessage = lastMessageEvent
roomSummary.otherMemberIds.clear()
roomSummary.otherMemberIds.addAll(otherRoomMembers.keys)
}

}