Merge branch 'hotfix/1.5.0_v2' into main
This commit is contained in:
commit
cb6d0a66cb
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package im.vector.app.features.home.room.list.home
|
package im.vector.app.features.home.room.list.home
|
||||||
|
|
||||||
import androidx.paging.PagedList
|
|
||||||
import com.airbnb.epoxy.EpoxyModel
|
import com.airbnb.epoxy.EpoxyModel
|
||||||
import com.airbnb.epoxy.paging.PagedListEpoxyController
|
import com.airbnb.epoxy.paging.PagedListEpoxyController
|
||||||
import im.vector.app.core.platform.StateView
|
import im.vector.app.core.platform.StateView
|
||||||
|
@ -76,13 +75,6 @@ class HomeFilteredRoomsController @Inject constructor(
|
||||||
this.emptyStateData = state
|
this.emptyStateData = state
|
||||||
}
|
}
|
||||||
|
|
||||||
fun submitPagedList(newList: PagedList<RoomSummary>) {
|
|
||||||
submitList(newList)
|
|
||||||
if (newList.isEmpty()) {
|
|
||||||
requestForcedModelBuild()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun buildItemModel(currentPosition: Int, item: RoomSummary?): EpoxyModel<*> {
|
override fun buildItemModel(currentPosition: Int, item: RoomSummary?): EpoxyModel<*> {
|
||||||
return if (item == null) {
|
return if (item == null) {
|
||||||
val host = this
|
val host = this
|
||||||
|
|
|
@ -152,12 +152,10 @@ class HomeRoomListFragment :
|
||||||
headersController.submitData(it)
|
headersController.submitData(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
roomListViewModel.onEach(HomeRoomListViewState::roomsPagedList) { roomsList ->
|
roomListViewModel.roomsLivePagedList.observe(viewLifecycleOwner) { roomsList ->
|
||||||
roomsList?.let {
|
roomsController.submitList(roomsList)
|
||||||
roomsController.submitPagedList(it)
|
if (roomsList.isEmpty()) {
|
||||||
if (it.isEmpty()) {
|
roomsController.requestForcedModelBuild()
|
||||||
roomsController.requestForcedModelBuild()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,11 @@
|
||||||
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.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
import androidx.paging.PagedList
|
import androidx.paging.PagedList
|
||||||
|
import arrow.core.Option
|
||||||
import arrow.core.toOption
|
import arrow.core.toOption
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
||||||
import dagger.assisted.Assisted
|
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.displayname.getBestName
|
||||||
import im.vector.app.features.home.room.list.home.header.HomeRoomFilter
|
import im.vector.app.features.home.room.list.home.header.HomeRoomFilter
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.asSharedFlow
|
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.Optional
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import org.matrix.android.sdk.flow.flow
|
import org.matrix.android.sdk.flow.flow
|
||||||
import java.util.concurrent.CancellationException
|
|
||||||
|
|
||||||
class HomeRoomListViewModel @AssistedInject constructor(
|
class HomeRoomListViewModel @AssistedInject constructor(
|
||||||
@Assisted initialState: HomeRoomListViewState,
|
@Assisted initialState: HomeRoomListViewState,
|
||||||
|
@ -87,19 +88,24 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
companion object : MavericksViewModelFactory<HomeRoomListViewModel, HomeRoomListViewState> by hiltMavericksViewModelFactory()
|
companion object : MavericksViewModelFactory<HomeRoomListViewModel, HomeRoomListViewState> by hiltMavericksViewModelFactory()
|
||||||
|
|
||||||
|
private var roomsFlow: Flow<Option<RoomSummary>>? = null
|
||||||
private val pagedListConfig = PagedList.Config.Builder()
|
private val pagedListConfig = PagedList.Config.Builder()
|
||||||
.setPageSize(10)
|
.setPageSize(10)
|
||||||
.setInitialLoadSizeHint(20)
|
.setInitialLoadSizeHint(20)
|
||||||
.setEnablePlaceholders(true)
|
.setEnablePlaceholders(true)
|
||||||
.setPrefetchDistance(10)
|
|
||||||
.build()
|
.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 var currentFilter: HomeRoomFilter = HomeRoomFilter.ALL
|
||||||
private val _emptyStateFlow = MutableSharedFlow<Optional<StateView.State.Empty>>(replay = 1)
|
private val _emptyStateFlow = MutableSharedFlow<Optional<StateView.State.Empty>>(replay = 1)
|
||||||
val emptyStateFlow = _emptyStateFlow.asSharedFlow()
|
val emptyStateFlow = _emptyStateFlow.asSharedFlow()
|
||||||
|
|
||||||
private var roomsFlowJob: Job? = null
|
|
||||||
|
|
||||||
private var filteredPagedRoomSummariesLive: UpdatableLivePageResult? = null
|
private var filteredPagedRoomSummariesLive: UpdatableLivePageResult? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -223,6 +229,8 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeRooms() = viewModelScope.launch {
|
private fun observeRooms() = viewModelScope.launch {
|
||||||
|
filteredPagedRoomSummariesLive?.livePagedList?.removeObserver(internalPagedListObserver)
|
||||||
|
|
||||||
val builder = RoomSummaryQueryParams.Builder().also {
|
val builder = RoomSummaryQueryParams.Builder().also {
|
||||||
it.memberships = listOf(Membership.JOIN)
|
it.memberships = listOf(Membership.JOIN)
|
||||||
}
|
}
|
||||||
|
@ -233,7 +241,6 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
||||||
} else {
|
} else {
|
||||||
RoomSortOrder.ACTIVITY
|
RoomSortOrder.ACTIVITY
|
||||||
}
|
}
|
||||||
|
|
||||||
val liveResults = session.roomService().getFilteredPagedRoomSummariesLive(
|
val liveResults = session.roomService().getFilteredPagedRoomSummariesLive(
|
||||||
params,
|
params,
|
||||||
pagedListConfig,
|
pagedListConfig,
|
||||||
|
@ -249,21 +256,15 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
.onEach { selectedSpaceOption ->
|
.onEach { selectedSpaceOption ->
|
||||||
val selectedSpace = selectedSpaceOption.orNull()
|
val selectedSpace = selectedSpaceOption.orNull()
|
||||||
liveResults.queryParams = liveResults.queryParams.copy(
|
filteredPagedRoomSummariesLive?.queryParams = liveResults.queryParams.copy(
|
||||||
spaceFilter = selectedSpace?.roomId.toActiveSpaceOrNoFilter()
|
spaceFilter = selectedSpace?.roomId.toActiveSpaceOrNoFilter()
|
||||||
)
|
)
|
||||||
emitEmptyState()
|
emitEmptyState()
|
||||||
}
|
}
|
||||||
|
.also { roomsFlow = it }
|
||||||
.launchIn(viewModelScope)
|
.launchIn(viewModelScope)
|
||||||
|
|
||||||
roomsFlowJob?.cancel(CancellationException())
|
liveResults.livePagedList.observeForever(internalPagedListObserver)
|
||||||
|
|
||||||
roomsFlowJob = liveResults.livePagedList
|
|
||||||
.asFlow()
|
|
||||||
.onEach {
|
|
||||||
setState { copy(roomsPagedList = it) }
|
|
||||||
}
|
|
||||||
.launchIn(viewModelScope)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeOrderPreferences() {
|
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) {
|
private fun handleChangeRoomFilter(newFilter: HomeRoomFilter) {
|
||||||
if (currentFilter == newFilter) {
|
if (currentFilter == newFilter) {
|
||||||
return
|
return
|
||||||
|
|
|
@ -16,14 +16,11 @@
|
||||||
|
|
||||||
package im.vector.app.features.home.room.list.home
|
package im.vector.app.features.home.room.list.home
|
||||||
|
|
||||||
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
|
||||||
import im.vector.app.features.home.room.list.home.header.RoomsHeadersData
|
import im.vector.app.features.home.room.list.home.header.RoomsHeadersData
|
||||||
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 roomsPagedList: PagedList<RoomSummary>? = null,
|
|
||||||
) : MavericksState
|
) : MavericksState
|
||||||
|
|
Loading…
Reference in New Issue