mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-25 09:10:53 +01:00
Merge pull request #5616 from vector-im/hotfix/fre/collapse_rooms_section
Fix rooms section collapsing
This commit is contained in:
commit
81aa42a8e8
1
changelog.d/5616.bugfix
Normal file
1
changelog.d/5616.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Fix inconsistencies between the arrow visibility and the collapse action on the room sections
|
@ -148,8 +148,10 @@ class RoomListFragment @Inject constructor(
|
||||
}
|
||||
|
||||
private fun refreshCollapseStates() {
|
||||
val sectionsCount = adapterInfosList.count { !it.sectionHeaderAdapter.roomsSectionData.isHidden }
|
||||
roomListViewModel.sections.forEachIndexed { index, roomsSection ->
|
||||
val actualBlock = adapterInfosList[index]
|
||||
val isRoomSectionCollapsable = sectionsCount > 1
|
||||
val isRoomSectionExpanded = roomsSection.isExpanded.value.orTrue()
|
||||
if (actualBlock.section.isExpanded && !isRoomSectionExpanded) {
|
||||
// mark controller as collapsed
|
||||
@ -158,12 +160,18 @@ class RoomListFragment @Inject constructor(
|
||||
// we must expand!
|
||||
actualBlock.contentEpoxyController.setCollapsed(false)
|
||||
}
|
||||
actualBlock.section = actualBlock.section.copy(
|
||||
isExpanded = isRoomSectionExpanded
|
||||
)
|
||||
actualBlock.sectionHeaderAdapter.updateSection(
|
||||
actualBlock.sectionHeaderAdapter.roomsSectionData.copy(isExpanded = isRoomSectionExpanded)
|
||||
)
|
||||
actualBlock.section = actualBlock.section.copy(isExpanded = isRoomSectionExpanded)
|
||||
actualBlock.sectionHeaderAdapter.updateSection {
|
||||
it.copy(
|
||||
isExpanded = isRoomSectionExpanded,
|
||||
isCollapsable = isRoomSectionCollapsable
|
||||
)
|
||||
}
|
||||
|
||||
if (!isRoomSectionExpanded && !isRoomSectionCollapsable) {
|
||||
// force expand if the section is not collapsable
|
||||
roomListViewModel.handle(RoomListAction.ToggleSection(roomsSection))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,33 +279,36 @@ class RoomListFragment @Inject constructor(
|
||||
|
||||
val concatAdapter = ConcatAdapter()
|
||||
|
||||
roomListViewModel.sections.forEach { section ->
|
||||
val sectionAdapter = SectionHeaderAdapter {
|
||||
roomListViewModel.handle(RoomListAction.ToggleSection(section))
|
||||
}.also {
|
||||
it.updateSection(SectionHeaderAdapter.RoomsSectionData(section.sectionName))
|
||||
roomListViewModel.sections.forEachIndexed { index, section ->
|
||||
val sectionAdapter = SectionHeaderAdapter(SectionHeaderAdapter.RoomsSectionData(section.sectionName)) {
|
||||
if (adapterInfosList[index].sectionHeaderAdapter.roomsSectionData.isCollapsable) {
|
||||
roomListViewModel.handle(RoomListAction.ToggleSection(section))
|
||||
}
|
||||
}
|
||||
|
||||
val contentAdapter =
|
||||
when {
|
||||
section.livePages != null -> {
|
||||
section.livePages != null -> {
|
||||
pagedControllerFactory.createRoomSummaryPagedController()
|
||||
.also { controller ->
|
||||
section.livePages.observe(viewLifecycleOwner) { pl ->
|
||||
controller.submitList(pl)
|
||||
sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy(
|
||||
isHidden = pl.isEmpty(),
|
||||
isLoading = false
|
||||
))
|
||||
sectionAdapter.updateSection {
|
||||
it.copy(
|
||||
isHidden = pl.isEmpty(),
|
||||
isLoading = false
|
||||
)
|
||||
}
|
||||
refreshCollapseStates()
|
||||
checkEmptyState()
|
||||
}
|
||||
observeItemCount(section, sectionAdapter)
|
||||
section.notificationCount.observe(viewLifecycleOwner) { counts ->
|
||||
sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy(
|
||||
notificationCount = counts.totalCount,
|
||||
isHighlighted = counts.isHighlight,
|
||||
shouldShowExpandedArrow = shouldShowExpendedArrow()
|
||||
))
|
||||
sectionAdapter.updateSection {
|
||||
it.copy(
|
||||
notificationCount = counts.totalCount,
|
||||
isHighlighted = counts.isHighlight,
|
||||
)
|
||||
}
|
||||
}
|
||||
section.isExpanded.observe(viewLifecycleOwner) { _ ->
|
||||
refreshCollapseStates()
|
||||
@ -310,10 +321,13 @@ class RoomListFragment @Inject constructor(
|
||||
.also { controller ->
|
||||
section.liveSuggested.observe(viewLifecycleOwner) { info ->
|
||||
controller.setData(info)
|
||||
sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy(
|
||||
isHidden = info.rooms.isEmpty(),
|
||||
isLoading = false
|
||||
))
|
||||
sectionAdapter.updateSection {
|
||||
it.copy(
|
||||
isHidden = info.rooms.isEmpty(),
|
||||
isLoading = false
|
||||
)
|
||||
}
|
||||
refreshCollapseStates()
|
||||
checkEmptyState()
|
||||
}
|
||||
observeItemCount(section, sectionAdapter)
|
||||
@ -328,20 +342,23 @@ class RoomListFragment @Inject constructor(
|
||||
.also { controller ->
|
||||
section.liveList?.observe(viewLifecycleOwner) { list ->
|
||||
controller.setData(list)
|
||||
sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy(
|
||||
isHidden = list.isEmpty(),
|
||||
isLoading = false,
|
||||
shouldShowExpandedArrow = shouldShowExpendedArrow()
|
||||
))
|
||||
sectionAdapter.updateSection {
|
||||
it.copy(
|
||||
isHidden = list.isEmpty(),
|
||||
isLoading = false,
|
||||
)
|
||||
}
|
||||
refreshCollapseStates()
|
||||
checkEmptyState()
|
||||
}
|
||||
observeItemCount(section, sectionAdapter)
|
||||
section.notificationCount.observe(viewLifecycleOwner) { counts ->
|
||||
sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy(
|
||||
notificationCount = counts.totalCount,
|
||||
isHighlighted = counts.isHighlight,
|
||||
shouldShowExpandedArrow = shouldShowExpendedArrow()
|
||||
))
|
||||
sectionAdapter.updateSection {
|
||||
it.copy(
|
||||
notificationCount = counts.totalCount,
|
||||
isHighlighted = counts.isHighlight
|
||||
)
|
||||
}
|
||||
}
|
||||
section.isExpanded.observe(viewLifecycleOwner) { _ ->
|
||||
refreshCollapseStates()
|
||||
@ -389,9 +406,9 @@ class RoomListFragment @Inject constructor(
|
||||
section.itemCount
|
||||
.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
|
||||
.collect { count ->
|
||||
sectionAdapter.updateSection(
|
||||
sectionAdapter.roomsSectionData.copy(itemCount = count)
|
||||
)
|
||||
sectionAdapter.updateSection {
|
||||
it.copy(itemCount = count)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -448,10 +465,6 @@ class RoomListFragment @Inject constructor(
|
||||
footerController.setData(state)
|
||||
}
|
||||
|
||||
private fun shouldShowExpendedArrow(): Boolean {
|
||||
return adapterInfosList.filter { !it.sectionHeaderAdapter.roomsSectionData.isHidden }.size >= 2
|
||||
}
|
||||
|
||||
private fun checkEmptyState() {
|
||||
val shouldShowEmpty = adapterInfosList.all { it.sectionHeaderAdapter.roomsSectionData.isHidden } &&
|
||||
!adapterInfosList.any { it.sectionHeaderAdapter.roomsSectionData.isLoading }
|
||||
|
@ -29,6 +29,7 @@ import im.vector.app.databinding.ItemRoomCategoryBinding
|
||||
import im.vector.app.features.themes.ThemeUtils
|
||||
|
||||
class SectionHeaderAdapter constructor(
|
||||
roomsSectionData: RoomsSectionData,
|
||||
private val onClickAction: ClickListener
|
||||
) : RecyclerView.Adapter<SectionHeaderAdapter.VH>() {
|
||||
|
||||
@ -41,14 +42,15 @@ class SectionHeaderAdapter constructor(
|
||||
val isHidden: Boolean = true,
|
||||
// This will be false until real data has been submitted once
|
||||
val isLoading: Boolean = true,
|
||||
val shouldShowExpandedArrow: Boolean = false
|
||||
val isCollapsable: Boolean = false
|
||||
)
|
||||
|
||||
lateinit var roomsSectionData: RoomsSectionData
|
||||
var roomsSectionData: RoomsSectionData = roomsSectionData
|
||||
private set
|
||||
|
||||
fun updateSection(newRoomsSectionData: RoomsSectionData) {
|
||||
if (!::roomsSectionData.isInitialized || newRoomsSectionData != roomsSectionData) {
|
||||
fun updateSection(block: (RoomsSectionData) -> RoomsSectionData) {
|
||||
val newRoomsSectionData = block(roomsSectionData)
|
||||
if (roomsSectionData != newRoomsSectionData) {
|
||||
roomsSectionData = newRoomsSectionData
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
@ -84,7 +86,7 @@ class SectionHeaderAdapter constructor(
|
||||
fun bind(roomsSectionData: RoomsSectionData) {
|
||||
binding.roomCategoryTitleView.text = roomsSectionData.name
|
||||
val tintColor = ThemeUtils.getColor(binding.root.context, R.attr.vctr_content_secondary)
|
||||
if (roomsSectionData.shouldShowExpandedArrow) {
|
||||
if (roomsSectionData.isCollapsable) {
|
||||
binding.roomCategoryCounterView.visibility = View.VISIBLE
|
||||
val expandedArrowDrawableRes = if (roomsSectionData.isExpanded) R.drawable.ic_expand_more else R.drawable.ic_expand_less
|
||||
val expandedArrowDrawable = ContextCompat.getDrawable(binding.root.context, expandedArrowDrawableRes)?.also {
|
||||
|
Loading…
Reference in New Issue
Block a user