Merge branch 'hotfix/1.5.0_v2' into main

This commit is contained in:
ganfra 2022-09-22 18:18:26 +02:00
commit cb6d0a66cb
4 changed files with 26 additions and 33 deletions

View File

@ -16,7 +16,6 @@
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
@ -76,13 +75,6 @@ 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

View File

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

View File

@ -17,8 +17,11 @@
package im.vector.app.features.home.room.list.home
import android.widget.ImageView
import androidx.lifecycle.asFlow
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.paging.PagedList
import arrow.core.Option
import arrow.core.toOption
import com.airbnb.mvrx.MavericksViewModelFactory
import dagger.assisted.Assisted
@ -35,7 +38,6 @@ 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
@ -69,7 +71,6 @@ 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,
@ -87,19 +88,24 @@ 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)
.setEnablePlaceholders(true)
.setPrefetchDistance(10)
.build()
private val _roomsLivePagedList = MutableLiveData<PagedList<RoomSummary>>()
val roomsLivePagedList: LiveData<PagedList<RoomSummary>> = _roomsLivePagedList
private val internalPagedListObserver = Observer<PagedList<RoomSummary>> {
_roomsLivePagedList.postValue(it)
}
private var currentFilter: HomeRoomFilter = HomeRoomFilter.ALL
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 {
@ -223,6 +229,8 @@ class HomeRoomListViewModel @AssistedInject constructor(
}
private fun observeRooms() = viewModelScope.launch {
filteredPagedRoomSummariesLive?.livePagedList?.removeObserver(internalPagedListObserver)
val builder = RoomSummaryQueryParams.Builder().also {
it.memberships = listOf(Membership.JOIN)
}
@ -233,7 +241,6 @@ class HomeRoomListViewModel @AssistedInject constructor(
} else {
RoomSortOrder.ACTIVITY
}
val liveResults = session.roomService().getFilteredPagedRoomSummariesLive(
params,
pagedListConfig,
@ -249,21 +256,15 @@ class HomeRoomListViewModel @AssistedInject constructor(
}
.onEach { selectedSpaceOption ->
val selectedSpace = selectedSpaceOption.orNull()
liveResults.queryParams = liveResults.queryParams.copy(
filteredPagedRoomSummariesLive?.queryParams = liveResults.queryParams.copy(
spaceFilter = selectedSpace?.roomId.toActiveSpaceOrNoFilter()
)
emitEmptyState()
}
.also { roomsFlow = it }
.launchIn(viewModelScope)
roomsFlowJob?.cancel(CancellationException())
roomsFlowJob = liveResults.livePagedList
.asFlow()
.onEach {
setState { copy(roomsPagedList = it) }
}
.launchIn(viewModelScope)
liveResults.livePagedList.observeForever(internalPagedListObserver)
}
private fun observeOrderPreferences() {
@ -344,6 +345,11 @@ class HomeRoomListViewModel @AssistedInject constructor(
}
}
override fun onCleared() {
super.onCleared()
filteredPagedRoomSummariesLive?.livePagedList?.removeObserver(internalPagedListObserver)
}
private fun handleChangeRoomFilter(newFilter: HomeRoomFilter) {
if (currentFilter == newFilter) {
return

View File

@ -16,14 +16,11 @@
package im.vector.app.features.home.room.list.home
import androidx.paging.PagedList
import com.airbnb.mvrx.MavericksState
import im.vector.app.core.platform.StateView
import im.vector.app.features.home.room.list.home.header.RoomsHeadersData
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 roomsPagedList: PagedList<RoomSummary>? = null,
) : MavericksState