mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 11:59:12 +03:00
Merge pull request #7186 from vector-im/bugfix/eric/fixes-room-list-updates
Fixes Room List not getting updated when fragment is not in focus
This commit is contained in:
commit
52d7369ac3
5 changed files with 27 additions and 10 deletions
1
changelog.d/7186.bugfix
Normal file
1
changelog.d/7186.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Fixes Room List not getting updated when fragment is not in focus
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package im.vector.app.features.home.room.list.home
|
||||
|
||||
import androidx.paging.PagedList
|
||||
import com.airbnb.epoxy.EpoxyModel
|
||||
import com.airbnb.epoxy.paging.PagedListEpoxyController
|
||||
import im.vector.app.core.platform.StateView
|
||||
|
@ -75,6 +76,13 @@ class HomeFilteredRoomsController @Inject constructor(
|
|||
this.emptyStateData = state
|
||||
}
|
||||
|
||||
fun submitPagedList(newList: PagedList<RoomSummary>) {
|
||||
submitList(newList)
|
||||
if (newList.isEmpty()) {
|
||||
requestForcedModelBuild()
|
||||
}
|
||||
}
|
||||
|
||||
override fun buildItemModel(currentPosition: Int, item: RoomSummary?): EpoxyModel<*> {
|
||||
return if (item == null) {
|
||||
val host = this
|
||||
|
|
|
@ -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::roomsPagedList) { roomsList ->
|
||||
roomsList?.let {
|
||||
roomsController.submitPagedList(it)
|
||||
if (it.isEmpty()) {
|
||||
roomsController.requestForcedModelBuild()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
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
|
||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||
import dagger.assisted.Assisted
|
||||
|
@ -35,6 +35,7 @@ import im.vector.app.core.resources.StringProvider
|
|||
import im.vector.app.features.displayname.getBestName
|
||||
import im.vector.app.features.home.room.list.home.header.HomeRoomFilter
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
|
@ -68,6 +69,7 @@ import org.matrix.android.sdk.api.session.room.state.isPublic
|
|||
import org.matrix.android.sdk.api.util.Optional
|
||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||
import org.matrix.android.sdk.flow.flow
|
||||
import java.util.concurrent.CancellationException
|
||||
|
||||
class HomeRoomListViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: HomeRoomListViewState,
|
||||
|
@ -85,7 +87,6 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
|||
|
||||
companion object : MavericksViewModelFactory<HomeRoomListViewModel, HomeRoomListViewState> by hiltMavericksViewModelFactory()
|
||||
|
||||
private var roomsFlow: Flow<Option<RoomSummary>>? = null
|
||||
private val pagedListConfig = PagedList.Config.Builder()
|
||||
.setPageSize(10)
|
||||
.setInitialLoadSizeHint(20)
|
||||
|
@ -97,6 +98,8 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
|||
private val _emptyStateFlow = MutableSharedFlow<Optional<StateView.State.Empty>>(replay = 1)
|
||||
val emptyStateFlow = _emptyStateFlow.asSharedFlow()
|
||||
|
||||
private var roomsFlowJob: Job? = null
|
||||
|
||||
private var filteredPagedRoomSummariesLive: UpdatableLivePageResult? = null
|
||||
|
||||
init {
|
||||
|
@ -251,10 +254,16 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
|||
)
|
||||
emitEmptyState()
|
||||
}
|
||||
.also { roomsFlow = it }
|
||||
.launchIn(viewModelScope)
|
||||
|
||||
setState { copy(roomsLivePagedList = liveResults.livePagedList) }
|
||||
roomsFlowJob?.cancel(CancellationException())
|
||||
|
||||
roomsFlowJob = liveResults.livePagedList
|
||||
.asFlow()
|
||||
.onEach {
|
||||
setState { copy(roomsPagedList = it) }
|
||||
}
|
||||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
private fun observeOrderPreferences() {
|
||||
|
|
|
@ -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<PagedList<RoomSummary>>? = null,
|
||||
val roomsPagedList: PagedList<RoomSummary>? = null,
|
||||
) : MavericksState
|
||||
|
|
Loading…
Reference in a new issue