From 100b187be37ba8cefe49d2cca2feb7f3f014df8e Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 2 Apr 2021 11:43:56 +0200 Subject: [PATCH] Fix / loading initial state, duplicate sections and footer on empty --- .../app/features/home/room/list/RoomListFragment.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 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 8e837e85c6..ede3df2c18 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 @@ -95,11 +95,12 @@ class RoomListFragment @Inject constructor( ) private val adapterInfosList = mutableListOf() - private val concatAdapter = ConcatAdapter() + private var concatAdapter : ConcatAdapter? = null override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - setupCreateRoomButton() + views.stateView.contentView = views.roomListView + views.stateView.state = StateView.State.Loading setupRecyclerView() sharedActionViewModel = activityViewModelProvider.get(RoomListQuickActionsSharedActionViewModel::class.java) roomListViewModel.observeViewEvents { @@ -134,10 +135,10 @@ class RoomListFragment @Inject constructor( val isRoomSectionExpanded = roomsSection.isExpanded.value.orTrue() if (actualBlock.section.isExpanded && !isRoomSectionExpanded) { // we have to remove the content adapter - concatAdapter.removeAdapter(actualBlock.contentAdapter.adapter) + concatAdapter?.removeAdapter(actualBlock.contentAdapter.adapter) } else if (!actualBlock.section.isExpanded && isRoomSectionExpanded) { // we must add it back! - concatAdapter.addAdapter(contentInsertIndex, actualBlock.contentAdapter.adapter) + concatAdapter?.addAdapter(contentInsertIndex, actualBlock.contentAdapter.adapter) } contentInsertIndex = if (isRoomSectionExpanded) { contentInsertIndex + 2 @@ -166,6 +167,7 @@ class RoomListFragment @Inject constructor( // TODO Cleanup listener on the ConcatAdapter's adapters? stateRestorer.clear() views.createChatFabMenu.listener = null + concatAdapter = null super.onDestroyView() } @@ -236,6 +238,8 @@ class RoomListFragment @Inject constructor( modelBuildListener = OnModelBuildFinishedListener { it.dispatchTo(stateRestorer) } + val concatAdapter = ConcatAdapter() + roomListViewModel.sections.forEach { section -> val sectionAdapter = SectionHeaderAdapter { roomListViewModel.handle(RoomListAction.ToggleSection(section)) @@ -280,6 +284,7 @@ class RoomListFragment @Inject constructor( footerController.listener = this concatAdapter.addAdapter(footerController.adapter) + this.concatAdapter = concatAdapter views.roomListView.adapter = concatAdapter }