From 5e75a3a80b6525d55d732466820fada5694a698e Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 19 Apr 2021 11:33:33 +0200 Subject: [PATCH] Add placehoders for paged room list --- .../room/list/RoomSummaryItemPlaceHolder.kt | 27 +++++++ .../room/list/RoomSummaryPagedController.kt | 26 ++---- .../room/list/SpaceRoomListSectionBuilder.kt | 12 ++- .../main/res/layout/item_room_placeholder.xml | 79 +++++++++++++++++++ 4 files changed, 123 insertions(+), 21 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemPlaceHolder.kt create mode 100644 vector/src/main/res/layout/item_room_placeholder.xml diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemPlaceHolder.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemPlaceHolder.kt new file mode 100644 index 0000000000..96d8f6418b --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemPlaceHolder.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2021 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 + +import com.airbnb.epoxy.EpoxyModelClass +import im.vector.app.R +import im.vector.app.core.epoxy.VectorEpoxyHolder +import im.vector.app.core.epoxy.VectorEpoxyModel + +@EpoxyModelClass(layout = R.layout.item_room_placeholder) +abstract class RoomSummaryItemPlaceHolder : VectorEpoxyModel() { + class Holder : VectorEpoxyHolder() +} diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryPagedController.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryPagedController.kt index aae548c1e7..e9cbc69215 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryPagedController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryPagedController.kt @@ -24,7 +24,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary class RoomSummaryPagedController( private val roomSummaryItemFactory: RoomSummaryItemFactory -) : PagedListEpoxyController ( +) : PagedListEpoxyController( // Important it must match the PageList builder notify Looper modelBuildingHandler = createUIHandler() ), CollapsableControllerExtension { @@ -39,12 +39,12 @@ class RoomSummaryPagedController( } override var collapsed = false - set(value) { - if (field != value) { - field = value - requestForcedModelBuild() + set(value) { + if (field != value) { + field = value + requestForcedModelBuild() + } } - } override fun addModels(models: List>) { if (collapsed) { @@ -56,19 +56,7 @@ class RoomSummaryPagedController( override fun buildItemModel(currentPosition: Int, item: RoomSummary?): EpoxyModel<*> { // for place holder if enabled - item ?: return roomSummaryItemFactory.createRoomItem( - roomSummary = RoomSummary( - roomId = "null_item_pos_$currentPosition", - name = "", - encryptionEventTs = null, - isEncrypted = false, - typingUsers = emptyList() - ), - selectedRoomIds = emptySet(), - onClick = null, - onLongClick = null - ) - + item ?: return RoomSummaryItemPlaceHolder_().apply { id(currentPosition) } return roomSummaryItemFactory.create(item, roomChangeMembershipStates.orEmpty(), emptySet(), listener) } } 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 426c29a622..a05f6ebaf8 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 @@ -20,6 +20,7 @@ import androidx.annotation.StringRes import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.liveData +import androidx.paging.PagedList import com.airbnb.mvrx.Async import im.vector.app.AppStateHandler import im.vector.app.R @@ -52,6 +53,13 @@ class SpaceRoomListSectionBuilder( val onUdpatable: (UpdatableLivePageResult) -> Unit ) : RoomListSectionBuilder { + val pagedListConfig = PagedList.Config.Builder() + .setPageSize(10) + .setInitialLoadSizeHint(20) + .setEnablePlaceholders(true) + .setPrefetchDistance(10) + .build() + override fun buildSections(mode: RoomListDisplayMode): List { val sections = mutableListOf() val activeSpaceAwareQueries = mutableListOf() @@ -322,8 +330,8 @@ class SpaceRoomListSectionBuilder( } } RoomListViewModel.SpaceFilterStrategy.NONE -> roomQueryParams - } - + }, + pagedListConfig ).also { when (spaceFilterStrategy) { RoomListViewModel.SpaceFilterStrategy.NORMAL -> { diff --git a/vector/src/main/res/layout/item_room_placeholder.xml b/vector/src/main/res/layout/item_room_placeholder.xml new file mode 100644 index 0000000000..41131c5150 --- /dev/null +++ b/vector/src/main/res/layout/item_room_placeholder.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + +