From 4ef0bc9052480fe1cc0db580b918ad6fda3989d1 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 24 Mar 2022 10:19:53 +0000 Subject: [PATCH 01/12] fixing wrong account created flag when creating a session from a direct login --- .../im/vector/app/features/onboarding/OnboardingViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt index 6659058b4e6..64fa3f0eee0 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt @@ -578,7 +578,7 @@ class OnboardingViewModel @AssistedInject constructor( onDirectLoginError(failure) return } - onSessionCreated(data, isAccountCreated = true) + onSessionCreated(data, isAccountCreated = false) } private fun onDirectLoginError(failure: Throwable) { From 1a0bd3f31eb932ce45548d81a009935039f36f08 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Thu, 24 Mar 2022 15:27:35 +0100 Subject: [PATCH 02/12] Revert "Revert "Do not suggest collapse if there is only one section"" This reverts commit 55b1a60f96e58491ae9c31f7b8453c951a940559. --- .../features/home/room/list/RoomListFragment.kt | 14 +++++++++++--- .../home/room/list/SectionHeaderAdapter.kt | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index 4265eebe627..a8f1174283e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -295,7 +295,8 @@ class RoomListFragment @Inject constructor( section.notificationCount.observe(viewLifecycleOwner) { counts -> sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy( notificationCount = counts.totalCount, - isHighlighted = counts.isHighlight + isHighlighted = counts.isHighlight, + shouldShowExpandedArrow = shouldShowExpendedArrow() )) } section.isExpanded.observe(viewLifecycleOwner) { _ -> @@ -329,14 +330,17 @@ class RoomListFragment @Inject constructor( controller.setData(list) sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy( isHidden = list.isEmpty(), - isLoading = false)) + isLoading = false, + shouldShowExpandedArrow = shouldShowExpendedArrow() + )) checkEmptyState() } observeItemCount(section, sectionAdapter) section.notificationCount.observe(viewLifecycleOwner) { counts -> sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy( notificationCount = counts.totalCount, - isHighlighted = counts.isHighlight + isHighlighted = counts.isHighlight, + shouldShowExpandedArrow = shouldShowExpendedArrow() )) } section.isExpanded.observe(viewLifecycleOwner) { _ -> @@ -444,6 +448,10 @@ class RoomListFragment @Inject constructor( footerController.setData(state) } + private fun shouldShowExpendedArrow(): Boolean { + return adapterInfosList.filter { !it.sectionHeaderAdapter.roomsSectionData.isHidden }.size >= 2 + } + private fun checkEmptyState() { val shouldShowEmpty = adapterInfosList.all { it.sectionHeaderAdapter.roomsSectionData.isHidden } && !adapterInfosList.any { it.sectionHeaderAdapter.roomsSectionData.isLoading } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt b/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt index 2e6436d21d4..cd2879cf28b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt @@ -17,6 +17,7 @@ package im.vector.app.features.home.room.list import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup import androidx.core.content.ContextCompat import androidx.core.graphics.drawable.DrawableCompat @@ -39,7 +40,8 @@ class SectionHeaderAdapter constructor( val isHighlighted: Boolean = false, val isHidden: Boolean = true, // This will be false until real data has been submitted once - val isLoading: Boolean = true + val isLoading: Boolean = true, + val shouldShowExpandedArrow: Boolean = false ) lateinit var roomsSectionData: RoomsSectionData @@ -82,11 +84,16 @@ class SectionHeaderAdapter constructor( fun bind(roomsSectionData: RoomsSectionData) { binding.roomCategoryTitleView.text = roomsSectionData.name val tintColor = ThemeUtils.getColor(binding.root.context, R.attr.vctr_content_secondary) - val expandedArrowDrawableRes = if (roomsSectionData.isExpanded) R.drawable.ic_expand_more else R.drawable.ic_expand_less - val expandedArrowDrawable = ContextCompat.getDrawable(binding.root.context, expandedArrowDrawableRes)?.also { - DrawableCompat.setTint(it, tintColor) + if (roomsSectionData.shouldShowExpandedArrow) { + binding.roomCategoryCounterView.visibility = View.VISIBLE + val expandedArrowDrawableRes = if (roomsSectionData.isExpanded) R.drawable.ic_expand_more else R.drawable.ic_expand_less + val expandedArrowDrawable = ContextCompat.getDrawable(binding.root.context, expandedArrowDrawableRes)?.also { + DrawableCompat.setTint(it, tintColor) + } + binding.roomCategoryCounterView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null) + } else { + binding.roomCategoryCounterView.visibility = View.GONE } - binding.roomCategoryCounterView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null) binding.roomCategoryCounterView.text = roomsSectionData.itemCount.takeIf { it > 0 }?.toString().orEmpty() binding.roomCategoryUnreadCounterBadgeView.render(UnreadCounterBadgeView.State(roomsSectionData.notificationCount, roomsSectionData.isHighlighted)) } From 70e5698082ba472e9c104b19e3802c67c039f82f Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 24 Mar 2022 15:41:35 +0100 Subject: [PATCH 03/12] Update versions to 1.4.7 --- matrix-sdk-android/build.gradle | 2 +- vector/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 2b2c38e22ac..a26a709afc4 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -31,7 +31,7 @@ android { // that the app's state is completely cleared between tests. testInstrumentationRunnerArguments clearPackageData: 'true' - buildConfigField "String", "SDK_VERSION", "\"1.4.6\"" + buildConfigField "String", "SDK_VERSION", "\"1.4.7\"" buildConfigField "String", "GIT_SDK_REVISION", "\"${gitRevision()}\"" buildConfigField "String", "GIT_SDK_REVISION_UNIX_DATE", "\"${gitRevisionUnixDate()}\"" diff --git a/vector/build.gradle b/vector/build.gradle index aeaad19e026..f58b7d444d4 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -18,7 +18,7 @@ ext.versionMinor = 4 // Note: even values are reserved for regular release, odd values for hotfix release. // When creating a hotfix, you should decrease the value, since the current value // is the value for the next regular release. -ext.versionPatch = 6 +ext.versionPatch = 7 static def getGitTimestamp() { def cmd = 'git show -s --format=%ct' From 745382cdfad3105e4bc473cbc7e3cc116eeebf9a Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 24 Mar 2022 15:41:42 +0100 Subject: [PATCH 04/12] RoomList : avoid using flow extension on realm results (leads to frozen object and leaks). --- .../sdk/api/session/room/RoomService.kt | 4 ++-- .../session/room/DefaultRoomService.kt | 4 ++-- .../room/summary/RoomSummaryDataSource.kt | 22 +++++++------------ .../room/list/RoomListSectionBuilderGroup.kt | 4 ++-- .../room/list/RoomListSectionBuilderSpace.kt | 4 ++-- .../spaces/manage/SpaceAddRoomsViewModel.kt | 6 ++--- 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt index f506b147df7..c2f8e6d0bee 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt @@ -218,9 +218,9 @@ interface RoomService { sortOrder: RoomSortOrder = RoomSortOrder.ACTIVITY): UpdatableLivePageResult /** - * Retrieve a flow on the number of rooms. + * Retrieve a LiveData on the number of rooms. */ - fun getRoomCountFlow(queryParams: RoomSummaryQueryParams): Flow + fun getRoomCountLive(queryParams: RoomSummaryQueryParams): LiveData /** * TODO Doc diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt index 0d78489fbda..28696285769 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt @@ -110,8 +110,8 @@ internal class DefaultRoomService @Inject constructor( return roomSummaryDataSource.getUpdatablePagedRoomSummariesLive(queryParams, pagedListConfig, sortOrder) } - override fun getRoomCountFlow(queryParams: RoomSummaryQueryParams): Flow { - return roomSummaryDataSource.getCountFlow(queryParams) + override fun getRoomCountLive(queryParams: RoomSummaryQueryParams): LiveData { + return roomSummaryDataSource.getCountLive(queryParams) } override fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams): RoomAggregateNotificationCount { 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 ea4f102fa57..f69fdb37c73 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 @@ -25,12 +25,7 @@ import androidx.paging.PagedList import com.zhuinden.monarchy.Monarchy import io.realm.Realm import io.realm.RealmQuery -import io.realm.kotlin.toFlow import io.realm.kotlin.where -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.distinctUntilChanged -import kotlinx.coroutines.flow.flowOn -import kotlinx.coroutines.flow.map import org.matrix.android.sdk.api.MatrixCoroutineDispatchers import org.matrix.android.sdk.api.query.ActiveSpaceFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter @@ -241,15 +236,14 @@ internal class RoomSummaryDataSource @Inject constructor( } } - fun getCountFlow(queryParams: RoomSummaryQueryParams): Flow = - realmSessionProvider - .withRealm { realm -> roomSummariesQuery(realm, queryParams).findAllAsync() } - .toFlow() - // need to create the flow on a context dispatcher with a thread with attached Looper - .flowOn(coroutineDispatchers.main) - .map { it.size } - .flowOn(coroutineDispatchers.io) - .distinctUntilChanged() + fun getCountLive(queryParams: RoomSummaryQueryParams): LiveData { + val liveRooms = monarchy.findAllManagedWithChanges { + roomSummariesQuery(it, queryParams) + } + return Transformations.map(liveRooms) { + it.realmResults.count() + } + } fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams): RoomAggregateNotificationCount { var notificationCount: RoomAggregateNotificationCount? = null 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 ec7915ba342..d687c68092c 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 @@ -75,7 +75,7 @@ class RoomListSectionBuilderGroup( onUpdatable(updatableFilterLivePageResult) val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() - .flatMapLatest { session.getRoomCountFlow(updatableFilterLivePageResult.queryParams) } + .flatMapLatest { session.getRoomCountLive(updatableFilterLivePageResult.queryParams).asFlow() } .distinctUntilChanged() sections.add( @@ -276,7 +276,7 @@ class RoomListSectionBuilderGroup( sectionName = name, livePages = livePagedList, notifyOfLocalEcho = notifyOfLocalEcho, - itemCount = session.getRoomCountFlow(roomQueryParams) + itemCount = session.getRoomCountLive(roomQueryParams).asFlow() ) ) } 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 f82dbd43e13..3e21b0f58f0 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 @@ -94,7 +94,7 @@ class RoomListSectionBuilderSpace( onUpdatable(updatableFilterLivePageResult) val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() - .flatMapLatest { session.getRoomCountFlow(updatableFilterLivePageResult.queryParams) } + .flatMapLatest { session.getRoomCountLive(updatableFilterLivePageResult.queryParams).asFlow() } .distinctUntilChanged() sections.add( @@ -400,7 +400,7 @@ class RoomListSectionBuilderSpace( val itemCountFlow = livePagedList.asFlow() .flatMapLatest { val queryParams = roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()) - session.getRoomCountFlow(queryParams) + session.getRoomCountLive(queryParams).asFlow() } .distinctUntilChanged() diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt index 7d99c53f230..318f701985b 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt @@ -84,7 +84,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor( val spaceCountFlow: Flow by lazy { spaceUpdatableLivePageResult.livePagedList.asFlow() - .flatMapLatest { session.getRoomCountFlow(spaceUpdatableLivePageResult.queryParams) } + .flatMapLatest { session.getRoomCountLive(spaceUpdatableLivePageResult.queryParams).asFlow() } .distinctUntilChanged() } @@ -110,7 +110,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor( val roomCountFlow: Flow by lazy { roomUpdatableLivePageResult.livePagedList.asFlow() - .flatMapLatest { session.getRoomCountFlow(roomUpdatableLivePageResult.queryParams) } + .flatMapLatest { session.getRoomCountLive(roomUpdatableLivePageResult.queryParams).asFlow() } .distinctUntilChanged() } @@ -136,7 +136,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor( val dmCountFlow: Flow by lazy { dmUpdatableLivePageResult.livePagedList.asFlow() - .flatMapLatest { session.getRoomCountFlow(dmUpdatableLivePageResult.queryParams) } + .flatMapLatest { session.getRoomCountLive(dmUpdatableLivePageResult.queryParams).asFlow() } .distinctUntilChanged() } From a362d5427d7fd28fb4aca37366ed05d1350ecf7e Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Wed, 23 Mar 2022 15:18:13 +0100 Subject: [PATCH 05/12] Fix arrow visibility on section header --- .../home/room/list/RoomListFragment.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index a8f1174283e..9ed170f7c52 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -148,9 +148,10 @@ class RoomListFragment @Inject constructor( } private fun refreshCollapseStates() { + val sectionsCount = adapterInfosList.count { !it.sectionHeaderAdapter.roomsSectionData.isHidden } roomListViewModel.sections.forEachIndexed { index, roomsSection -> val actualBlock = adapterInfosList[index] - val isRoomSectionExpanded = roomsSection.isExpanded.value.orTrue() + val isRoomSectionExpanded = roomsSection.isExpanded.value.orTrue() || sectionsCount == 1 if (actualBlock.section.isExpanded && !isRoomSectionExpanded) { // mark controller as collapsed actualBlock.contentEpoxyController.setCollapsed(true) @@ -162,7 +163,10 @@ class RoomListFragment @Inject constructor( isExpanded = isRoomSectionExpanded ) actualBlock.sectionHeaderAdapter.updateSection( - actualBlock.sectionHeaderAdapter.roomsSectionData.copy(isExpanded = isRoomSectionExpanded) + actualBlock.sectionHeaderAdapter.roomsSectionData.copy( + isExpanded = isRoomSectionExpanded, + shouldShowExpandedArrow = sectionsCount > 1 + ) ) } } @@ -289,6 +293,7 @@ class RoomListFragment @Inject constructor( isHidden = pl.isEmpty(), isLoading = false )) + refreshCollapseStates() checkEmptyState() } observeItemCount(section, sectionAdapter) @@ -296,7 +301,6 @@ class RoomListFragment @Inject constructor( sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy( notificationCount = counts.totalCount, isHighlighted = counts.isHighlight, - shouldShowExpandedArrow = shouldShowExpendedArrow() )) } section.isExpanded.observe(viewLifecycleOwner) { _ -> @@ -314,6 +318,7 @@ class RoomListFragment @Inject constructor( isHidden = info.rooms.isEmpty(), isLoading = false )) + refreshCollapseStates() checkEmptyState() } observeItemCount(section, sectionAdapter) @@ -331,16 +336,15 @@ class RoomListFragment @Inject constructor( sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy( isHidden = list.isEmpty(), isLoading = false, - shouldShowExpandedArrow = shouldShowExpendedArrow() )) + refreshCollapseStates() checkEmptyState() } observeItemCount(section, sectionAdapter) section.notificationCount.observe(viewLifecycleOwner) { counts -> sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy( notificationCount = counts.totalCount, - isHighlighted = counts.isHighlight, - shouldShowExpandedArrow = shouldShowExpendedArrow() + isHighlighted = counts.isHighlight )) } section.isExpanded.observe(viewLifecycleOwner) { _ -> @@ -448,10 +452,6 @@ class RoomListFragment @Inject constructor( footerController.setData(state) } - private fun shouldShowExpendedArrow(): Boolean { - return adapterInfosList.filter { !it.sectionHeaderAdapter.roomsSectionData.isHidden }.size >= 2 - } - private fun checkEmptyState() { val shouldShowEmpty = adapterInfosList.all { it.sectionHeaderAdapter.roomsSectionData.isHidden } && !adapterInfosList.any { it.sectionHeaderAdapter.roomsSectionData.isLoading } From a97d3eae7ee19ab3c083bc457c7d5751c78f448c Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Thu, 24 Mar 2022 11:58:17 +0100 Subject: [PATCH 06/12] Pass lambda to updateSection method --- .../home/room/list/RoomListFragment.kt | 74 ++++++++++--------- .../home/room/list/SectionHeaderAdapter.kt | 8 +- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index 9ed170f7c52..d92fc0403f7 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -162,12 +162,12 @@ class RoomListFragment @Inject constructor( actualBlock.section = actualBlock.section.copy( isExpanded = isRoomSectionExpanded ) - actualBlock.sectionHeaderAdapter.updateSection( - actualBlock.sectionHeaderAdapter.roomsSectionData.copy( - isExpanded = isRoomSectionExpanded, - shouldShowExpandedArrow = sectionsCount > 1 - ) - ) + actualBlock.sectionHeaderAdapter.updateSection { + it.copy( + isExpanded = isRoomSectionExpanded, + shouldShowExpandedArrow = sectionsCount > 1 + ) + } } } @@ -276,32 +276,34 @@ class RoomListFragment @Inject constructor( val concatAdapter = ConcatAdapter() roomListViewModel.sections.forEach { section -> - val sectionAdapter = SectionHeaderAdapter { + val sectionAdapter = SectionHeaderAdapter(SectionHeaderAdapter.RoomsSectionData(section.sectionName)) { roomListViewModel.handle(RoomListAction.ToggleSection(section)) - }.also { - it.updateSection(SectionHeaderAdapter.RoomsSectionData(section.sectionName)) } val contentAdapter = when { - section.livePages != null -> { + section.livePages != null -> { pagedControllerFactory.createRoomSummaryPagedController() .also { controller -> section.livePages.observe(viewLifecycleOwner) { pl -> controller.submitList(pl) - sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy( - isHidden = pl.isEmpty(), - isLoading = false - )) + sectionAdapter.updateSection { + it.copy( + isHidden = pl.isEmpty(), + isLoading = false + ) + } refreshCollapseStates() checkEmptyState() } observeItemCount(section, sectionAdapter) section.notificationCount.observe(viewLifecycleOwner) { counts -> - sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy( - notificationCount = counts.totalCount, - isHighlighted = counts.isHighlight, - )) + sectionAdapter.updateSection { + it.copy( + notificationCount = counts.totalCount, + isHighlighted = counts.isHighlight, + ) + } } section.isExpanded.observe(viewLifecycleOwner) { _ -> refreshCollapseStates() @@ -314,10 +316,12 @@ class RoomListFragment @Inject constructor( .also { controller -> section.liveSuggested.observe(viewLifecycleOwner) { info -> controller.setData(info) - sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy( - isHidden = info.rooms.isEmpty(), - isLoading = false - )) + sectionAdapter.updateSection { + it.copy( + isHidden = info.rooms.isEmpty(), + isLoading = false + ) + } refreshCollapseStates() checkEmptyState() } @@ -333,19 +337,23 @@ class RoomListFragment @Inject constructor( .also { controller -> section.liveList?.observe(viewLifecycleOwner) { list -> controller.setData(list) - sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy( - isHidden = list.isEmpty(), - isLoading = false, - )) + sectionAdapter.updateSection { + it.copy( + isHidden = list.isEmpty(), + isLoading = false, + ) + } refreshCollapseStates() checkEmptyState() } observeItemCount(section, sectionAdapter) section.notificationCount.observe(viewLifecycleOwner) { counts -> - sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy( - notificationCount = counts.totalCount, - isHighlighted = counts.isHighlight - )) + sectionAdapter.updateSection { + it.copy( + notificationCount = counts.totalCount, + isHighlighted = counts.isHighlight + ) + } } section.isExpanded.observe(viewLifecycleOwner) { _ -> refreshCollapseStates() @@ -393,9 +401,9 @@ class RoomListFragment @Inject constructor( section.itemCount .flowWithLifecycle(lifecycle, Lifecycle.State.STARTED) .collect { count -> - sectionAdapter.updateSection( - sectionAdapter.roomsSectionData.copy(itemCount = count) - ) + sectionAdapter.updateSection { + it.copy(itemCount = count) + } } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt b/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt index cd2879cf28b..0267151bd18 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt @@ -29,6 +29,7 @@ import im.vector.app.databinding.ItemRoomCategoryBinding import im.vector.app.features.themes.ThemeUtils class SectionHeaderAdapter constructor( + roomsSectionData: RoomsSectionData, private val onClickAction: ClickListener ) : RecyclerView.Adapter() { @@ -44,11 +45,12 @@ class SectionHeaderAdapter constructor( val shouldShowExpandedArrow: Boolean = false ) - lateinit var roomsSectionData: RoomsSectionData + var roomsSectionData: RoomsSectionData = roomsSectionData private set - fun updateSection(newRoomsSectionData: RoomsSectionData) { - if (!::roomsSectionData.isInitialized || newRoomsSectionData != roomsSectionData) { + fun updateSection(block: (RoomsSectionData) -> RoomsSectionData) { + val newRoomsSectionData = block(roomsSectionData) + if (roomsSectionData != newRoomsSectionData) { roomsSectionData = newRoomsSectionData notifyDataSetChanged() } From 1ef1bd81bcec155126865d132d4b89e9a248fab5 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Thu, 24 Mar 2022 14:35:40 +0100 Subject: [PATCH 07/12] Improve room section collapsing --- .../home/room/list/RoomListFragment.kt | 21 ++++++++++++------- .../home/room/list/SectionHeaderAdapter.kt | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index d92fc0403f7..1ae4bc135bc 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -151,7 +151,8 @@ class RoomListFragment @Inject constructor( val sectionsCount = adapterInfosList.count { !it.sectionHeaderAdapter.roomsSectionData.isHidden } roomListViewModel.sections.forEachIndexed { index, roomsSection -> val actualBlock = adapterInfosList[index] - val isRoomSectionExpanded = roomsSection.isExpanded.value.orTrue() || sectionsCount == 1 + val isRoomSectionCollapsable = sectionsCount > 1 + val isRoomSectionExpanded = roomsSection.isExpanded.value.orTrue() if (actualBlock.section.isExpanded && !isRoomSectionExpanded) { // mark controller as collapsed actualBlock.contentEpoxyController.setCollapsed(true) @@ -159,15 +160,18 @@ class RoomListFragment @Inject constructor( // we must expand! actualBlock.contentEpoxyController.setCollapsed(false) } - actualBlock.section = actualBlock.section.copy( - isExpanded = isRoomSectionExpanded - ) + actualBlock.section = actualBlock.section.copy(isExpanded = isRoomSectionExpanded) actualBlock.sectionHeaderAdapter.updateSection { it.copy( isExpanded = isRoomSectionExpanded, - shouldShowExpandedArrow = sectionsCount > 1 + isCollapsable = isRoomSectionCollapsable ) } + + if (!isRoomSectionExpanded && !isRoomSectionCollapsable) { + // force expand if the section is not collapsable + roomListViewModel.handle(RoomListAction.ToggleSection(roomsSection)) + } } } @@ -275,11 +279,12 @@ class RoomListFragment @Inject constructor( val concatAdapter = ConcatAdapter() - roomListViewModel.sections.forEach { section -> + roomListViewModel.sections.forEachIndexed { index, section -> val sectionAdapter = SectionHeaderAdapter(SectionHeaderAdapter.RoomsSectionData(section.sectionName)) { - roomListViewModel.handle(RoomListAction.ToggleSection(section)) + if (adapterInfosList[index].sectionHeaderAdapter.roomsSectionData.isCollapsable) { + roomListViewModel.handle(RoomListAction.ToggleSection(section)) + } } - val contentAdapter = when { section.livePages != null -> { diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt b/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt index 0267151bd18..7633bc0d2a1 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt @@ -42,7 +42,7 @@ class SectionHeaderAdapter constructor( val isHidden: Boolean = true, // This will be false until real data has been submitted once val isLoading: Boolean = true, - val shouldShowExpandedArrow: Boolean = false + val isCollapsable: Boolean = false ) var roomsSectionData: RoomsSectionData = roomsSectionData @@ -86,7 +86,7 @@ class SectionHeaderAdapter constructor( fun bind(roomsSectionData: RoomsSectionData) { binding.roomCategoryTitleView.text = roomsSectionData.name val tintColor = ThemeUtils.getColor(binding.root.context, R.attr.vctr_content_secondary) - if (roomsSectionData.shouldShowExpandedArrow) { + if (roomsSectionData.isCollapsable) { binding.roomCategoryCounterView.visibility = View.VISIBLE val expandedArrowDrawableRes = if (roomsSectionData.isExpanded) R.drawable.ic_expand_more else R.drawable.ic_expand_less val expandedArrowDrawable = ContextCompat.getDrawable(binding.root.context, expandedArrowDrawableRes)?.also { From 3c73ccce7b22f6489c06f014ed2f07e97b5de077 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Thu, 24 Mar 2022 14:43:25 +0100 Subject: [PATCH 08/12] Add changelog entry --- changelog.d/5616.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5616.bugfix diff --git a/changelog.d/5616.bugfix b/changelog.d/5616.bugfix new file mode 100644 index 00000000000..5bec45854df --- /dev/null +++ b/changelog.d/5616.bugfix @@ -0,0 +1 @@ +Fix inconsistencies between the arrow visibility and the collapse action on the room sections \ No newline at end of file From 87438085c66483c5858f2c78b2bbf24a0f9a2477 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 24 Mar 2022 18:49:57 +0100 Subject: [PATCH 09/12] RoomList: fix count not showing if not collapsable --- .../features/home/room/list/SectionHeaderAdapter.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt b/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt index 7633bc0d2a1..3f1dfebf7b6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/SectionHeaderAdapter.kt @@ -16,8 +16,8 @@ package im.vector.app.features.home.room.list +import android.graphics.drawable.Drawable import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import androidx.core.content.ContextCompat import androidx.core.graphics.drawable.DrawableCompat @@ -86,16 +86,16 @@ class SectionHeaderAdapter constructor( fun bind(roomsSectionData: RoomsSectionData) { binding.roomCategoryTitleView.text = roomsSectionData.name val tintColor = ThemeUtils.getColor(binding.root.context, R.attr.vctr_content_secondary) - if (roomsSectionData.isCollapsable) { - binding.roomCategoryCounterView.visibility = View.VISIBLE + val collapsableArrowDrawable: Drawable? = if (roomsSectionData.isCollapsable) { val expandedArrowDrawableRes = if (roomsSectionData.isExpanded) R.drawable.ic_expand_more else R.drawable.ic_expand_less - val expandedArrowDrawable = ContextCompat.getDrawable(binding.root.context, expandedArrowDrawableRes)?.also { + ContextCompat.getDrawable(binding.root.context, expandedArrowDrawableRes)?.also { DrawableCompat.setTint(it, tintColor) } - binding.roomCategoryCounterView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null) } else { - binding.roomCategoryCounterView.visibility = View.GONE + null } + binding.root.isClickable = roomsSectionData.isCollapsable + binding.roomCategoryCounterView.setCompoundDrawablesWithIntrinsicBounds(null, null, collapsableArrowDrawable, null) binding.roomCategoryCounterView.text = roomsSectionData.itemCount.takeIf { it > 0 }?.toString().orEmpty() binding.roomCategoryUnreadCounterBadgeView.render(UnreadCounterBadgeView.State(roomsSectionData.notificationCount, roomsSectionData.isHighlighted)) } From 04b136e3e4bccdc5b5ebbd026bc39d14545ac84d Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 24 Mar 2022 18:50:33 +0100 Subject: [PATCH 10/12] RoomList: more fixes on count --- .../sdk/api/session/room/RoomService.kt | 4 +- .../session/room/DefaultRoomService.kt | 1 - .../room/summary/RoomSummaryDataSource.kt | 2 +- .../home/room/list/RoomListFragment.kt | 4 +- .../room/list/RoomListSectionBuilderGroup.kt | 80 +++--- .../room/list/RoomListSectionBuilderSpace.kt | 262 +++++++++--------- 6 files changed, 178 insertions(+), 175 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt index c2f8e6d0bee..aec358218b4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt @@ -18,7 +18,6 @@ package org.matrix.android.sdk.api.session.room import androidx.lifecycle.LiveData import androidx.paging.PagedList -import kotlinx.coroutines.flow.Flow import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState import org.matrix.android.sdk.api.session.room.model.Membership @@ -218,7 +217,8 @@ interface RoomService { sortOrder: RoomSortOrder = RoomSortOrder.ACTIVITY): UpdatableLivePageResult /** - * Retrieve a LiveData on the number of rooms. + * Return a LiveData on the number of rooms + * @param queryParams parameters to query the room summaries. It can be use to keep only joined rooms, for instance. */ fun getRoomCountLive(queryParams: RoomSummaryQueryParams): LiveData diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt index 28696285769..1bc98015aa9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt @@ -20,7 +20,6 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.Transformations import androidx.paging.PagedList import com.zhuinden.monarchy.Monarchy -import kotlinx.coroutines.flow.Flow import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.room.Room import org.matrix.android.sdk.api.session.room.RoomService 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 f69fdb37c73..1925fe8e9f8 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 @@ -241,7 +241,7 @@ internal class RoomSummaryDataSource @Inject constructor( roomSummariesQuery(it, queryParams) } return Transformations.map(liveRooms) { - it.realmResults.count() + it.realmResults.where().count().toInt() } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index 1ae4bc135bc..67d7a732cc6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -53,6 +53,7 @@ import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedA import im.vector.app.features.home.room.list.widget.NotifsFabMenuView import im.vector.app.features.notifications.NotificationDrawerManager import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch @@ -287,7 +288,7 @@ class RoomListFragment @Inject constructor( } val contentAdapter = when { - section.livePages != null -> { + section.livePages != null -> { pagedControllerFactory.createRoomSummaryPagedController() .also { controller -> section.livePages.observe(viewLifecycleOwner) { pl -> @@ -405,6 +406,7 @@ class RoomListFragment @Inject constructor( lifecycleScope.launch { section.itemCount .flowWithLifecycle(lifecycle, Lifecycle.State.STARTED) + .filter { it > 0 } .collect { count -> sectionAdapter.updateSection { it.copy(itemCount = count) 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 d687c68092c..bd43a83f2c4 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 @@ -70,22 +70,20 @@ class RoomListSectionBuilderGroup( }, { qpm -> val name = stringProvider.getString(R.string.bottom_action_rooms) - session.getFilteredPagedRoomSummariesLive(qpm) - .let { updatableFilterLivePageResult -> - onUpdatable(updatableFilterLivePageResult) + val updatableFilterLivePageResult = session.getFilteredPagedRoomSummariesLive(qpm) + onUpdatable(updatableFilterLivePageResult) - val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() - .flatMapLatest { session.getRoomCountLive(updatableFilterLivePageResult.queryParams).asFlow() } - .distinctUntilChanged() + val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() + .flatMapLatest { session.getRoomCountLive(updatableFilterLivePageResult.queryParams).asFlow() } + .distinctUntilChanged() - sections.add( - RoomsSection( - sectionName = name, - livePages = updatableFilterLivePageResult.livePagedList, - itemCount = itemCountFlow - ) - ) - } + sections.add( + RoomsSection( + sectionName = name, + livePages = updatableFilterLivePageResult.livePagedList, + itemCount = itemCountFlow + ) + ) } ) } @@ -252,37 +250,33 @@ class RoomListSectionBuilderGroup( @StringRes nameRes: Int, notifyOfLocalEcho: Boolean = false, query: (RoomSummaryQueryParams.Builder) -> Unit) { - withQueryParams( - { query.invoke(it) }, - { roomQueryParams -> - val name = stringProvider.getString(nameRes) - session.getFilteredPagedRoomSummariesLive(roomQueryParams) - .also { - activeSpaceUpdaters.add(it) - }.livePagedList - .let { livePagedList -> - // use it also as a source to update count - livePagedList.asFlow() - .onEach { - sections.find { it.sectionName == name } - ?.notificationCount - ?.postValue(session.getNotificationCountForRooms(roomQueryParams)) - } - .flowOn(Dispatchers.Default) - .launchIn(coroutineScope) + withQueryParams(query) { roomQueryParams -> + val name = stringProvider.getString(nameRes) + session.getFilteredPagedRoomSummariesLive(roomQueryParams) + .also { + activeSpaceUpdaters.add(it) + }.livePagedList + .let { livePagedList -> + // use it also as a source to update count + livePagedList.asFlow() + .onEach { + sections.find { it.sectionName == name } + ?.notificationCount + ?.postValue(session.getNotificationCountForRooms(roomQueryParams)) + } + .flowOn(Dispatchers.Default) + .launchIn(coroutineScope) - sections.add( - RoomsSection( - sectionName = name, - livePages = livePagedList, - notifyOfLocalEcho = notifyOfLocalEcho, - itemCount = session.getRoomCountLive(roomQueryParams).asFlow() - ) + sections.add( + RoomsSection( + sectionName = name, + livePages = livePagedList, + notifyOfLocalEcho = notifyOfLocalEcho, + itemCount = session.getRoomCountLive(roomQueryParams).asFlow() ) - } - } - - ) + ) + } + } } private fun withQueryParams(builder: (RoomSummaryQueryParams.Builder) -> Unit, block: (RoomSummaryQueryParams) -> Unit) { 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 3e21b0f58f0..262df2784a8 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 @@ -32,6 +32,7 @@ import im.vector.app.features.invite.showInvites import im.vector.app.space import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flatMapLatest @@ -40,6 +41,7 @@ import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.update import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.query.ActiveSpaceFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter @@ -83,64 +85,10 @@ class RoomListSectionBuilderSpace( } RoomListDisplayMode.FILTERED -> { // Used when searching for rooms - withQueryParams( - { - it.memberships = Membership.activeMemberships() - }, - { qpm -> - val name = stringProvider.getString(R.string.bottom_action_rooms) - session.getFilteredPagedRoomSummariesLive(qpm) - .let { updatableFilterLivePageResult -> - onUpdatable(updatableFilterLivePageResult) - - val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() - .flatMapLatest { session.getRoomCountLive(updatableFilterLivePageResult.queryParams).asFlow() } - .distinctUntilChanged() - - sections.add( - RoomsSection( - sectionName = name, - livePages = updatableFilterLivePageResult.livePagedList, - itemCount = itemCountFlow - ) - ) - } - } - ) + buildFilteredSection(sections) } RoomListDisplayMode.NOTIFICATIONS -> { - if (autoAcceptInvites.showInvites()) { - addSection( - sections = sections, - activeSpaceUpdaters = activeSpaceAwareQueries, - nameRes = R.string.invitations_header, - notifyOfLocalEcho = true, - spaceFilterStrategy = if (onlyOrphansInHome) { - RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL - } else { - RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL - }, - countRoomAsNotif = true - ) { - it.memberships = listOf(Membership.INVITE) - it.roomCategoryFilter = RoomCategoryFilter.ALL - } - } - - addSection( - sections = sections, - activeSpaceUpdaters = activeSpaceAwareQueries, - nameRes = R.string.bottom_action_rooms, - notifyOfLocalEcho = false, - spaceFilterStrategy = if (onlyOrphansInHome) { - RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL - } else { - RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL - } - ) { - it.memberships = listOf(Membership.JOIN) - it.roomCategoryFilter = RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS - } + buildNotificationsSection(sections, activeSpaceAwareQueries) } } @@ -332,6 +280,67 @@ class RoomListSectionBuilderSpace( } } + private fun buildNotificationsSection(sections: MutableList, activeSpaceAwareQueries: MutableList) { + if (autoAcceptInvites.showInvites()) { + addSection( + sections = sections, + activeSpaceUpdaters = activeSpaceAwareQueries, + nameRes = R.string.invitations_header, + notifyOfLocalEcho = true, + spaceFilterStrategy = if (onlyOrphansInHome) { + RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL + } else { + RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL + }, + countRoomAsNotif = true + ) { + it.memberships = listOf(Membership.INVITE) + it.roomCategoryFilter = RoomCategoryFilter.ALL + } + } + + addSection( + sections = sections, + activeSpaceUpdaters = activeSpaceAwareQueries, + nameRes = R.string.bottom_action_rooms, + notifyOfLocalEcho = false, + spaceFilterStrategy = if (onlyOrphansInHome) { + RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL + } else { + RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL + } + ) { + it.memberships = listOf(Membership.JOIN) + it.roomCategoryFilter = RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS + } + } + + private fun buildFilteredSection(sections: MutableList) { + // Used when searching for rooms + withQueryParams( + { + it.memberships = Membership.activeMemberships() + }, + { qpm -> + val name = stringProvider.getString(R.string.bottom_action_rooms) + val updatableFilterLivePageResult = session.getFilteredPagedRoomSummariesLive(qpm) + onUpdatable(updatableFilterLivePageResult) + + val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() + .flatMapLatest { session.getRoomCountLive(updatableFilterLivePageResult.queryParams).asFlow() } + .distinctUntilChanged() + + sections.add( + RoomsSection( + sectionName = name, + livePages = updatableFilterLivePageResult.livePagedList, + itemCount = itemCountFlow + ) + ) + } + ) + } + private fun addSection(sections: MutableList, activeSpaceUpdaters: MutableList, @StringRes nameRes: Int, @@ -339,83 +348,82 @@ class RoomListSectionBuilderSpace( spaceFilterStrategy: RoomListViewModel.SpaceFilterStrategy = RoomListViewModel.SpaceFilterStrategy.NONE, countRoomAsNotif: Boolean = false, query: (RoomSummaryQueryParams.Builder) -> Unit) { - withQueryParams( - { query.invoke(it) }, - { roomQueryParams -> - val name = stringProvider.getString(nameRes) - session.getFilteredPagedRoomSummariesLive( - roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()), - pagedListConfig - ).also { - when (spaceFilterStrategy) { - RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> { - activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater { - override fun updateForSpaceId(roomId: String?) { - it.queryParams = roomQueryParams.copy( - activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId) - ) - } - }) - } - RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> { - activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater { - override fun updateForSpaceId(roomId: String?) { - if (roomId != null) { - it.queryParams = roomQueryParams.copy( - activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId) - ) - } else { - it.queryParams = roomQueryParams.copy( - activeSpaceFilter = ActiveSpaceFilter.None - ) - } - } - }) - } - RoomListViewModel.SpaceFilterStrategy.NONE -> { - // we ignore current space for this one + withQueryParams(query) { roomQueryParams -> + val updatedQueryParams = roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()) + val liveQueryParams = MutableStateFlow(updatedQueryParams) + val itemCountFlow = liveQueryParams + .flatMapLatest { + session.getRoomCountLive(it).asFlow() + } + .flowOn(Dispatchers.Main) + .distinctUntilChanged() + + val name = stringProvider.getString(nameRes) + val filteredPagedRoomSummariesLive = session.getFilteredPagedRoomSummariesLive( + roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()), + pagedListConfig + ) + when (spaceFilterStrategy) { + RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> { + activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater { + override fun updateForSpaceId(roomId: String?) { + filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy( + activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId) + ) + liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams } + } + }) + } + RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> { + activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater { + override fun updateForSpaceId(roomId: String?) { + if (roomId != null) { + filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy( + activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId) + ) + } else { + filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy( + activeSpaceFilter = ActiveSpaceFilter.None + ) } + liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams } } - }.livePagedList - .let { livePagedList -> - // use it also as a source to update count - livePagedList.asFlow() - .onEach { - Timber.v("Thread space list: ${Thread.currentThread()}") - sections.find { it.sectionName == name } - ?.notificationCount - ?.postValue( - if (countRoomAsNotif) { - RoomAggregateNotificationCount(it.size, it.size) - } else { - session.getNotificationCountForRooms( - roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()) - ) - } - ) - } - .flowOn(Dispatchers.Default) - .launchIn(viewModelScope) + }) + } + RoomListViewModel.SpaceFilterStrategy.NONE -> { + // we ignore current space for this one + } + } - val itemCountFlow = livePagedList.asFlow() - .flatMapLatest { - val queryParams = roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()) - session.getRoomCountLive(queryParams).asFlow() + val livePagedList = filteredPagedRoomSummariesLive.livePagedList + // use it also as a source to update count + livePagedList.asFlow() + .onEach { + Timber.v("Thread space list: ${Thread.currentThread()}") + sections.find { it.sectionName == name } + ?.notificationCount + ?.postValue( + if (countRoomAsNotif) { + RoomAggregateNotificationCount(it.size, it.size) + } else { + session.getNotificationCountForRooms( + roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()) + ) } - .distinctUntilChanged() - - sections.add( - RoomsSection( - sectionName = name, - livePages = livePagedList, - notifyOfLocalEcho = notifyOfLocalEcho, - itemCount = itemCountFlow - ) ) - } - } + } + .flowOn(Dispatchers.Default) + .launchIn(viewModelScope) - ) + sections.add( + RoomsSection( + sectionName = name, + livePages = livePagedList, + notifyOfLocalEcho = notifyOfLocalEcho, + itemCount = itemCountFlow + ) + ) + } } private fun withQueryParams(builder: (RoomSummaryQueryParams.Builder) -> Unit, block: (RoomSummaryQueryParams) -> Unit) { From 8bcc2f5b0c62e27fd87f7374a256cc98cd477287 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 24 Mar 2022 19:07:44 +0100 Subject: [PATCH 11/12] Fix formating --- .../app/features/home/room/list/RoomListSectionBuilderSpace.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 262df2784a8..d405bc5b6fb 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 @@ -280,7 +280,8 @@ class RoomListSectionBuilderSpace( } } - private fun buildNotificationsSection(sections: MutableList, activeSpaceAwareQueries: MutableList) { + private fun buildNotificationsSection(sections: MutableList, + activeSpaceAwareQueries: MutableList) { if (autoAcceptInvites.showInvites()) { addSection( sections = sections, From 60ecfd4fc23d37a3a6363010cce52f1a0b34ff5e Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 24 Mar 2022 19:08:55 +0100 Subject: [PATCH 12/12] Update changes --- CHANGES.md | 9 +++++++++ changelog.d/5616.bugfix | 1 - fastlane/metadata/android/en-US/changelogs/40104070.txt | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) delete mode 100644 changelog.d/5616.bugfix create mode 100644 fastlane/metadata/android/en-US/changelogs/40104070.txt diff --git a/CHANGES.md b/CHANGES.md index e293a776dd4..5f0a2945de1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,11 @@ +Changes in Element v1.4.7 (2022-03-24) +====================================== + +Bugfixes 🐛 +---------- + - Fix inconsistencies between the arrow visibility and the collapse action on the room sections ([#5616](https://github.com/vector-im/element-android/issues/5616)) + - Fix room list header count flickering + Changes in Element v1.4.6 (2022-03-23) ====================================== @@ -37,6 +45,7 @@ SDK API changes ⚠️ Other changes ------------- + - Refactoring for safer olm and megolm session usage ([#5380](https://github.com/vector-im/element-android/issues/5380)) - Improve headers UI in Rooms/Messages lists ([#4533](https://github.com/vector-im/element-android/issues/4533)) - Number of unread messages on space badge now include number of unread DMs ([#5260](https://github.com/vector-im/element-android/issues/5260)) - Amend spaces menu to be consistent with iOS version ([#5270](https://github.com/vector-im/element-android/issues/5270)) diff --git a/changelog.d/5616.bugfix b/changelog.d/5616.bugfix deleted file mode 100644 index 5bec45854df..00000000000 --- a/changelog.d/5616.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix inconsistencies between the arrow visibility and the collapse action on the room sections \ No newline at end of file diff --git a/fastlane/metadata/android/en-US/changelogs/40104070.txt b/fastlane/metadata/android/en-US/changelogs/40104070.txt new file mode 100644 index 00000000000..99a3ecfe7b0 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/40104070.txt @@ -0,0 +1,2 @@ +Main changes in this version: Various bug fixes and stability improvements. +Full changelog: https://github.com/vector-im/element-android/releases/tag/v1.4.7 \ No newline at end of file