From 0fd13a53c245222a5aa83adee92fc322175f78b1 Mon Sep 17 00:00:00 2001 From: ashiagr Date: Fri, 10 Mar 2023 13:32:53 +0530 Subject: [PATCH] Pre fetch next page --- .../discover/util/ScrollingLinearLayoutManager.kt | 12 +++++++++++- .../pocketcasts/discover/view/DiscoverAdapter.kt | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/features/discover/src/main/java/au/com/shiftyjelly/pocketcasts/discover/util/ScrollingLinearLayoutManager.kt b/modules/features/discover/src/main/java/au/com/shiftyjelly/pocketcasts/discover/util/ScrollingLinearLayoutManager.kt index 38e1e7b643e..262ca19bf0f 100644 --- a/modules/features/discover/src/main/java/au/com/shiftyjelly/pocketcasts/discover/util/ScrollingLinearLayoutManager.kt +++ b/modules/features/discover/src/main/java/au/com/shiftyjelly/pocketcasts/discover/util/ScrollingLinearLayoutManager.kt @@ -6,7 +6,10 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearSmoothScroller import androidx.recyclerview.widget.RecyclerView -/* Increases scrolling speed of recyclerView.smoothScrollToPosition(position) */ +/* +1. Increases scrolling speed of recyclerView.smoothScrollToPosition(position) +2. Sets custom extra layout space for pre caching an extra page +*/ class ScrollingLinearLayoutManager( context: Context?, orientation: Int, @@ -27,6 +30,13 @@ class ScrollingLinearLayoutManager( startSmoothScroll(linearSmoothScroller) } + /* By default, LinearLayoutManager lays out 1 extra page of items while smooth scrolling, in the direction of the scroll. + This behavior is overridden to lay out an extra page even on a manual swipe. */ + override fun calculateExtraLayoutSpace(state: RecyclerView.State, extraLayoutSpace: IntArray) { + extraLayoutSpace[0] = 0 + extraLayoutSpace[1] = this.width + } + companion object { private const val MILLISECONDS_PER_INCH = 100f // default is 25f (bigger = slower) } diff --git a/modules/features/discover/src/main/java/au/com/shiftyjelly/pocketcasts/discover/view/DiscoverAdapter.kt b/modules/features/discover/src/main/java/au/com/shiftyjelly/pocketcasts/discover/view/DiscoverAdapter.kt index e52dad5c170..237ba041dbd 100644 --- a/modules/features/discover/src/main/java/au/com/shiftyjelly/pocketcasts/discover/view/DiscoverAdapter.kt +++ b/modules/features/discover/src/main/java/au/com/shiftyjelly/pocketcasts/discover/view/DiscoverAdapter.kt @@ -79,7 +79,7 @@ import au.com.shiftyjelly.pocketcasts.ui.R as UR private const val MAX_ROWS_SMALL_LIST = 20 private const val CURRENT_PAGE = "current_page" private const val TOTAL_PAGES = "total_pages" -private const val INITIAL_PREFETCH_COUNT = 3 +private const val INITIAL_PREFETCH_COUNT = 1 internal data class ChangeRegionRow(val region: DiscoverRegion)