-
Notifications
You must be signed in to change notification settings - Fork 906
filtered room list at home #6724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
87ff248
new room list implementation for EditLayout
c7f6163
code review changes
997b4fc
lint fixes
e0222a4
filtered room list at home
56a91e6
Merge branch 'develop' into feature/nfe/edit_layout_filters
95140f9
lint fixes
baf82ce
Merge branch 'develop' into feature/nfe/edit_layout_filters
325ce4d
Merge branch 'develop' into feature/nfe/edit_layout_filters
8aa3049
review fixes, low priorites excluded from unreads
dc7ddb9
changelog added
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
library/ui-styles/src/main/res/values/styles_tablayout.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
|
|
||
| <style name="Widget.App.TabLayout" parent="Widget.MaterialComponents.TabLayout"> | ||
| <item name="materialThemeOverlay">@style/ThemeOverlay.Vector.HomeFilterTabLayout</item> | ||
| <item name="tabTextAppearance">@style/TextAppearance.Vector.FilterTabTextAppearance</item> | ||
| </style> | ||
|
|
||
| <style name="TextAppearance.Vector.FilterTabTextAppearance" parent="TextAppearance.Vector.Subtitle"> | ||
| <item name="textAllCaps">false</item> | ||
| </style> | ||
|
|
||
| <style name="ThemeOverlay.Vector.HomeFilterTabLayout" parent="Theme.Vector.Launcher"> | ||
| <item name="colorSurface">?vctr_toolbar_background</item> | ||
| <item name="colorOnSurface">?vctr_content_secondary</item> | ||
| </style> | ||
|
|
||
| </resources> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,31 +27,36 @@ import im.vector.app.core.di.MavericksAssistedViewModelFactory | |||||
| import im.vector.app.core.di.hiltMavericksViewModelFactory | ||||||
| import im.vector.app.core.platform.StateView | ||||||
| import im.vector.app.core.platform.VectorViewModel | ||||||
| import im.vector.app.features.settings.VectorPreferences | ||||||
| import im.vector.app.features.home.room.list.home.filter.HomeRoomFilter | ||||||
| import kotlinx.coroutines.Dispatchers | ||||||
| import kotlinx.coroutines.flow.MutableSharedFlow | ||||||
| import kotlinx.coroutines.flow.SharedFlow | ||||||
| import kotlinx.coroutines.flow.asSharedFlow | ||||||
| import kotlinx.coroutines.flow.combine | ||||||
| import kotlinx.coroutines.flow.distinctUntilChanged | ||||||
| import kotlinx.coroutines.flow.launchIn | ||||||
| import kotlinx.coroutines.flow.map | ||||||
| import kotlinx.coroutines.flow.onEach | ||||||
| import kotlinx.coroutines.flow.onStart | ||||||
| import kotlinx.coroutines.launch | ||||||
| import org.matrix.android.sdk.api.extensions.orFalse | ||||||
| import org.matrix.android.sdk.api.query.SpaceFilter | ||||||
| import org.matrix.android.sdk.api.query.RoomCategoryFilter | ||||||
| import org.matrix.android.sdk.api.query.RoomTagQueryFilter | ||||||
| import org.matrix.android.sdk.api.query.toActiveSpaceOrNoFilter | ||||||
| import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms | ||||||
| import org.matrix.android.sdk.api.session.Session | ||||||
| import org.matrix.android.sdk.api.session.getRoom | ||||||
| import org.matrix.android.sdk.api.session.room.RoomSortOrder | ||||||
| import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams | ||||||
| import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult | ||||||
| import org.matrix.android.sdk.api.session.room.model.Membership | ||||||
| import org.matrix.android.sdk.api.session.room.model.tag.RoomTag | ||||||
| import org.matrix.android.sdk.api.session.room.state.isPublic | ||||||
| import org.matrix.android.sdk.flow.flow | ||||||
|
|
||||||
| class HomeRoomListViewModel @AssistedInject constructor( | ||||||
| @Assisted initialState: HomeRoomListViewState, | ||||||
| private val session: Session, | ||||||
| private val spaceStateHandler: SpaceStateHandler, | ||||||
| private val vectorPreferences: VectorPreferences, | ||||||
| private val spaceStateHandler: SpaceStateHandler | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a trailing comma here?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ) : VectorViewModel<HomeRoomListViewState, HomeRoomListAction, HomeRoomListViewEvents>(initialState) { | ||||||
|
|
||||||
| @AssistedFactory | ||||||
|
|
@@ -71,14 +76,16 @@ class HomeRoomListViewModel @AssistedInject constructor( | |||||
| private val _sections = MutableSharedFlow<Set<HomeRoomSection>>(replay = 1) | ||||||
| val sections = _sections.asSharedFlow() | ||||||
|
|
||||||
| private var filteredPagedRoomSummariesLive: UpdatableLivePageResult? = null | ||||||
|
|
||||||
| init { | ||||||
| configureSections() | ||||||
| } | ||||||
|
|
||||||
| private fun configureSections() { | ||||||
| val newSections = mutableSetOf<HomeRoomSection>() | ||||||
|
|
||||||
| newSections.add(getAllRoomsSection()) | ||||||
| newSections.add(getFilteredRoomsSection()) | ||||||
|
|
||||||
| viewModelScope.launch { | ||||||
| _sections.emit(newSections) | ||||||
|
|
@@ -89,15 +96,21 @@ class HomeRoomListViewModel @AssistedInject constructor( | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private fun getAllRoomsSection(): HomeRoomSection.RoomSummaryData { | ||||||
| private fun getFilteredRoomsSection(): HomeRoomSection.RoomSummaryData { | ||||||
| val builder = RoomSummaryQueryParams.Builder().also { | ||||||
| it.memberships = listOf(Membership.JOIN) | ||||||
| } | ||||||
|
|
||||||
| val filteredPagedRoomSummariesLive = session.roomService().getFilteredPagedRoomSummariesLive( | ||||||
| builder.build(), | ||||||
| pagedListConfig | ||||||
| ) | ||||||
| val params = getFilteredQueryParams(HomeRoomFilter.ALL, builder.build()) | ||||||
| val sortOrder = RoomSortOrder.ACTIVITY // TODO: https://github.com/vector-im/element-android/issues/6506 | ||||||
|
|
||||||
| val liveResults = session.roomService().getFilteredPagedRoomSummariesLive( | ||||||
| params, | ||||||
| pagedListConfig, | ||||||
| sortOrder | ||||||
| ).also { | ||||||
| this.filteredPagedRoomSummariesLive = it | ||||||
| } | ||||||
|
|
||||||
| spaceStateHandler.getSelectedSpaceFlow() | ||||||
| .distinctUntilChanged() | ||||||
|
|
@@ -106,20 +119,83 @@ class HomeRoomListViewModel @AssistedInject constructor( | |||||
| } | ||||||
| .onEach { selectedSpaceOption -> | ||||||
| val selectedSpace = selectedSpaceOption.orNull() | ||||||
| filteredPagedRoomSummariesLive.queryParams = filteredPagedRoomSummariesLive.queryParams.copy( | ||||||
| spaceFilter = getSpaceFilter(selectedSpaceId = selectedSpace?.roomId) | ||||||
| liveResults.queryParams = liveResults.queryParams.copy( | ||||||
| spaceFilter = selectedSpace?.roomId.toActiveSpaceOrNoFilter() | ||||||
| ) | ||||||
| }.launchIn(viewModelScope) | ||||||
|
|
||||||
| return HomeRoomSection.RoomSummaryData( | ||||||
| list = filteredPagedRoomSummariesLive.livePagedList | ||||||
| list = liveResults.livePagedList, | ||||||
| showFilters = true, // TODO: https://github.com/vector-im/element-android/issues/6506 | ||||||
| filtersData = getFiltersDataFlow() | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| private fun getSpaceFilter(selectedSpaceId: String?): SpaceFilter { | ||||||
| return when { | ||||||
| vectorPreferences.prefSpacesShowAllRoomInHome() -> selectedSpaceId.toActiveSpaceOrNoFilter() | ||||||
| else -> selectedSpaceId.toActiveSpaceOrOrphanRooms() | ||||||
| private fun getFiltersDataFlow(): SharedFlow<List<HomeRoomFilter>> { | ||||||
| val flow = MutableSharedFlow<List<HomeRoomFilter>>(replay = 1) | ||||||
|
|
||||||
| val favouritesFlow = session.flow() | ||||||
| .liveRoomSummaries( | ||||||
| RoomSummaryQueryParams.Builder().also { builder -> | ||||||
| builder.roomTagQueryFilter = RoomTagQueryFilter(true, null, null) | ||||||
| }.build() | ||||||
| ) | ||||||
| .map { it.isNotEmpty() } | ||||||
| .distinctUntilChanged() | ||||||
|
|
||||||
| val dmsFLow = session.flow() | ||||||
| .liveRoomSummaries( | ||||||
| RoomSummaryQueryParams.Builder().also { builder -> | ||||||
| builder.memberships = listOf(Membership.JOIN) | ||||||
| builder.roomCategoryFilter = RoomCategoryFilter.ONLY_DM | ||||||
| }.build() | ||||||
| ) | ||||||
| .map { it.isNotEmpty() } | ||||||
| .distinctUntilChanged() | ||||||
|
|
||||||
| favouritesFlow.combine(dmsFLow) { hasFavourite, hasDm -> | ||||||
| hasFavourite to hasDm | ||||||
| }.onEach { (hasFavourite, hasDm) -> | ||||||
| val filtersData = mutableListOf( | ||||||
| HomeRoomFilter.ALL, | ||||||
| HomeRoomFilter.UNREADS | ||||||
| ) | ||||||
| if (hasFavourite) { | ||||||
| filtersData.add( | ||||||
| HomeRoomFilter.FAVOURITES | ||||||
| ) | ||||||
| } | ||||||
| if (hasDm) { | ||||||
| filtersData.add( | ||||||
| HomeRoomFilter.PEOPlE | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| flow.emit(filtersData) | ||||||
| }.launchIn(viewModelScope) | ||||||
|
|
||||||
| return flow | ||||||
| } | ||||||
|
|
||||||
| private fun getFilteredQueryParams(filter: HomeRoomFilter, currentParams: RoomSummaryQueryParams): RoomSummaryQueryParams { | ||||||
| return when (filter) { | ||||||
| HomeRoomFilter.ALL -> currentParams.copy( | ||||||
| roomCategoryFilter = null, | ||||||
| roomTagQueryFilter = null | ||||||
| ) | ||||||
| HomeRoomFilter.UNREADS -> currentParams.copy( | ||||||
| roomCategoryFilter = RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS, | ||||||
| roomTagQueryFilter = null | ||||||
| ) | ||||||
| HomeRoomFilter.FAVOURITES -> | ||||||
| currentParams.copy( | ||||||
| roomCategoryFilter = null, | ||||||
| roomTagQueryFilter = RoomTagQueryFilter(true, null, null) | ||||||
| ) | ||||||
| HomeRoomFilter.PEOPlE -> currentParams.copy( | ||||||
| roomCategoryFilter = RoomCategoryFilter.ONLY_DM, | ||||||
| roomTagQueryFilter = null | ||||||
| ) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -129,6 +205,13 @@ class HomeRoomListViewModel @AssistedInject constructor( | |||||
| is HomeRoomListAction.LeaveRoom -> handleLeaveRoom(action) | ||||||
| is HomeRoomListAction.ChangeRoomNotificationState -> handleChangeNotificationMode(action) | ||||||
| is HomeRoomListAction.ToggleTag -> handleToggleTag(action) | ||||||
| is HomeRoomListAction.ChangeRoomFilter -> handleChangeRoomFilter(action) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private fun handleChangeRoomFilter(action: HomeRoomListAction.ChangeRoomFilter) { | ||||||
| filteredPagedRoomSummariesLive?.let { liveResults -> | ||||||
| liveResults.queryParams = getFilteredQueryParams(action.filter, liveResults.queryParams) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...ain/java/im/vector/app/features/home/room/list/home/filter/HomeFilteredRoomsController.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright (c) 2022 New Vector Ltd | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package im.vector.app.features.home.room.list.home.filter | ||
|
|
||
| import com.airbnb.epoxy.EpoxyModel | ||
| import com.airbnb.epoxy.paging.PagedListEpoxyController | ||
| import im.vector.app.core.utils.createUIHandler | ||
| import im.vector.app.features.home.RoomListDisplayMode | ||
| import im.vector.app.features.home.room.list.RoomListListener | ||
| import im.vector.app.features.home.room.list.RoomSummaryItemFactory | ||
| import im.vector.app.features.home.room.list.RoomSummaryItemPlaceHolder_ | ||
| import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState | ||
| import org.matrix.android.sdk.api.session.room.model.RoomSummary | ||
|
|
||
| class HomeFilteredRoomsController( | ||
| private val roomSummaryItemFactory: RoomSummaryItemFactory, | ||
| private val showFilters: Boolean, | ||
| ) : PagedListEpoxyController<RoomSummary>( | ||
| // Important it must match the PageList builder notify Looper | ||
| modelBuildingHandler = createUIHandler() | ||
| ) { | ||
|
|
||
| private var roomChangeMembershipStates: Map<String, ChangeMembershipState>? = null | ||
| set(value) { | ||
| field = value | ||
| // ideally we could search for visible models and update only those | ||
| requestForcedModelBuild() | ||
| } | ||
|
|
||
| var listener: RoomListListener? = null | ||
| var onFilterChanged: ((HomeRoomFilter) -> Unit)? = null | ||
|
|
||
| private var filtersData: List<HomeRoomFilter>? = null | ||
|
|
||
| override fun addModels(models: List<EpoxyModel<*>>) { | ||
| val host = this | ||
| if (showFilters) { | ||
| roomFilterHeaderItem { | ||
| id("filter_header") | ||
| filtersData(host.filtersData) | ||
| onFilterChangedListener(host.onFilterChanged) | ||
| } | ||
| } | ||
| super.addModels(models) | ||
| } | ||
|
|
||
| fun submitFiltersData(data: List<HomeRoomFilter>) { | ||
| this.filtersData = data | ||
| requestForcedModelBuild() | ||
| } | ||
|
|
||
| override fun buildItemModel(currentPosition: Int, item: RoomSummary?): EpoxyModel<*> { | ||
| item ?: return RoomSummaryItemPlaceHolder_().apply { id(currentPosition) } | ||
| return roomSummaryItemFactory.create(item, roomChangeMembershipStates.orEmpty(), emptySet(), RoomListDisplayMode.ROOMS, listener) | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
vector/src/main/java/im/vector/app/features/home/room/list/home/filter/HomeRoomFilter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Copyright (c) 2022 New Vector Ltd | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package im.vector.app.features.home.room.list.home.filter | ||
|
|
||
| import androidx.annotation.StringRes | ||
| import im.vector.app.R | ||
|
|
||
| enum class HomeRoomFilter(@StringRes val titleRes: Int) { | ||
| ALL(R.string.room_list_filter_all), | ||
| UNREADS(R.string.room_list_filter_unreads), | ||
| FAVOURITES(R.string.room_list_filter_favourites), | ||
| PEOPlE(R.string.room_list_filter_people), | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do
Widget.Vector.TabLayoutfor consistent with other styles in the app