After some time I got an idea, I've stopped listening to scroll on RecyclerView
and started listening to NestedScrollView
onScroll
event.
I managed to make my loadOnDemand recyclerView
using this snippet
nsv_posts_timeline.setOnScrollChangeListener(
NestedScrollView.OnScrollChangeListener {
_, scrollX, scrollY, _, oldScrollY ->
if(scrollY > oldScrollY){
val totalItens = timelineAdapter.itemCount
val currentView = rv_timeline.findChildViewUnder(scrollX.toFloat(), scrollY.toFloat())
val childPosition = rv_timeline.getChildAdapterPosition(currentView)
if((totalItens/2) - (stepSize/2) <= childPosition && !isLoading){
isLoading = true
//skip , take
timelinePresenter.loadMore(totalItens, 5)
}
}
})
isLoading
is a class property that I change to false when my callback returns from server