Skip to content

Commit

Permalink
Pre fetch next page
Browse files Browse the repository at this point in the history
  • Loading branch information
ashiagr committed Mar 10, 2023
1 parent 59b4879 commit 0fd13a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 0fd13a5

Please sign in to comment.