Android library to simplify implementation of pagination functionality (load more) on RecyclerView
This library is available on jitpack.io.
Add this in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
implementation 'com.github.I3eyonder:paging-supporter:x.y.z'
val pagingSupporter = PagingSupporter.setupFor(recyclerView) {
setTriggerThreshold(5)
setReverseScroll(true) // reverse scroll direction to load more. Default is false (scroll from top to bottom)
setLoadMoreCallback { currentItemCount, state ->
state.isLoading = true // notify new items are loading...
// load more data
state.nextToken = Any // saving next token for next load more request if needed
state.isLoading = false // notify loading done
state.hasMoreData =
false // mark that no more data available, so do not trigger loading any more.
}
setOnLoadingChangedListener {
// show or hide some UI element based on loading state
}
}.install()
There is also have RecyclerView
extensions
recyclerView.setupPagingSupporter {
setTriggerThreshold(5)
}.install()
LoadMoreState
is also available via PagingSupporter#loadMoreState
PagingSupporter
provide uninstall()
method to remove load more functionality from RecyclerView
.
PagingSupporter.Builder#setLoadMoreScrollHandler()
allow you to supply custom implementation
of LoadMoreScrollHandler
to support different LayoutManager
than LinearLayoutManager
,GridLayoutManager
and StaggeredGridLayoutManager
PagingSupporter.setupFor(recyclerView) {
setLoadMoreScrollHandler(object : LoadMoreScrollHandler<FlexboxLayoutManager> {
override fun firstVisiblePosition(layoutManager: FlexboxLayoutManager): Int {
TODO("Not yet implemented")
}
override fun lastVisiblePosition(layoutManager: FlexboxLayoutManager): Int {
TODO("Not yet implemented")
}
override fun isScrollingCorrectDirection(
layoutManager: FlexboxLayoutManager,
dx: Int,
dy: Int,
isReverseScroll: Boolean
): Boolean {
TODO("Not yet implemented")
}
override fun shouldTriggerLoadMore(
layoutManager: FlexboxLayoutManager,
firstVisiblePosition: Int,
lastVisiblePosition: Int,
totalItem: Int,
triggerThreshold: Int,
isReverseScroll: Boolean
): Boolean {
TODO("Not yet implemented")
}
})
}.install()
Refer LinearLoadMoreScrollHandler
for implementation
Copyright 2022 Hieu Pham
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.