Rework on how we dispose the subscriptions
This commit is contained in:
parent
ac2f1ee7fe
commit
256df7e869
@ -20,4 +20,6 @@ import im.vector.app.features.home.RoomListDisplayMode
|
|||||||
|
|
||||||
interface RoomListSectionBuilder {
|
interface RoomListSectionBuilder {
|
||||||
fun buildSections(mode: RoomListDisplayMode) : List<RoomsSection>
|
fun buildSections(mode: RoomListDisplayMode) : List<RoomsSection>
|
||||||
|
|
||||||
|
fun dispose()
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import im.vector.app.core.resources.StringProvider
|
|||||||
import im.vector.app.features.home.RoomListDisplayMode
|
import im.vector.app.features.home.RoomListDisplayMode
|
||||||
import im.vector.app.features.invite.AutoAcceptInvites
|
import im.vector.app.features.invite.AutoAcceptInvites
|
||||||
import im.vector.app.features.invite.showInvites
|
import im.vector.app.features.invite.showInvites
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import org.matrix.android.sdk.api.query.RoomCategoryFilter
|
import org.matrix.android.sdk.api.query.RoomCategoryFilter
|
||||||
import org.matrix.android.sdk.api.query.RoomTagQueryFilter
|
import org.matrix.android.sdk.api.query.RoomTagQueryFilter
|
||||||
@ -39,10 +39,11 @@ class RoomListSectionBuilderGroup(
|
|||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
private val appStateHandler: AppStateHandler,
|
private val appStateHandler: AppStateHandler,
|
||||||
private val autoAcceptInvites: AutoAcceptInvites,
|
private val autoAcceptInvites: AutoAcceptInvites,
|
||||||
private val onDisposable: (Disposable) -> Unit,
|
|
||||||
private val onUpdatable: (UpdatableLivePageResult) -> Unit
|
private val onUpdatable: (UpdatableLivePageResult) -> Unit
|
||||||
) : RoomListSectionBuilder {
|
) : RoomListSectionBuilder {
|
||||||
|
|
||||||
|
private val disposables = CompositeDisposable()
|
||||||
|
|
||||||
override fun buildSections(mode: RoomListDisplayMode): List<RoomsSection> {
|
override fun buildSections(mode: RoomListDisplayMode): List<RoomsSection> {
|
||||||
val activeGroupAwareQueries = mutableListOf<UpdatableLivePageResult>()
|
val activeGroupAwareQueries = mutableListOf<UpdatableLivePageResult>()
|
||||||
val sections = mutableListOf<RoomsSection>()
|
val sections = mutableListOf<RoomsSection>()
|
||||||
@ -110,7 +111,7 @@ class RoomListSectionBuilderGroup(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.also {
|
}.also {
|
||||||
onDisposable.invoke(it)
|
disposables.add(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sections
|
return sections
|
||||||
@ -257,7 +258,7 @@ class RoomListSectionBuilderGroup(
|
|||||||
?.notificationCount
|
?.notificationCount
|
||||||
?.postValue(session.getNotificationCountForRooms(roomQueryParams))
|
?.postValue(session.getNotificationCountForRooms(roomQueryParams))
|
||||||
}.also {
|
}.also {
|
||||||
onDisposable.invoke(it)
|
disposables.add(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
sections.add(
|
sections.add(
|
||||||
@ -279,4 +280,8 @@ class RoomListSectionBuilderGroup(
|
|||||||
.build()
|
.build()
|
||||||
.let { block(it) }
|
.let { block(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun dispose() {
|
||||||
|
disposables.dispose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import im.vector.app.features.invite.AutoAcceptInvites
|
|||||||
import im.vector.app.features.invite.showInvites
|
import im.vector.app.features.invite.showInvites
|
||||||
import im.vector.app.space
|
import im.vector.app.space
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxkotlin.Observables
|
import io.reactivex.rxkotlin.Observables
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@ -52,12 +52,13 @@ class RoomListSectionBuilderSpace(
|
|||||||
private val appStateHandler: AppStateHandler,
|
private val appStateHandler: AppStateHandler,
|
||||||
private val viewModelScope: CoroutineScope,
|
private val viewModelScope: CoroutineScope,
|
||||||
private val autoAcceptInvites: AutoAcceptInvites,
|
private val autoAcceptInvites: AutoAcceptInvites,
|
||||||
private val onDisposable: (Disposable) -> Unit,
|
|
||||||
private val onUpdatable: (UpdatableLivePageResult) -> Unit,
|
private val onUpdatable: (UpdatableLivePageResult) -> Unit,
|
||||||
private val suggestedRoomJoiningState: LiveData<Map<String, Async<Unit>>>,
|
private val suggestedRoomJoiningState: LiveData<Map<String, Async<Unit>>>,
|
||||||
private val onlyOrphansInHome: Boolean = false
|
private val onlyOrphansInHome: Boolean = false
|
||||||
) : RoomListSectionBuilder {
|
) : RoomListSectionBuilder {
|
||||||
|
|
||||||
|
private val disposables = CompositeDisposable()
|
||||||
|
|
||||||
private val pagedListConfig = PagedList.Config.Builder()
|
private val pagedListConfig = PagedList.Config.Builder()
|
||||||
.setPageSize(10)
|
.setPageSize(10)
|
||||||
.setInitialLoadSizeHint(20)
|
.setInitialLoadSizeHint(20)
|
||||||
@ -137,7 +138,7 @@ class RoomListSectionBuilderSpace(
|
|||||||
updater.updateForSpaceId(selectedSpace?.roomId)
|
updater.updateForSpaceId(selectedSpace?.roomId)
|
||||||
}
|
}
|
||||||
}.also {
|
}.also {
|
||||||
onDisposable.invoke(it)
|
disposables.add(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sections
|
return sections
|
||||||
@ -252,7 +253,7 @@ class RoomListSectionBuilderSpace(
|
|||||||
}.subscribe {
|
}.subscribe {
|
||||||
liveSuggestedRooms.postValue(it)
|
liveSuggestedRooms.postValue(it)
|
||||||
}.also {
|
}.also {
|
||||||
onDisposable.invoke(it)
|
disposables.add(it)
|
||||||
}
|
}
|
||||||
sections.add(
|
sections.add(
|
||||||
RoomsSection(
|
RoomsSection(
|
||||||
@ -384,7 +385,7 @@ class RoomListSectionBuilderSpace(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}.also {
|
}.also {
|
||||||
onDisposable.invoke(it)
|
disposables.add(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
sections.add(
|
sections.add(
|
||||||
@ -428,4 +429,8 @@ class RoomListSectionBuilderSpace(
|
|||||||
RoomListViewModel.SpaceFilterStrategy.NONE -> this
|
RoomListViewModel.SpaceFilterStrategy.NONE -> this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun dispose() {
|
||||||
|
disposables.dispose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,17 +120,13 @@ class RoomListViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val sections: List<RoomsSection> by lazy {
|
private val roomListSectionBuilder = if (appStateHandler.getCurrentRoomGroupingMethod() is RoomGroupingMethod.BySpace) {
|
||||||
if (appStateHandler.getCurrentRoomGroupingMethod() is RoomGroupingMethod.BySpace) {
|
|
||||||
RoomListSectionBuilderSpace(
|
RoomListSectionBuilderSpace(
|
||||||
session,
|
session,
|
||||||
stringProvider,
|
stringProvider,
|
||||||
appStateHandler,
|
appStateHandler,
|
||||||
viewModelScope,
|
viewModelScope,
|
||||||
autoAcceptInvites,
|
autoAcceptInvites,
|
||||||
{
|
|
||||||
it.disposeOnClear()
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
updatableQuery = it
|
updatableQuery = it
|
||||||
},
|
},
|
||||||
@ -142,15 +138,14 @@ class RoomListViewModel @Inject constructor(
|
|||||||
session,
|
session,
|
||||||
stringProvider,
|
stringProvider,
|
||||||
appStateHandler,
|
appStateHandler,
|
||||||
autoAcceptInvites,
|
autoAcceptInvites
|
||||||
{
|
|
||||||
it.disposeOnClear()
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
updatableQuery = it
|
updatableQuery = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.buildSections(initialState.displayMode)
|
|
||||||
|
val sections: List<RoomsSection> by lazy {
|
||||||
|
roomListSectionBuilder.buildSections(initialState.displayMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handle(action: RoomListAction) {
|
override fun handle(action: RoomListAction) {
|
||||||
@ -340,4 +335,9 @@ class RoomListViewModel @Inject constructor(
|
|||||||
_viewEvents.post(value)
|
_viewEvents.post(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
super.onCleared()
|
||||||
|
roomListSectionBuilder.dispose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user