Skip to content

Instantly share code, notes, and snippets.

@rahulsainani
Last active May 13, 2021 16:37
Show Gist options
  • Save rahulsainani/d8833c36b375afe215371b8bc9f613d4 to your computer and use it in GitHub Desktop.
Save rahulsainani/d8833c36b375afe215371b8bc9f613d4 to your computer and use it in GitHub Desktop.
private tailrec suspend fun autoScrollFeaturesList() {
if (recyclerFeatures.canScrollHorizontally(DIRECTION_RIGHT)) {
recyclerFeatures.smoothScrollBy(SCROLL_DX, 0)
} else {
val firstPosition =
(recyclerFeatures.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
if (firstPosition != RecyclerView.NO_POSITION) {
val currentList = featuresAdapter.currentList
val secondPart = currentList.subList(0, firstPosition)
val firstPart = currentList.subList(firstPosition, currentList.size)
featuresAdapter.submitList(firstPart + secondPart)
}
}
delay(DELAY_BETWEEN_SCROLL_MS)
autoScrollFeaturesList()
}
private const val DELAY_BETWEEN_SCROLL_MS = 25L
private const val SCROLL_DX = 5
private const val DIRECTION_RIGHT = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment