Skip to content

Instantly share code, notes, and snippets.

@enginebai
Created April 21, 2019 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enginebai/bfcc5d09a022e9159746efb91b020dd1 to your computer and use it in GitHub Desktop.
Save enginebai/bfcc5d09a022e9159746efb91b020dd1 to your computer and use it in GitHub Desktop.
// ...(略)
mPresenter.loadFirstPage()
mList.addOnScrollListener(object : RecyclerView.OnScrollListener() {
var mShouldReload = false
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
val layoutManager = recyclerView.layoutManager as LinearLayoutManager
val firstVisibleItem = layoutManager.findFirstVisibleItemPosition()
val visibleItemCount = layoutManager.childCount
val totalItemCount: Int = layoutManager.itemCount
mShouldReload = firstVisibleItem + visibleItemCount == totalItemCount && dy > 0
}
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (newState == RecyclerView.SCROLL_STATE_IDLE && mShouldReload)
mPresenter.loadNextPage()
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment