Fix read marker visibility/position when filtering some events

This commit is contained in:
ganfra 2021-05-10 16:53:52 +02:00
parent fb0205e903
commit 581847e5c1
2 changed files with 9 additions and 7 deletions

View file

@ -24,6 +24,7 @@ Bugfix 🐛:
- Fix read marker not updating automatically (#3267)
- Sent video does not contains duration (#3272)
- Properly clean the back stack if the user cancel registration when waiting for email validation
- Fix read marker visibility/position when filtering some events
Translations 🗣:
-

View file

@ -62,6 +62,7 @@ class TimelineControllerInterceptorHelper(private val positionOfReadMarker: KMut
val firstUnreadEventId = (unreadState as? UnreadState.HasUnread)?.firstUnreadEventId
var atLeastOneVisibleItemSinceLastDaySeparator = false
var atLeastOneVisibleItemsBeforeReadMarker = false
var appendReadMarker = false
// Then iterate on models so we have the exact positions in the adapter
modelsIterator.forEach { epoxyModel ->
@ -72,11 +73,7 @@ class TimelineControllerInterceptorHelper(private val positionOfReadMarker: KMut
}
epoxyModel.getEventIds().forEach { eventId ->
adapterPositionMapping[eventId] = index
if (epoxyModel.canAppendReadMarker() && eventId == firstUnreadEventId && atLeastOneVisibleItemsBeforeReadMarker) {
modelsIterator.addReadMarkerItem(callback)
index++
positionOfReadMarker.set(index)
}
appendReadMarker = epoxyModel.canAppendReadMarker() && eventId == firstUnreadEventId && atLeastOneVisibleItemsBeforeReadMarker
}
}
if (epoxyModel is DaySeparatorItem) {
@ -91,6 +88,12 @@ class TimelineControllerInterceptorHelper(private val positionOfReadMarker: KMut
atLeastOneVisibleItemSinceLastDaySeparator = true
}
}
if (appendReadMarker) {
modelsIterator.addReadMarkerItem(callback)
index++
positionOfReadMarker.set(index)
appendReadMarker = false
}
index++
}
previousModelsSize = models.size
@ -103,8 +106,6 @@ class TimelineControllerInterceptorHelper(private val positionOfReadMarker: KMut
it.setOnVisibilityStateChanged(ReadMarkerVisibilityStateChangedListener(callback))
}
add(readMarker)
// Use next as we still have some process to do before the next iterator loop
next()
}
private fun MutableListIterator<EpoxyModel<*>>.removeCallItemIfNeeded(