Fixes room list not getting updated when not in focus

This commit is contained in:
ericdecanini 2022-09-20 18:22:39 -04:00
parent 8624199be3
commit fe1e74fa06
3 changed files with 14 additions and 7 deletions

View file

@ -152,10 +152,10 @@ class HomeRoomListFragment :
headersController.submitData(it) headersController.submitData(it)
} }
roomListViewModel.onEach(HomeRoomListViewState::roomsLivePagedList) { roomsListLive -> roomListViewModel.onEach(HomeRoomListViewState::roomsLivePagedList) { roomsList ->
roomsListLive?.observe(viewLifecycleOwner) { roomsList -> roomsList?.let {
roomsController.submitList(roomsList) roomsController.submitList(it)
if (roomsList.isEmpty()) { if (it.isEmpty()) {
roomsController.requestForcedModelBuild() roomsController.requestForcedModelBuild()
} }
} }

View file

@ -17,6 +17,7 @@
package im.vector.app.features.home.room.list.home package im.vector.app.features.home.room.list.home
import android.widget.ImageView import android.widget.ImageView
import androidx.lifecycle.asFlow
import androidx.paging.PagedList import androidx.paging.PagedList
import arrow.core.Option import arrow.core.Option
import arrow.core.toOption import arrow.core.toOption
@ -43,6 +44,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
@ -254,7 +256,13 @@ class HomeRoomListViewModel @AssistedInject constructor(
.also { roomsFlow = it } .also { roomsFlow = it }
.launchIn(viewModelScope) .launchIn(viewModelScope)
setState { copy(roomsLivePagedList = liveResults.livePagedList) } liveResults.livePagedList
.asFlow()
.onEach {
setState { copy(roomsLivePagedList = it) }
}
.flowOn(Dispatchers.Default)
.launchIn(viewModelScope)
} }
private fun observeOrderPreferences() { private fun observeOrderPreferences() {

View file

@ -16,7 +16,6 @@
package im.vector.app.features.home.room.list.home package im.vector.app.features.home.room.list.home
import androidx.lifecycle.LiveData
import androidx.paging.PagedList import androidx.paging.PagedList
import com.airbnb.mvrx.MavericksState import com.airbnb.mvrx.MavericksState
import im.vector.app.core.platform.StateView import im.vector.app.core.platform.StateView
@ -26,5 +25,5 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
data class HomeRoomListViewState( data class HomeRoomListViewState(
val state: StateView.State = StateView.State.Content, val state: StateView.State = StateView.State.Content,
val headersData: RoomsHeadersData = RoomsHeadersData(), val headersData: RoomsHeadersData = RoomsHeadersData(),
val roomsLivePagedList: LiveData<PagedList<RoomSummary>>? = null, val roomsLivePagedList: PagedList<RoomSummary>? = null,
) : MavericksState ) : MavericksState