mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-18 04:50:08 +03:00
Open at unread: Do not show loading animation if already reached end
Change-Id: I90b0a92cddb779651983f69871fa1942f2f45785
This commit is contained in:
parent
581c0ffcb0
commit
d92ce97f84
4 changed files with 28 additions and 3 deletions
|
@ -139,6 +139,7 @@ interface Timeline {
|
|||
* Pagination state
|
||||
*/
|
||||
data class PaginationState(
|
||||
val hasLoadedAtLeastOnce: Boolean = false,
|
||||
val hasMoreToLoad: Boolean = true,
|
||||
val loading: Boolean = false,
|
||||
val inError: Boolean = false
|
||||
|
|
|
@ -229,7 +229,17 @@ internal class DefaultTimeline(private val roomId: String,
|
|||
Timber.v("$baseLogMessage: result $loadMoreResult")
|
||||
val hasMoreToLoad = loadMoreResult != LoadMoreResult.REACHED_END
|
||||
updateState(direction) {
|
||||
it.copy(loading = false, hasMoreToLoad = hasMoreToLoad)
|
||||
it.copy(loading = false, hasMoreToLoad = hasMoreToLoad, hasLoadedAtLeastOnce = true)
|
||||
}
|
||||
// Stop forward-loading animation also when backwards loading, if we know we have all already
|
||||
if (direction == Timeline.Direction.BACKWARDS) {
|
||||
updateState(Timeline.Direction.FORWARDS) {
|
||||
if (!it.hasLoadedAtLeastOnce && strategy.hasFullyLoadedForward()) {
|
||||
it.copy(hasMoreToLoad = false)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -263,10 +273,10 @@ internal class DefaultTimeline(private val roomId: String,
|
|||
|
||||
private fun initPaginationStates(eventId: String?) {
|
||||
updateState(Timeline.Direction.FORWARDS) {
|
||||
it.copy(loading = false, hasMoreToLoad = eventId != null)
|
||||
it.copy(loading = false, hasMoreToLoad = eventId != null, hasLoadedAtLeastOnce = false)
|
||||
}
|
||||
updateState(Timeline.Direction.BACKWARDS) {
|
||||
it.copy(loading = false, hasMoreToLoad = true)
|
||||
it.copy(loading = false, hasMoreToLoad = true, hasLoadedAtLeastOnce = false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -230,6 +230,10 @@ internal class LoadTimelineStrategy(
|
|||
return timelineChunk?.hasReachedLastForward().orFalse()
|
||||
}
|
||||
|
||||
fun hasFullyLoadedForward(): Boolean {
|
||||
return timelineChunk?.hasLoadedAllEventsForwards().orFalse()
|
||||
}
|
||||
|
||||
private fun RealmResults<ChunkEntity>.createTimelineChunk(): TimelineChunk? {
|
||||
return firstOrNull()?.let {
|
||||
return TimelineChunk(
|
||||
|
|
|
@ -121,6 +121,16 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity,
|
|||
}
|
||||
}
|
||||
|
||||
fun hasLoadedAllEventsForwards(recurse: Boolean = false): Boolean {
|
||||
return if (isLastForward.get()) {
|
||||
builtEvents.isNotEmpty() && timelineEventEntities.first(null)?.displayIndex == builtEvents.firstOrNull()?.displayIndex
|
||||
} else if (recurse) {
|
||||
nextChunk?.hasLoadedAllEventsForwards().orFalse()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun builtItems(includesNext: Boolean, includesPrev: Boolean): List<TimelineEvent> {
|
||||
val deepBuiltItems = ArrayList<TimelineEvent>(builtEvents.size)
|
||||
if (includesNext) {
|
||||
|
|
Loading…
Add table
Reference in a new issue