mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Timeline: check for create event to hide loader
This commit is contained in:
parent
8ca60eadbb
commit
3217277bc4
@ -83,18 +83,21 @@ interface Timeline {
|
||||
* The latest event is the first in the list
|
||||
* @param snapshot the most up to date snapshot
|
||||
*/
|
||||
fun onTimelineUpdated(snapshot: List<TimelineEvent>)
|
||||
fun onTimelineUpdated(snapshot: List<TimelineEvent>) = Unit
|
||||
|
||||
/**
|
||||
* Called whenever an error we can't recover from occurred
|
||||
*/
|
||||
fun onTimelineFailure(throwable: Throwable)
|
||||
fun onTimelineFailure(throwable: Throwable) = Unit
|
||||
|
||||
/**
|
||||
* Called when new events come through the sync
|
||||
*/
|
||||
fun onNewTimelineEvents(eventIds: List<String>)
|
||||
fun onNewTimelineEvents(eventIds: List<String>) = Unit
|
||||
|
||||
/**
|
||||
* Called when the pagination state has changed in one direction
|
||||
*/
|
||||
fun onStateUpdated(direction: Direction, state: PaginationState) = Unit
|
||||
}
|
||||
|
||||
|
@ -174,6 +174,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
||||
private var inSubmitList: Boolean = false
|
||||
private var hasReachedInvite: Boolean = false
|
||||
private var hasUTD: Boolean = false
|
||||
private var hasReachedCreateEvent: Boolean = false
|
||||
private var positionOfReadMarker: Int? = null
|
||||
private var partialState: PartialState = PartialState()
|
||||
|
||||
@ -286,7 +287,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
||||
return
|
||||
}
|
||||
// Avoid displaying two loaders if there is no elements between them
|
||||
val showBackwardsLoader = !showingForwardLoader || timelineModels.isNotEmpty()
|
||||
val showBackwardsLoader = (!showingForwardLoader || timelineModels.isNotEmpty()) && !hasReachedCreateEvent
|
||||
// We can hide the loader but still add the item to controller so it can trigger backwards pagination
|
||||
LoadingItem_()
|
||||
.id("backward_loading_item_$timestamp")
|
||||
@ -301,22 +302,6 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
||||
submitSnapshot(snapshot)
|
||||
}
|
||||
|
||||
override fun onTimelineFailure(throwable: Throwable) {
|
||||
// no-op, already handled
|
||||
}
|
||||
|
||||
override fun onNewTimelineEvents(eventIds: List<String>) {
|
||||
// no-op, already handled
|
||||
}
|
||||
|
||||
override fun onStateUpdated(direction: Timeline.Direction, state: Timeline.PaginationState) {
|
||||
if (!state.hasMoreToLoad) {
|
||||
backgroundHandler.post {
|
||||
requestDelayedModelBuild(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun submitSnapshot(newSnapshot: List<TimelineEvent>) {
|
||||
backgroundHandler.post {
|
||||
inSubmitList = true
|
||||
@ -471,10 +456,14 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
||||
private fun preprocessReverseEvents() {
|
||||
receiptsByEvent.clear()
|
||||
timelineEventsGroups.clear()
|
||||
hasReachedCreateEvent = false
|
||||
val itr = currentSnapshot.listIterator(currentSnapshot.size)
|
||||
var lastShownEventId: String? = null
|
||||
while (itr.hasPrevious()) {
|
||||
val event = itr.previous()
|
||||
if (!hasReachedCreateEvent && event.root.type == EventType.STATE_ROOM_CREATE) {
|
||||
hasReachedCreateEvent = true
|
||||
}
|
||||
timelineEventsGroups.addOrIgnore(event)
|
||||
val currentReadReceipts = ArrayList(event.readReceipts).filter {
|
||||
it.user.userId != session.myUserId
|
||||
|
Loading…
Reference in New Issue
Block a user