Create a UserViewModel to avoid duplicated code.
This commit is contained in:
parent
2d9a5b5a2a
commit
98645ebb5b
9 changed files with 132 additions and 8 deletions
|
|
@ -50,19 +50,22 @@ import io.element.android.x.features.roomlist.model.stubbedRoomSummaries
|
|||
import io.element.android.x.matrix.core.RoomId
|
||||
import io.element.android.x.matrix.core.UserId
|
||||
import io.element.android.x.matrix.ui.model.MatrixUser
|
||||
import io.element.android.x.matrix.ui.viewmodels.user.UserViewModel
|
||||
import io.element.android.x.matrix.ui.viewmodels.user.UserViewState
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
@Composable
|
||||
fun RoomListScreen(
|
||||
viewModel: RoomListViewModel = mavericksViewModel(),
|
||||
userViewModel: UserViewModel = mavericksViewModel(),
|
||||
onRoomClicked: (RoomId) -> Unit = { },
|
||||
onOpenSettings: () -> Unit = { },
|
||||
) {
|
||||
val filter by viewModel.collectAsState(RoomListViewState::filter)
|
||||
LogCompositions(tag = "RoomListScreen", msg = "Root")
|
||||
val roomSummaries by viewModel.collectAsState(RoomListViewState::rooms)
|
||||
val matrixUser by viewModel.collectAsState(RoomListViewState::user)
|
||||
val matrixUser by userViewModel.collectAsState(UserViewState::user)
|
||||
RoomListContent(
|
||||
roomSummaries = roomSummaries().orEmpty().toImmutableList(),
|
||||
matrixUser = matrixUser(),
|
||||
|
|
|
|||
|
|
@ -78,10 +78,6 @@ class RoomListViewModel @AssistedInject constructor(
|
|||
}
|
||||
|
||||
private fun handleInit() {
|
||||
matrixUserHelper.getCurrentUserData(avatarSize = AvatarSize.SMALL).execute {
|
||||
copy(user = it)
|
||||
}
|
||||
|
||||
// Observe the room list and the filter
|
||||
combine(
|
||||
client.roomSummaryDataSource().roomSummaries()
|
||||
|
|
|
|||
|
|
@ -20,10 +20,8 @@ import com.airbnb.mvrx.Async
|
|||
import com.airbnb.mvrx.MavericksState
|
||||
import com.airbnb.mvrx.Uninitialized
|
||||
import io.element.android.x.matrix.core.RoomId
|
||||
import io.element.android.x.matrix.ui.model.MatrixUser
|
||||
|
||||
data class RoomListViewState(
|
||||
val user: Async<MatrixUser> = Uninitialized,
|
||||
// Will contain the filtered rooms, using ::filter (if filter is not empty)
|
||||
val rooms: Async<List<RoomListRoomSummary>> = Uninitialized,
|
||||
val filter: String = "",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue