From ca2794193c23e639be0b2e290b8524ed793244a9 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 19 Jul 2021 18:16:36 +0200 Subject: [PATCH 1/8] Typo --- .../features/home/room/list/GroupRoomListSectionBuilder.kt | 4 ++-- .../features/home/room/list/SpaceRoomListSectionBuilder.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/GroupRoomListSectionBuilder.kt b/vector/src/main/java/im/vector/app/features/home/room/list/GroupRoomListSectionBuilder.kt index 106a02cd3c..4e6fe3ccee 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/GroupRoomListSectionBuilder.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/GroupRoomListSectionBuilder.kt @@ -42,7 +42,7 @@ class GroupRoomListSectionBuilder( val appStateHandler: AppStateHandler, private val autoAcceptInvites: AutoAcceptInvites, val onDisposable: (Disposable) -> Unit, - val onUdpatable: (UpdatableLivePageResult) -> Unit + val onUpdatable: (UpdatableLivePageResult) -> Unit ) : RoomListSectionBuilder { override fun buildSections(mode: RoomListDisplayMode): List { @@ -69,7 +69,7 @@ class GroupRoomListSectionBuilder( val name = stringProvider.getString(R.string.bottom_action_rooms) session.getFilteredPagedRoomSummariesLive(qpm) .let { updatableFilterLivePageResult -> - onUdpatable(updatableFilterLivePageResult) + onUpdatable(updatableFilterLivePageResult) sections.add(RoomsSection(name, updatableFilterLivePageResult.livePagedList)) } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/SpaceRoomListSectionBuilder.kt b/vector/src/main/java/im/vector/app/features/home/room/list/SpaceRoomListSectionBuilder.kt index 5a296ce7ed..a05e464ab1 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/SpaceRoomListSectionBuilder.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/SpaceRoomListSectionBuilder.kt @@ -54,7 +54,7 @@ class SpaceRoomListSectionBuilder( private val suggestedRoomJoiningState: LiveData>>, private val autoAcceptInvites: AutoAcceptInvites, val onDisposable: (Disposable) -> Unit, - val onUdpatable: (UpdatableLivePageResult) -> Unit, + val onUpdatable: (UpdatableLivePageResult) -> Unit, val onlyOrphansInHome: Boolean = false ) : RoomListSectionBuilder { @@ -84,7 +84,7 @@ class SpaceRoomListSectionBuilder( val name = stringProvider.getString(R.string.bottom_action_rooms) session.getFilteredPagedRoomSummariesLive(qpm) .let { updatableFilterLivePageResult -> - onUdpatable(updatableFilterLivePageResult) + onUpdatable(updatableFilterLivePageResult) sections.add(RoomsSection(name, updatableFilterLivePageResult.livePagedList)) } } From ac8303bb990347c7cf246d8b409611c5f7060fc6 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 19 Jul 2021 18:23:14 +0200 Subject: [PATCH 2/8] Add low priority section in DM tab #3463 --- changelog.d/3463.feature | 1 + .../room/list/GroupRoomListSectionBuilder.kt | 17 +++++++++++--- .../room/list/SpaceRoomListSectionBuilder.kt | 23 +++++++++++++++---- 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 changelog.d/3463.feature diff --git a/changelog.d/3463.feature b/changelog.d/3463.feature new file mode 100644 index 0000000000..a0a5f85393 --- /dev/null +++ b/changelog.d/3463.feature @@ -0,0 +1 @@ +Add low priority section in DM tab \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/GroupRoomListSectionBuilder.kt b/vector/src/main/java/im/vector/app/features/home/room/list/GroupRoomListSectionBuilder.kt index 4e6fe3ccee..e4bcc8ff0c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/GroupRoomListSectionBuilder.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/GroupRoomListSectionBuilder.kt @@ -52,7 +52,7 @@ class GroupRoomListSectionBuilder( when (mode) { RoomListDisplayMode.PEOPLE -> { - // 3 sections Invites / Fav / Dms + // 4 sections Invites / Fav / Dms / Low Priority buildPeopleSections(sections, activeGroupAwareQueries, actualGroupId) } RoomListDisplayMode.ROOMS -> { @@ -218,7 +218,19 @@ class GroupRoomListSectionBuilder( ) { it.memberships = listOf(Membership.JOIN) it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM - it.roomTagQueryFilter = RoomTagQueryFilter(false, null, null) + it.roomTagQueryFilter = RoomTagQueryFilter(false, false, null) + it.activeGroupId = actualGroupId + } + + addSection( + sections, + activeSpaceAwareQueries, + R.string.low_priority_header, + false + ) { + it.memberships = listOf(Membership.JOIN) + it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM + it.roomTagQueryFilter = RoomTagQueryFilter(false, true, null) it.activeGroupId = actualGroupId } } @@ -231,7 +243,6 @@ class GroupRoomListSectionBuilder( withQueryParams( { query.invoke(it) }, { roomQueryParams -> - val name = stringProvider.getString(nameRes) session.getFilteredPagedRoomSummariesLive(roomQueryParams) .also { diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/SpaceRoomListSectionBuilder.kt b/vector/src/main/java/im/vector/app/features/home/room/list/SpaceRoomListSectionBuilder.kt index a05e464ab1..725a62e7d5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/SpaceRoomListSectionBuilder.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/SpaceRoomListSectionBuilder.kt @@ -261,7 +261,8 @@ class SpaceRoomListSectionBuilder( private fun buildDmSections(sections: MutableList, activeSpaceAwareQueries: MutableList) { if (autoAcceptInvites.showInvites()) { - addSection(sections = sections, + addSection( + sections = sections, activeSpaceUpdaters = activeSpaceAwareQueries, nameRes = R.string.invitations_header, notifyOfLocalEcho = true, @@ -273,7 +274,8 @@ class SpaceRoomListSectionBuilder( } } - addSection(sections, + addSection( + sections, activeSpaceAwareQueries, R.string.bottom_action_favourites, false, @@ -284,7 +286,8 @@ class SpaceRoomListSectionBuilder( it.roomTagQueryFilter = RoomTagQueryFilter(true, null, null) } - addSection(sections, + addSection( + sections, activeSpaceAwareQueries, R.string.bottom_action_people_x, false, @@ -292,7 +295,19 @@ class SpaceRoomListSectionBuilder( ) { it.memberships = listOf(Membership.JOIN) it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM - it.roomTagQueryFilter = RoomTagQueryFilter(false, null, null) + it.roomTagQueryFilter = RoomTagQueryFilter(false, false, null) + } + + addSection( + sections, + activeSpaceAwareQueries, + R.string.low_priority_header, + false, + RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL + ) { + it.memberships = listOf(Membership.JOIN) + it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM + it.roomTagQueryFilter = RoomTagQueryFilter(false, true, null) } } From 40907a71b6c0c24fa474cd2a837f644849df4f7a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 19 Jul 2021 18:44:57 +0200 Subject: [PATCH 3/8] Cleanup --- .../api/session/room/RoomSummaryQueryParams.kt | 9 +-------- .../room/summary/RoomSummaryDataSource.kt | 18 +++++++++--------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomSummaryQueryParams.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomSummaryQueryParams.kt index 88ec2de768..b440857518 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomSummaryQueryParams.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomSummaryQueryParams.kt @@ -39,12 +39,6 @@ fun spaceSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) = .build() } -enum class RoomCategoryFilter { - ONLY_DM, - ONLY_ROOMS, - ALL -} - /** * This class can be used to filter room summaries to use with: * [org.matrix.android.sdk.api.session.room.Room] and [org.matrix.android.sdk.api.session.room.RoomService] @@ -59,11 +53,10 @@ data class RoomSummaryQueryParams( val excludeType: List?, val includeType: List?, val activeSpaceFilter: ActiveSpaceFilter?, - var activeGroupId: String? = null + val activeGroupId: String? = null ) { class Builder { - var roomId: QueryStringValue = QueryStringValue.IsNotEmpty var displayName: QueryStringValue = QueryStringValue.IsNotEmpty var canonicalAlias: QueryStringValue = QueryStringValue.NoCondition diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt index bff1af60ca..0b8c6df806 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt @@ -247,10 +247,10 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat queryParams.roomCategoryFilter?.let { when (it) { - RoomCategoryFilter.ONLY_DM -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, true) - RoomCategoryFilter.ONLY_ROOMS -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, false) + RoomCategoryFilter.ONLY_DM -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, true) + RoomCategoryFilter.ONLY_ROOMS -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, false) RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS -> query.greaterThan(RoomSummaryEntityFields.NOTIFICATION_COUNT, 0) - RoomCategoryFilter.ALL -> { + RoomCategoryFilter.ALL -> { // nop } } @@ -274,15 +274,15 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat query.equalTo(RoomSummaryEntityFields.ROOM_TYPE, it) } when (queryParams.roomCategoryFilter) { - RoomCategoryFilter.ONLY_DM -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, true) - RoomCategoryFilter.ONLY_ROOMS -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, false) + RoomCategoryFilter.ONLY_DM -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, true) + RoomCategoryFilter.ONLY_ROOMS -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, false) RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS -> query.greaterThan(RoomSummaryEntityFields.NOTIFICATION_COUNT, 0) - RoomCategoryFilter.ALL -> Unit // nop + RoomCategoryFilter.ALL -> Unit // nop } // Timber.w("VAL: activeSpaceId : ${queryParams.activeSpaceId}") when (queryParams.activeSpaceFilter) { - is ActiveSpaceFilter.ActiveSpace -> { + is ActiveSpaceFilter.ActiveSpace -> { // It's annoying but for now realm java does not support querying in primitive list :/ // https://github.com/realm/realm-java/issues/5361 if (queryParams.activeSpaceFilter.currentSpaceId == null) { @@ -300,8 +300,8 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat } } - if (queryParams.activeGroupId != null) { - query.contains(RoomSummaryEntityFields.GROUP_IDS, queryParams.activeGroupId!!) + queryParams.activeGroupId?.let { activeGroupId -> + query.contains(RoomSummaryEntityFields.GROUP_IDS, activeGroupId) } return query } From b8abe1b7adc6ea0e6c3ed7f9dc5d8062f7e68a73 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 19 Jul 2021 18:54:14 +0200 Subject: [PATCH 4/8] Rename class for code clarity --- ...omListSectionBuilder.kt => RoomListSectionBuilderGroup.kt} | 2 +- ...omListSectionBuilder.kt => RoomListSectionBuilderSpace.kt} | 2 +- .../vector/app/features/home/room/list/RoomListViewModel.kt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename vector/src/main/java/im/vector/app/features/home/room/list/{GroupRoomListSectionBuilder.kt => RoomListSectionBuilderGroup.kt} (99%) rename vector/src/main/java/im/vector/app/features/home/room/list/{SpaceRoomListSectionBuilder.kt => RoomListSectionBuilderSpace.kt} (99%) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/GroupRoomListSectionBuilder.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt similarity index 99% rename from vector/src/main/java/im/vector/app/features/home/room/list/GroupRoomListSectionBuilder.kt rename to vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt index e4bcc8ff0c..2ce18030e1 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/GroupRoomListSectionBuilder.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt @@ -35,7 +35,7 @@ import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.rx.asObservable -class GroupRoomListSectionBuilder( +class RoomListSectionBuilderGroup( val session: Session, val stringProvider: StringProvider, val viewModelScope: CoroutineScope, diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/SpaceRoomListSectionBuilder.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt similarity index 99% rename from vector/src/main/java/im/vector/app/features/home/room/list/SpaceRoomListSectionBuilder.kt rename to vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt index 725a62e7d5..ff34f57c1e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/SpaceRoomListSectionBuilder.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt @@ -46,7 +46,7 @@ import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount import org.matrix.android.sdk.rx.asObservable -class SpaceRoomListSectionBuilder( +class RoomListSectionBuilderSpace( val session: Session, val stringProvider: StringProvider, val appStateHandler: AppStateHandler, diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt index c5f166ea5b..0c4b9a9561 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt @@ -122,7 +122,7 @@ class RoomListViewModel @Inject constructor( val sections: List by lazy { if (appStateHandler.getCurrentRoomGroupingMethod() is RoomGroupingMethod.BySpace) { - SpaceRoomListSectionBuilder( + RoomListSectionBuilderSpace( session, stringProvider, appStateHandler, @@ -138,7 +138,7 @@ class RoomListViewModel @Inject constructor( vectorPreferences.labsSpacesOnlyOrphansInHome() ).buildSections(initialState.displayMode) } else { - GroupRoomListSectionBuilder( + RoomListSectionBuilderGroup( session, stringProvider, viewModelScope, From 14b4bff4771cb7ba6db0b1dad5a9b4c130262079 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 19 Jul 2021 18:56:15 +0200 Subject: [PATCH 5/8] Use the interface power! --- .../vector/app/features/home/room/list/RoomListViewModel.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt index 0c4b9a9561..f807b34889 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt @@ -136,7 +136,7 @@ class RoomListViewModel @Inject constructor( updatableQuery = it }, vectorPreferences.labsSpacesOnlyOrphansInHome() - ).buildSections(initialState.displayMode) + ) } else { RoomListSectionBuilderGroup( session, @@ -150,8 +150,9 @@ class RoomListViewModel @Inject constructor( { updatableQuery = it } - ).buildSections(initialState.displayMode) + ) } + .buildSections(initialState.displayMode) } override fun handle(action: RoomListAction) { From 5990e5a52b9d4f6d0bc8e2b9193eda7785fe0a40 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 19 Jul 2021 18:59:27 +0200 Subject: [PATCH 6/8] Cleanup constructors --- .../room/list/RoomListSectionBuilderGroup.kt | 12 +++++------- .../room/list/RoomListSectionBuilderSpace.kt | 18 +++++++++--------- .../home/room/list/RoomListViewModel.kt | 10 ++++------ 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt index 2ce18030e1..e43370c1af 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt @@ -26,7 +26,6 @@ import im.vector.app.features.invite.AutoAcceptInvites import im.vector.app.features.invite.showInvites import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers -import kotlinx.coroutines.CoroutineScope import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.query.RoomTagQueryFilter import org.matrix.android.sdk.api.session.Session @@ -36,13 +35,12 @@ import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.rx.asObservable class RoomListSectionBuilderGroup( - val session: Session, - val stringProvider: StringProvider, - val viewModelScope: CoroutineScope, - val appStateHandler: AppStateHandler, + private val session: Session, + private val stringProvider: StringProvider, + private val appStateHandler: AppStateHandler, private val autoAcceptInvites: AutoAcceptInvites, - val onDisposable: (Disposable) -> Unit, - val onUpdatable: (UpdatableLivePageResult) -> Unit + private val onDisposable: (Disposable) -> Unit, + private val onUpdatable: (UpdatableLivePageResult) -> Unit ) : RoomListSectionBuilder { override fun buildSections(mode: RoomListDisplayMode): List { diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt index ff34f57c1e..1e1134c284 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt @@ -47,18 +47,18 @@ import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotification import org.matrix.android.sdk.rx.asObservable class RoomListSectionBuilderSpace( - val session: Session, - val stringProvider: StringProvider, - val appStateHandler: AppStateHandler, - val viewModelScope: CoroutineScope, - private val suggestedRoomJoiningState: LiveData>>, + private val session: Session, + private val stringProvider: StringProvider, + private val appStateHandler: AppStateHandler, + private val viewModelScope: CoroutineScope, private val autoAcceptInvites: AutoAcceptInvites, - val onDisposable: (Disposable) -> Unit, - val onUpdatable: (UpdatableLivePageResult) -> Unit, - val onlyOrphansInHome: Boolean = false + private val onDisposable: (Disposable) -> Unit, + private val onUpdatable: (UpdatableLivePageResult) -> Unit, + private val suggestedRoomJoiningState: LiveData>>, + private val onlyOrphansInHome: Boolean = false ) : RoomListSectionBuilder { - val pagedListConfig = PagedList.Config.Builder() + private val pagedListConfig = PagedList.Config.Builder() .setPageSize(10) .setInitialLoadSizeHint(20) .setEnablePlaceholders(true) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt index f807b34889..e8e46acc2d 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt @@ -127,7 +127,6 @@ class RoomListViewModel @Inject constructor( stringProvider, appStateHandler, viewModelScope, - suggestedRoomJoiningState, autoAcceptInvites, { it.disposeOnClear() @@ -135,22 +134,21 @@ class RoomListViewModel @Inject constructor( { updatableQuery = it }, + suggestedRoomJoiningState, vectorPreferences.labsSpacesOnlyOrphansInHome() ) } else { RoomListSectionBuilderGroup( session, stringProvider, - viewModelScope, appStateHandler, autoAcceptInvites, { it.disposeOnClear() - }, - { - updatableQuery = it } - ) + ) { + updatableQuery = it + } } .buildSections(initialState.displayMode) } From ac2f1ee7fe20964509cd558f586a3b2d936ee599 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 19 Jul 2021 19:03:41 +0200 Subject: [PATCH 7/8] Cleanup and comment --- .../home/room/list/RoomListSectionBuilderGroup.kt | 3 +++ .../home/room/list/RoomListSectionBuilderSpace.kt | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt index e43370c1af..1ca379882c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt @@ -86,6 +86,7 @@ class RoomListSectionBuilderGroup( it.activeGroupId = actualGroupId } } + addSection( sections, activeGroupAwareQueries, @@ -111,6 +112,7 @@ class RoomListSectionBuilderGroup( }.also { onDisposable.invoke(it) } + return sections } @@ -257,6 +259,7 @@ class RoomListSectionBuilderGroup( }.also { onDisposable.invoke(it) } + sections.add( RoomsSection( sectionName = name, diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt index 1e1134c284..6edbb07992 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt @@ -70,12 +70,15 @@ class RoomListSectionBuilderSpace( val activeSpaceAwareQueries = mutableListOf() when (mode) { RoomListDisplayMode.PEOPLE -> { + // 4 sections Invites / Fav / Dms / Low Priority buildDmSections(sections, activeSpaceAwareQueries) } RoomListDisplayMode.ROOMS -> { + // 6 sections invites / Fav / Rooms / Low Priority / Server notice / Suggested rooms buildRoomsSections(sections, activeSpaceAwareQueries) } RoomListDisplayMode.FILTERED -> { + // Used when searching for rooms withQueryParams( { it.memberships = Membership.activeMemberships() @@ -140,7 +143,8 @@ class RoomListSectionBuilderSpace( return sections } - private fun buildRoomsSections(sections: MutableList, activeSpaceAwareQueries: MutableList) { + private fun buildRoomsSections(sections: MutableList, + activeSpaceAwareQueries: MutableList) { if (autoAcceptInvites.showInvites()) { addSection( sections = sections, @@ -259,7 +263,8 @@ class RoomListSectionBuilderSpace( ) } - private fun buildDmSections(sections: MutableList, activeSpaceAwareQueries: MutableList) { + private fun buildDmSections(sections: MutableList, + activeSpaceAwareQueries: MutableList) { if (autoAcceptInvites.showInvites()) { addSection( sections = sections, @@ -321,7 +326,6 @@ class RoomListSectionBuilderSpace( withQueryParams( { query.invoke(it) }, { roomQueryParams -> - val name = stringProvider.getString(nameRes) session.getFilteredPagedRoomSummariesLive( roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()), @@ -364,7 +368,6 @@ class RoomListSectionBuilderSpace( } }.livePagedList .let { livePagedList -> - // use it also as a source to update count livePagedList.asObservable() .observeOn(Schedulers.computation()) From 256df7e8699a84ee1973807d9d4de0fe0d9e9e1d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 19 Jul 2021 19:18:49 +0200 Subject: [PATCH 8/8] Rework on how we dispose the subscriptions --- .../home/room/list/RoomListSectionBuilder.kt | 2 + .../room/list/RoomListSectionBuilderGroup.kt | 13 ++-- .../room/list/RoomListSectionBuilderSpace.kt | 15 +++-- .../home/room/list/RoomListViewModel.kt | 60 +++++++++---------- 4 files changed, 51 insertions(+), 39 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilder.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilder.kt index 5267158000..019a6ceddf 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilder.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilder.kt @@ -20,4 +20,6 @@ import im.vector.app.features.home.RoomListDisplayMode interface RoomListSectionBuilder { fun buildSections(mode: RoomListDisplayMode) : List + + fun dispose() } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt index 1ca379882c..f101669af3 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt @@ -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 { val activeGroupAwareQueries = mutableListOf() val sections = mutableListOf() @@ -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() + } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt index 6edbb07992..13a6fc0d2d 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt @@ -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>>, 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() + } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt index e8e46acc2d..845be0b18b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt @@ -120,37 +120,32 @@ class RoomListViewModel @Inject constructor( } } - val sections: List 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 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() + } }