forked from GitHub-Mirror/riotX-android
Group: should refresh when user data come. [WIP]
This commit is contained in:
parent
77fd7cd33c
commit
1d3faa7d9b
@ -56,6 +56,6 @@ private class LiveDataObservable<T>(
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> LiveData<T>.asObservable(): Observable<T> {
|
||||
return LiveDataObservable(this)
|
||||
fun <T> LiveData<T>.asObservable(defaultValue: T? = null): Observable<T> {
|
||||
return LiveDataObservable(this, defaultValue)
|
||||
}
|
@ -21,6 +21,7 @@ import im.vector.matrix.android.api.session.group.model.GroupSummary
|
||||
import im.vector.matrix.android.api.session.pushers.Pusher
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
import im.vector.matrix.android.api.session.sync.SyncState
|
||||
import im.vector.matrix.android.api.session.user.model.User
|
||||
import io.reactivex.Observable
|
||||
|
||||
class RxSession(private val session: Session) {
|
||||
@ -41,6 +42,10 @@ class RxSession(private val session: Session) {
|
||||
return session.livePushers().asObservable()
|
||||
}
|
||||
|
||||
fun liveUser(userId: String): Observable<User?> {
|
||||
return session.observeUser(userId).asObservable(User(userId))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun Session.rx(): RxSession {
|
||||
|
@ -54,6 +54,7 @@ class GroupListFragment : VectorBaseFragment(), GroupSummaryController.Callback
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
groupController.callback = this
|
||||
stateView.contentView = groupListEpoxyRecyclerView
|
||||
groupListEpoxyRecyclerView.setHasFixedSize(true)
|
||||
groupListEpoxyRecyclerView.setController(groupController)
|
||||
viewModel.subscribe { renderState(it) }
|
||||
viewModel.openGroupLiveData.observeEvent(this) {
|
||||
|
@ -26,11 +26,16 @@ import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.group.model.GroupSummary
|
||||
import im.vector.matrix.android.api.session.user.model.User
|
||||
import im.vector.matrix.rx.rx
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.core.utils.LiveEvent
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.functions.BiFunction
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
const val ALL_COMMUNITIES_GROUP_ID = "ALL_COMMUNITIES_GROUP_ID"
|
||||
|
||||
@ -89,22 +94,21 @@ class GroupListViewModel @AssistedInject constructor(@Assisted initialState: Gro
|
||||
}
|
||||
|
||||
private fun observeGroupSummaries() {
|
||||
session
|
||||
.rx()
|
||||
.liveGroupSummaries()
|
||||
.map {
|
||||
val myUser = session.getUser(session.sessionParams.credentials.userId)
|
||||
Observable.combineLatest<User?, List<GroupSummary>, List<GroupSummary>>(
|
||||
session.rx().liveUser(session.myUserId),
|
||||
session.rx().liveGroupSummaries(),
|
||||
BiFunction { user, groupSummary ->
|
||||
val allCommunityGroup = GroupSummary(
|
||||
groupId = ALL_COMMUNITIES_GROUP_ID,
|
||||
displayName = stringProvider.getString(R.string.group_all_communities),
|
||||
avatarUrl = myUser?.avatarUrl ?: "")
|
||||
listOf(allCommunityGroup) + it
|
||||
}
|
||||
.execute { async ->
|
||||
// TODO Phase2 Handle the case where the selected group is deleted on another client
|
||||
val newSelectedGroup = selectedGroup ?: async()?.firstOrNull()
|
||||
copy(asyncGroups = async, selectedGroup = newSelectedGroup)
|
||||
avatarUrl = user.avatarUrl ?: "")
|
||||
listOf(allCommunityGroup) + groupSummary
|
||||
}
|
||||
).execute { async ->
|
||||
// TODO Phase2 Handle the case where the selected group is deleted on another client
|
||||
val newSelectedGroup = selectedGroup ?: async()?.firstOrNull()
|
||||
copy(asyncGroups = async, selectedGroup = newSelectedGroup)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user