Created
April 21, 2019 02:08
-
-
Save enginebai/bfcc5d09a022e9159746efb91b020dd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ...(略) | |
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