mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-27 09:31:20 +01:00
Fix filtering use case
This commit is contained in:
parent
c79aa267c3
commit
3d27d9d2d2
@ -22,10 +22,8 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
|
||||
interface UpdatableLivePageResult {
|
||||
val livePagedList: LiveData<PagedList<RoomSummary>>
|
||||
|
||||
fun updateQuery(builder: (RoomSummaryQueryParams) -> RoomSummaryQueryParams)
|
||||
|
||||
val liveBoundaries: LiveData<ResultBoundaries>
|
||||
var queryParams: RoomSummaryQueryParams
|
||||
}
|
||||
|
||||
data class ResultBoundaries(
|
||||
|
@ -228,14 +228,16 @@ internal class RoomSummaryDataSource @Inject constructor(
|
||||
return object : UpdatableLivePageResult {
|
||||
override val livePagedList: LiveData<PagedList<RoomSummary>> = mapped
|
||||
|
||||
override fun updateQuery(builder: (RoomSummaryQueryParams) -> RoomSummaryQueryParams) {
|
||||
realmDataSourceFactory.updateQuery {
|
||||
roomSummariesQuery(it, builder.invoke(queryParams)).process(sortOrder)
|
||||
}
|
||||
}
|
||||
|
||||
override val liveBoundaries: LiveData<ResultBoundaries>
|
||||
get() = boundaries
|
||||
|
||||
override var queryParams: RoomSummaryQueryParams = queryParams
|
||||
set(value) {
|
||||
field = value
|
||||
realmDataSourceFactory.updateQuery {
|
||||
roomSummariesQuery(it, value).process(sortOrder)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ import im.vector.app.features.invite.showInvites
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
@ -68,16 +69,19 @@ class RoomListSectionBuilderGroup(
|
||||
it.memberships = Membership.activeMemberships()
|
||||
},
|
||||
{ qpm ->
|
||||
// TODO find a clean way to listen query params changes to show the filtered rooms count
|
||||
val name = stringProvider.getString(R.string.bottom_action_rooms)
|
||||
session.getFilteredPagedRoomSummariesLive(qpm)
|
||||
.let { updatableFilterLivePageResult ->
|
||||
onUpdatable(updatableFilterLivePageResult)
|
||||
|
||||
val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow()
|
||||
.flatMapLatest { session.getRoomCountFlow(updatableFilterLivePageResult.queryParams) }
|
||||
|
||||
sections.add(
|
||||
RoomsSection(
|
||||
sectionName = name,
|
||||
livePages = updatableFilterLivePageResult.livePagedList,
|
||||
itemCount = session.getRoomCountFlow(qpm)
|
||||
itemCount = itemCountFlow
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -116,9 +120,7 @@ class RoomListSectionBuilderGroup(
|
||||
.onEach { groupingMethod ->
|
||||
val selectedGroupId = (groupingMethod.orNull() as? RoomGroupingMethod.ByLegacyGroup)?.groupSummary?.groupId
|
||||
activeGroupAwareQueries.onEach { updater ->
|
||||
updater.updateQuery { query ->
|
||||
query.copy(activeGroupId = selectedGroupId)
|
||||
}
|
||||
updater.queryParams = updater.queryParams.copy(activeGroupId = selectedGroupId)
|
||||
}
|
||||
}.launchIn(coroutineScope)
|
||||
|
||||
|
@ -88,16 +88,19 @@ class RoomListSectionBuilderSpace(
|
||||
it.memberships = Membership.activeMemberships()
|
||||
},
|
||||
{ qpm ->
|
||||
// TODO find a clean way to listen query params changes to show the filtered rooms count
|
||||
val name = stringProvider.getString(R.string.bottom_action_rooms)
|
||||
session.getFilteredPagedRoomSummariesLive(qpm)
|
||||
.let { updatableFilterLivePageResult ->
|
||||
onUpdatable(updatableFilterLivePageResult)
|
||||
|
||||
val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow()
|
||||
.flatMapLatest { session.getRoomCountFlow(updatableFilterLivePageResult.queryParams) }
|
||||
|
||||
sections.add(
|
||||
RoomsSection(
|
||||
sectionName = name,
|
||||
livePages = updatableFilterLivePageResult.livePagedList,
|
||||
itemCount = session.getRoomCountFlow(qpm)
|
||||
itemCount = itemCountFlow
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -347,11 +350,9 @@ class RoomListSectionBuilderSpace(
|
||||
RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> {
|
||||
activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater {
|
||||
override fun updateForSpaceId(roomId: String?) {
|
||||
it.updateQuery {
|
||||
it.copy(
|
||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId)
|
||||
)
|
||||
}
|
||||
it.queryParams = roomQueryParams.copy(
|
||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId)
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -359,17 +360,13 @@ class RoomListSectionBuilderSpace(
|
||||
activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater {
|
||||
override fun updateForSpaceId(roomId: String?) {
|
||||
if (roomId != null) {
|
||||
it.updateQuery {
|
||||
it.copy(
|
||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId)
|
||||
)
|
||||
}
|
||||
it.queryParams = roomQueryParams.copy(
|
||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId)
|
||||
)
|
||||
} else {
|
||||
it.updateQuery {
|
||||
it.copy(
|
||||
activeSpaceFilter = ActiveSpaceFilter.None
|
||||
)
|
||||
}
|
||||
it.queryParams = roomQueryParams.copy(
|
||||
activeSpaceFilter = ActiveSpaceFilter.None
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -192,8 +192,8 @@ class RoomListViewModel @AssistedInject constructor(
|
||||
roomFilter = action.filter
|
||||
)
|
||||
}
|
||||
updatableQuery?.updateQuery {
|
||||
it.copy(
|
||||
updatableQuery?.apply {
|
||||
queryParams = queryParams.copy(
|
||||
displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.NORMALIZED)
|
||||
)
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
package im.vector.app.features.spaces.manage
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.paging.PagedList
|
||||
import com.airbnb.mvrx.Fail
|
||||
import com.airbnb.mvrx.Loading
|
||||
@ -143,17 +142,13 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
|
||||
|
||||
override fun handle(action: SpaceAddRoomActions) {
|
||||
when (action) {
|
||||
is SpaceAddRoomActions.UpdateFilter -> {
|
||||
updatableLivePageResult.updateQuery {
|
||||
it.copy(
|
||||
displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE)
|
||||
)
|
||||
}
|
||||
updatableLiveSpacePageResult.updateQuery {
|
||||
it.copy(
|
||||
displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE)
|
||||
)
|
||||
}
|
||||
is SpaceAddRoomActions.UpdateFilter -> {
|
||||
updatableLivePageResult.queryParams = updatableLivePageResult.queryParams.copy(
|
||||
displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE)
|
||||
)
|
||||
updatableLivePageResult.queryParams = updatableLivePageResult.queryParams.copy(
|
||||
displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE)
|
||||
)
|
||||
setState {
|
||||
copy(
|
||||
currentFilter = action.filter
|
||||
@ -164,7 +159,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
|
||||
selectionList[action.roomSummary.roomId] = (selectionList[action.roomSummary.roomId] ?: false).not()
|
||||
selectionListLiveData.postValue(selectionList.toMap())
|
||||
}
|
||||
SpaceAddRoomActions.Save -> {
|
||||
SpaceAddRoomActions.Save -> {
|
||||
doAddSelectedRooms()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user