Merge pull request #1865 from vector-im/feature/fga/room_list_dynamic_api
RoomList : rework a bit the api and make usage of entriesWithDynamicAdapter
This commit is contained in:
commit
40efe4844e
17 changed files with 317 additions and 213 deletions
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2023 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 io.element.android.libraries.matrix.api.roomlist
|
||||
|
||||
/**
|
||||
* RoomList with dynamic filtering and loading.
|
||||
* This is useful for large lists of rooms.
|
||||
* It lets load rooms on demand and filter them.
|
||||
*/
|
||||
interface DynamicRoomList : RoomList {
|
||||
|
||||
companion object {
|
||||
const val DEFAULT_PAGE_SIZE = 20
|
||||
const val DEFAULT_PAGES_TO_LOAD = 10
|
||||
}
|
||||
|
||||
sealed interface Filter {
|
||||
/**
|
||||
* No filter applied.
|
||||
*/
|
||||
data object All : Filter
|
||||
|
||||
/**
|
||||
* Filter all rooms.
|
||||
*/
|
||||
data object None : Filter
|
||||
|
||||
/**
|
||||
* Filter rooms by normalized room name.
|
||||
*/
|
||||
data class NormalizedMatchRoomName(val pattern: String) : Filter
|
||||
}
|
||||
|
||||
/**
|
||||
* Load more rooms into the list if possible.
|
||||
*/
|
||||
suspend fun loadMore()
|
||||
|
||||
/**
|
||||
* Reset the list to its initial size.
|
||||
*/
|
||||
suspend fun reset()
|
||||
|
||||
/**
|
||||
* Update the filter to apply to the list.
|
||||
* @param filter the filter to apply.
|
||||
*/
|
||||
suspend fun updateFilter(filter: Filter)
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@ import kotlin.time.Duration
|
|||
* Can be retrieved from [RoomListService] methods.
|
||||
*/
|
||||
interface RoomList {
|
||||
|
||||
sealed interface LoadingState {
|
||||
data object NotLoaded : LoadingState
|
||||
data class Loaded(val numberOfRooms: Int) : LoadingState
|
||||
|
|
@ -43,6 +44,12 @@ interface RoomList {
|
|||
* This is useful to know if a specific set of rooms is loaded or not.
|
||||
*/
|
||||
val loadingState: StateFlow<LoadingState>
|
||||
|
||||
/**
|
||||
* Force a refresh of the room summaries.
|
||||
* Might be useful for some situations where we are not notified of changes.
|
||||
*/
|
||||
suspend fun rebuildSummaries()
|
||||
}
|
||||
|
||||
suspend fun RoomList.awaitLoaded(timeout: Duration = Duration.INFINITE) {
|
||||
|
|
|
|||
|
|
@ -41,12 +41,12 @@ interface RoomListService {
|
|||
* returns a [RoomList] object of all rooms we want to display.
|
||||
* This will exclude some rooms like the invites, or spaces.
|
||||
*/
|
||||
fun allRooms(): RoomList
|
||||
val allRooms: RoomList
|
||||
|
||||
/**
|
||||
* returns a [RoomList] object of all invites.
|
||||
*/
|
||||
fun invites(): RoomList
|
||||
val invites: RoomList
|
||||
|
||||
/**
|
||||
* Will set the visible range of all rooms.
|
||||
|
|
@ -54,11 +54,6 @@ interface RoomListService {
|
|||
*/
|
||||
fun updateAllRoomsVisibleRange(range: IntRange)
|
||||
|
||||
/**
|
||||
* Rebuild the room summaries, required when we know some data may have changed. (E.g. room notification settings)
|
||||
*/
|
||||
fun rebuildRoomSummaries()
|
||||
|
||||
/**
|
||||
* The sync indicator as a flow.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue