diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt index 829634259a..a0bd2d670a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt @@ -152,10 +152,10 @@ class HomeRoomListFragment : headersController.submitData(it) } - roomListViewModel.onEach(HomeRoomListViewState::roomsLivePagedList) { roomsListLive -> - roomsListLive?.observe(viewLifecycleOwner) { roomsList -> - roomsController.submitList(roomsList) - if (roomsList.isEmpty()) { + roomListViewModel.onEach(HomeRoomListViewState::roomsLivePagedList) { roomsList -> + roomsList?.let { + roomsController.submitList(it) + if (it.isEmpty()) { roomsController.requestForcedModelBuild() } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt index 35b2f02917..93856abd30 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt @@ -17,6 +17,7 @@ package im.vector.app.features.home.room.list.home import android.widget.ImageView +import androidx.lifecycle.asFlow import androidx.paging.PagedList import arrow.core.Option import arrow.core.toOption @@ -43,6 +44,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach @@ -254,7 +256,13 @@ class HomeRoomListViewModel @AssistedInject constructor( .also { roomsFlow = it } .launchIn(viewModelScope) - setState { copy(roomsLivePagedList = liveResults.livePagedList) } + liveResults.livePagedList + .asFlow() + .onEach { + setState { copy(roomsLivePagedList = it) } + } + .flowOn(Dispatchers.Default) + .launchIn(viewModelScope) } private fun observeOrderPreferences() { diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewState.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewState.kt index 95625bc4b9..7b7719981f 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewState.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewState.kt @@ -16,7 +16,6 @@ package im.vector.app.features.home.room.list.home -import androidx.lifecycle.LiveData import androidx.paging.PagedList import com.airbnb.mvrx.MavericksState import im.vector.app.core.platform.StateView @@ -26,5 +25,5 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary data class HomeRoomListViewState( val state: StateView.State = StateView.State.Content, val headersData: RoomsHeadersData = RoomsHeadersData(), - val roomsLivePagedList: LiveData>? = null, + val roomsLivePagedList: PagedList? = null, ) : MavericksState