Fix / loading initial state, duplicate sections and footer on empty

This commit is contained in:
Valere 2021-04-02 11:43:56 +02:00
parent b9f73c6cc3
commit 100b187be3

View File

@ -95,11 +95,12 @@ class RoomListFragment @Inject constructor(
) )
private val adapterInfosList = mutableListOf<SectionAdapterInfo>() private val adapterInfosList = mutableListOf<SectionAdapterInfo>()
private val concatAdapter = ConcatAdapter() private var concatAdapter : ConcatAdapter? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
setupCreateRoomButton() views.stateView.contentView = views.roomListView
views.stateView.state = StateView.State.Loading
setupRecyclerView() setupRecyclerView()
sharedActionViewModel = activityViewModelProvider.get(RoomListQuickActionsSharedActionViewModel::class.java) sharedActionViewModel = activityViewModelProvider.get(RoomListQuickActionsSharedActionViewModel::class.java)
roomListViewModel.observeViewEvents { roomListViewModel.observeViewEvents {
@ -134,10 +135,10 @@ class RoomListFragment @Inject constructor(
val isRoomSectionExpanded = roomsSection.isExpanded.value.orTrue() val isRoomSectionExpanded = roomsSection.isExpanded.value.orTrue()
if (actualBlock.section.isExpanded && !isRoomSectionExpanded) { if (actualBlock.section.isExpanded && !isRoomSectionExpanded) {
// we have to remove the content adapter // we have to remove the content adapter
concatAdapter.removeAdapter(actualBlock.contentAdapter.adapter) concatAdapter?.removeAdapter(actualBlock.contentAdapter.adapter)
} else if (!actualBlock.section.isExpanded && isRoomSectionExpanded) { } else if (!actualBlock.section.isExpanded && isRoomSectionExpanded) {
// we must add it back! // we must add it back!
concatAdapter.addAdapter(contentInsertIndex, actualBlock.contentAdapter.adapter) concatAdapter?.addAdapter(contentInsertIndex, actualBlock.contentAdapter.adapter)
} }
contentInsertIndex = if (isRoomSectionExpanded) { contentInsertIndex = if (isRoomSectionExpanded) {
contentInsertIndex + 2 contentInsertIndex + 2
@ -166,6 +167,7 @@ class RoomListFragment @Inject constructor(
// TODO Cleanup listener on the ConcatAdapter's adapters? // TODO Cleanup listener on the ConcatAdapter's adapters?
stateRestorer.clear() stateRestorer.clear()
views.createChatFabMenu.listener = null views.createChatFabMenu.listener = null
concatAdapter = null
super.onDestroyView() super.onDestroyView()
} }
@ -236,6 +238,8 @@ class RoomListFragment @Inject constructor(
modelBuildListener = OnModelBuildFinishedListener { it.dispatchTo(stateRestorer) } modelBuildListener = OnModelBuildFinishedListener { it.dispatchTo(stateRestorer) }
val concatAdapter = ConcatAdapter()
roomListViewModel.sections.forEach { section -> roomListViewModel.sections.forEach { section ->
val sectionAdapter = SectionHeaderAdapter { val sectionAdapter = SectionHeaderAdapter {
roomListViewModel.handle(RoomListAction.ToggleSection(section)) roomListViewModel.handle(RoomListAction.ToggleSection(section))
@ -280,6 +284,7 @@ class RoomListFragment @Inject constructor(
footerController.listener = this footerController.listener = this
concatAdapter.addAdapter(footerController.adapter) concatAdapter.addAdapter(footerController.adapter)
this.concatAdapter = concatAdapter
views.roomListView.adapter = concatAdapter views.roomListView.adapter = concatAdapter
} }