mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Rework on how we dispose the subscriptions
This commit is contained in:
parent
ac2f1ee7fe
commit
256df7e869
4 changed files with 51 additions and 39 deletions
|
@ -20,4 +20,6 @@ import im.vector.app.features.home.RoomListDisplayMode
|
|||
|
||||
interface RoomListSectionBuilder {
|
||||
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.invite.AutoAcceptInvites
|
||||
import im.vector.app.features.invite.showInvites
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.matrix.android.sdk.api.query.RoomCategoryFilter
|
||||
import org.matrix.android.sdk.api.query.RoomTagQueryFilter
|
||||
|
@ -39,10 +39,11 @@ class RoomListSectionBuilderGroup(
|
|||
private val stringProvider: StringProvider,
|
||||
private val appStateHandler: AppStateHandler,
|
||||
private val autoAcceptInvites: AutoAcceptInvites,
|
||||
private val onDisposable: (Disposable) -> Unit,
|
||||
private val onUpdatable: (UpdatableLivePageResult) -> Unit
|
||||
) : RoomListSectionBuilder {
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
override fun buildSections(mode: RoomListDisplayMode): List<RoomsSection> {
|
||||
val activeGroupAwareQueries = mutableListOf<UpdatableLivePageResult>()
|
||||
val sections = mutableListOf<RoomsSection>()
|
||||
|
@ -110,7 +111,7 @@ class RoomListSectionBuilderGroup(
|
|||
}
|
||||
}
|
||||
}.also {
|
||||
onDisposable.invoke(it)
|
||||
disposables.add(it)
|
||||
}
|
||||
|
||||
return sections
|
||||
|
@ -257,7 +258,7 @@ class RoomListSectionBuilderGroup(
|
|||
?.notificationCount
|
||||
?.postValue(session.getNotificationCountForRooms(roomQueryParams))
|
||||
}.also {
|
||||
onDisposable.invoke(it)
|
||||
disposables.add(it)
|
||||
}
|
||||
|
||||
sections.add(
|
||||
|
@ -279,4 +280,8 @@ class RoomListSectionBuilderGroup(
|
|||
.build()
|
||||
.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.space
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
@ -52,12 +52,13 @@ class RoomListSectionBuilderSpace(
|
|||
private val appStateHandler: AppStateHandler,
|
||||
private val viewModelScope: CoroutineScope,
|
||||
private val autoAcceptInvites: AutoAcceptInvites,
|
||||
private val onDisposable: (Disposable) -> Unit,
|
||||
private val onUpdatable: (UpdatableLivePageResult) -> Unit,
|
||||
private val suggestedRoomJoiningState: LiveData<Map<String, Async<Unit>>>,
|
||||
private val onlyOrphansInHome: Boolean = false
|
||||
) : RoomListSectionBuilder {
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
private val pagedListConfig = PagedList.Config.Builder()
|
||||
.setPageSize(10)
|
||||
.setInitialLoadSizeHint(20)
|
||||
|
@ -137,7 +138,7 @@ class RoomListSectionBuilderSpace(
|
|||
updater.updateForSpaceId(selectedSpace?.roomId)
|
||||
}
|
||||
}.also {
|
||||
onDisposable.invoke(it)
|
||||
disposables.add(it)
|
||||
}
|
||||
|
||||
return sections
|
||||
|
@ -252,7 +253,7 @@ class RoomListSectionBuilderSpace(
|
|||
}.subscribe {
|
||||
liveSuggestedRooms.postValue(it)
|
||||
}.also {
|
||||
onDisposable.invoke(it)
|
||||
disposables.add(it)
|
||||
}
|
||||
sections.add(
|
||||
RoomsSection(
|
||||
|
@ -384,7 +385,7 @@ class RoomListSectionBuilderSpace(
|
|||
}
|
||||
)
|
||||
}.also {
|
||||
onDisposable.invoke(it)
|
||||
disposables.add(it)
|
||||
}
|
||||
|
||||
sections.add(
|
||||
|
@ -428,4 +429,8 @@ class RoomListSectionBuilderSpace(
|
|||
RoomListViewModel.SpaceFilterStrategy.NONE -> this
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
disposables.dispose()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,37 +120,32 @@ class RoomListViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
val sections: List<RoomsSection> by lazy {
|
||||
if (appStateHandler.getCurrentRoomGroupingMethod() is RoomGroupingMethod.BySpace) {
|
||||
RoomListSectionBuilderSpace(
|
||||
session,
|
||||
stringProvider,
|
||||
appStateHandler,
|
||||
viewModelScope,
|
||||
autoAcceptInvites,
|
||||
{
|
||||
it.disposeOnClear()
|
||||
},
|
||||
{
|
||||
updatableQuery = it
|
||||
},
|
||||
suggestedRoomJoiningState,
|
||||
vectorPreferences.labsSpacesOnlyOrphansInHome()
|
||||
)
|
||||
} else {
|
||||
RoomListSectionBuilderGroup(
|
||||
session,
|
||||
stringProvider,
|
||||
appStateHandler,
|
||||
autoAcceptInvites,
|
||||
{
|
||||
it.disposeOnClear()
|
||||
}
|
||||
) {
|
||||
updatableQuery = it
|
||||
}
|
||||
private val roomListSectionBuilder = if (appStateHandler.getCurrentRoomGroupingMethod() is RoomGroupingMethod.BySpace) {
|
||||
RoomListSectionBuilderSpace(
|
||||
session,
|
||||
stringProvider,
|
||||
appStateHandler,
|
||||
viewModelScope,
|
||||
autoAcceptInvites,
|
||||
{
|
||||
updatableQuery = it
|
||||
},
|
||||
suggestedRoomJoiningState,
|
||||
vectorPreferences.labsSpacesOnlyOrphansInHome()
|
||||
)
|
||||
} else {
|
||||
RoomListSectionBuilderGroup(
|
||||
session,
|
||||
stringProvider,
|
||||
appStateHandler,
|
||||
autoAcceptInvites
|
||||
) {
|
||||
updatableQuery = it
|
||||
}
|
||||
.buildSections(initialState.displayMode)
|
||||
}
|
||||
|
||||
val sections: List<RoomsSection> by lazy {
|
||||
roomListSectionBuilder.buildSections(initialState.displayMode)
|
||||
}
|
||||
|
||||
override fun handle(action: RoomListAction) {
|
||||
|
@ -340,4 +335,9 @@ class RoomListViewModel @Inject constructor(
|
|||
_viewEvents.post(value)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
roomListSectionBuilder.dispose()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue