Fix / Room list empty state flickering
This commit is contained in:
parent
b45585f7c0
commit
d42761f98a
|
@ -251,7 +251,10 @@ class RoomListFragment @Inject constructor(
|
||||||
.also { controller ->
|
.also { controller ->
|
||||||
section.livePages.observe(viewLifecycleOwner) { pl ->
|
section.livePages.observe(viewLifecycleOwner) { pl ->
|
||||||
controller.submitList(pl)
|
controller.submitList(pl)
|
||||||
sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy(isHidden = pl.isEmpty()))
|
sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy(
|
||||||
|
isHidden = pl.isEmpty(),
|
||||||
|
isLoading = false
|
||||||
|
))
|
||||||
checkEmptyState()
|
checkEmptyState()
|
||||||
}
|
}
|
||||||
section.notificationCount.observe(viewLifecycleOwner) { counts ->
|
section.notificationCount.observe(viewLifecycleOwner) { counts ->
|
||||||
|
@ -271,7 +274,10 @@ class RoomListFragment @Inject constructor(
|
||||||
.also { controller ->
|
.also { controller ->
|
||||||
section.liveSuggested.observe(viewLifecycleOwner) { info ->
|
section.liveSuggested.observe(viewLifecycleOwner) { info ->
|
||||||
controller.setData(info)
|
controller.setData(info)
|
||||||
sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy(isHidden = info.rooms.isEmpty()))
|
sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy(
|
||||||
|
isHidden = info.rooms.isEmpty(),
|
||||||
|
isLoading = false
|
||||||
|
))
|
||||||
checkEmptyState()
|
checkEmptyState()
|
||||||
}
|
}
|
||||||
section.isExpanded.observe(viewLifecycleOwner) { _ ->
|
section.isExpanded.observe(viewLifecycleOwner) { _ ->
|
||||||
|
@ -285,7 +291,9 @@ class RoomListFragment @Inject constructor(
|
||||||
.also { controller ->
|
.also { controller ->
|
||||||
section.liveList?.observe(viewLifecycleOwner) { list ->
|
section.liveList?.observe(viewLifecycleOwner) { list ->
|
||||||
controller.setData(list)
|
controller.setData(list)
|
||||||
sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy(isHidden = list.isEmpty()))
|
sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy(
|
||||||
|
isHidden = list.isEmpty(),
|
||||||
|
isLoading = false))
|
||||||
checkEmptyState()
|
checkEmptyState()
|
||||||
}
|
}
|
||||||
section.notificationCount.observe(viewLifecycleOwner) { counts ->
|
section.notificationCount.observe(viewLifecycleOwner) { counts ->
|
||||||
|
@ -393,8 +401,9 @@ class RoomListFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkEmptyState() {
|
private fun checkEmptyState() {
|
||||||
val hasNoRoom = adapterInfosList.all { it.headerHeaderAdapter.roomsSectionData.isHidden }
|
val shouldShowEmpty = adapterInfosList.all { it.headerHeaderAdapter.roomsSectionData.isHidden }
|
||||||
if (hasNoRoom) {
|
&& !adapterInfosList.any { it.headerHeaderAdapter.roomsSectionData.isLoading }
|
||||||
|
if (shouldShowEmpty) {
|
||||||
val emptyState = when (roomListParams.displayMode) {
|
val emptyState = when (roomListParams.displayMode) {
|
||||||
RoomListDisplayMode.NOTIFICATIONS -> {
|
RoomListDisplayMode.NOTIFICATIONS -> {
|
||||||
StateView.State.Empty(
|
StateView.State.Empty(
|
||||||
|
@ -422,7 +431,12 @@ class RoomListFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
views.stateView.state = emptyState
|
views.stateView.state = emptyState
|
||||||
} else {
|
} else {
|
||||||
views.stateView.state = StateView.State.Content
|
// is there something to show already?
|
||||||
|
if (adapterInfosList.any { !it.headerHeaderAdapter.roomsSectionData.isHidden }) {
|
||||||
|
views.stateView.state = StateView.State.Content
|
||||||
|
} else {
|
||||||
|
views.stateView.state = StateView.State.Loading
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,9 @@ class SectionHeaderAdapter constructor(
|
||||||
val isExpanded: Boolean = true,
|
val isExpanded: Boolean = true,
|
||||||
val notificationCount: Int = 0,
|
val notificationCount: Int = 0,
|
||||||
val isHighlighted: Boolean = false,
|
val isHighlighted: Boolean = false,
|
||||||
val isHidden: Boolean = true
|
val isHidden: Boolean = true,
|
||||||
|
// This will be false until real data has been submitted once
|
||||||
|
val isLoading: Boolean = true
|
||||||
)
|
)
|
||||||
|
|
||||||
lateinit var roomsSectionData: RoomsSectionData
|
lateinit var roomsSectionData: RoomsSectionData
|
||||||
|
|
Loading…
Reference in New Issue