Fix new layout flicker/leaks
This commit is contained in:
parent
56189a2d5d
commit
2ea357ddc0
|
@ -51,6 +51,8 @@ import kotlinx.coroutines.flow.map
|
|||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.query.RoomCategoryFilter
|
||||
|
@ -108,12 +110,34 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
|||
|
||||
private var filteredPagedRoomSummariesLive: UpdatableLivePageResult? = null
|
||||
|
||||
private val switchDataSourceMutex = Mutex()
|
||||
|
||||
init {
|
||||
observeOrderPreferences()
|
||||
observeInvites()
|
||||
observeRecents()
|
||||
observeFilterTabs()
|
||||
observeRooms()
|
||||
observeSpaceChanges()
|
||||
}
|
||||
|
||||
private fun observeSpaceChanges() {
|
||||
spaceStateHandler.getSelectedSpaceFlow()
|
||||
.distinctUntilChanged()
|
||||
.onStart {
|
||||
emit(spaceStateHandler.getCurrentSpace().toOption())
|
||||
}
|
||||
.onEach { selectedSpaceOption ->
|
||||
val selectedSpace = selectedSpaceOption.orNull()
|
||||
filteredPagedRoomSummariesLive?.let { liveResults ->
|
||||
liveResults.queryParams = liveResults.queryParams.copy(
|
||||
spaceFilter = selectedSpace?.roomId.toActiveSpaceOrNoFilter()
|
||||
)
|
||||
emitEmptyState()
|
||||
}
|
||||
}
|
||||
.also { roomsFlow = it }
|
||||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
private fun observeInvites() {
|
||||
|
@ -229,10 +253,12 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
|||
}
|
||||
|
||||
private fun observeRooms() = viewModelScope.launch {
|
||||
switchDataSourceMutex.withLock {
|
||||
filteredPagedRoomSummariesLive?.livePagedList?.removeObserver(internalPagedListObserver)
|
||||
|
||||
val builder = RoomSummaryQueryParams.Builder().also {
|
||||
it.memberships = listOf(Membership.JOIN)
|
||||
it.spaceFilter = spaceStateHandler.getCurrentSpace()?.roomId.toActiveSpaceOrNoFilter()
|
||||
}
|
||||
|
||||
val params = getFilteredQueryParams(currentFilter, builder.build())
|
||||
|
@ -249,23 +275,9 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
|||
filteredPagedRoomSummariesLive = it
|
||||
}
|
||||
|
||||
spaceStateHandler.getSelectedSpaceFlow()
|
||||
.distinctUntilChanged()
|
||||
.onStart {
|
||||
emit(spaceStateHandler.getCurrentSpace().toOption())
|
||||
}
|
||||
.onEach { selectedSpaceOption ->
|
||||
val selectedSpace = selectedSpaceOption.orNull()
|
||||
filteredPagedRoomSummariesLive?.queryParams = liveResults.queryParams.copy(
|
||||
spaceFilter = selectedSpace?.roomId.toActiveSpaceOrNoFilter()
|
||||
)
|
||||
emitEmptyState()
|
||||
}
|
||||
.also { roomsFlow = it }
|
||||
.launchIn(viewModelScope)
|
||||
|
||||
liveResults.livePagedList.observeForever(internalPagedListObserver)
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeOrderPreferences() {
|
||||
preferencesStore.isAZOrderingEnabledFlow.onEach {
|
||||
|
|
Loading…
Reference in New Issue