From 11a47041618fb251fa1c43e2ac01621717729df5 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 24 Sep 2020 17:48:42 +0200 Subject: [PATCH] Clean files and update CHANGES --- CHANGES.md | 1 + .../home/room/detail/RoomDetailFragment.kt | 1 - .../detail/timeline/TimelineEventController.kt | 17 ++++++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 23bc0427e9..9971ee6d65 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Features ✨: Improvements 🙌: - PIN code: request PIN code if phone has been locked + - Small optimisation of scrolling experience in timeline Bugfix 🐛: - Fix Splash layout on small screens diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index d03e6bad1e..e7140f06f4 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -81,7 +81,6 @@ import im.vector.app.core.glide.GlideRequests import im.vector.app.core.intent.getMimeTypeFromUri import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.resources.ColorProvider -import im.vector.app.core.ui.model.Size import im.vector.app.core.ui.views.ActiveCallView import im.vector.app.core.ui.views.ActiveCallViewHolder import im.vector.app.core.ui.views.ActiveConferenceView diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt index a04057882e..c266337520 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt @@ -56,6 +56,8 @@ import org.matrix.android.sdk.api.session.room.timeline.Timeline import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import javax.inject.Inject +private const val DEFAULT_PREFETCH_THRESHOLD = 30 + class TimelineEventController @Inject constructor(private val dateFormatter: VectorDateFormatter, private val contentUploadStateTrackerBinder: ContentUploadStateTrackerBinder, private val contentDownloadStateTrackerBinder: ContentDownloadStateTrackerBinder, @@ -192,11 +194,11 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec models.add(position, readMarker) } } - val shouldAdd = timeline?.hasMoreToLoad(Timeline.Direction.BACKWARDS) ?: false - if (shouldAdd) { + val shouldAddBackwardPrefetch = timeline?.hasMoreToLoad(Timeline.Direction.BACKWARDS) ?: false + if (shouldAddBackwardPrefetch) { val indexOfPrefetchBackward = (previousModelsSize - 1) + .coerceAtMost(models.size - DEFAULT_PREFETCH_THRESHOLD) .coerceAtLeast(0) - .coerceAtMost(models.size - 1) val loadingItem = LoadingItem_() .id("prefetch_backward_loading${System.currentTimeMillis()}") @@ -205,6 +207,15 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec models.add(indexOfPrefetchBackward, loadingItem) } + val shouldAddForwardPrefetch = timeline?.hasMoreToLoad(Timeline.Direction.FORWARDS) ?: false + if (shouldAddForwardPrefetch) { + val indexOfPrefetchForward = DEFAULT_PREFETCH_THRESHOLD.coerceAtMost(models.size - 1) + val loadingItem = LoadingItem_() + .id("prefetch_forward_loading${System.currentTimeMillis()}") + .showLoader(false) + .setVisibilityStateChangedListener(Timeline.Direction.FORWARDS) + models.add(indexOfPrefetchForward, loadingItem) + } previousModelsSize = models.size }