idanatz / OneAdapter

A Viewholderless Adapter for RecyclerView, who supports builtin diffing, states (paging, empty...), events (clicking, swiping...), and more.
MIT License
470 stars 45 forks source link

Can we call next page with Paging Module to load without scrolling #41

Closed palVikas9 closed 3 years ago

palVikas9 commented 3 years ago

Hi @ironsrc,

Thanks for the library. Have been using it quite a number of my projects but have recently ran into a problem that the API response has only 10 items and the UI doesn't cover whole page and due to that the scroll event of recyclerview is not called.

Is there any way or function can make the Paging module load the next page without scrolling.

Any help would be appreciated.

idanatz commented 3 years ago

Hi @palVikas9 can you share the paging module definition? please expand on the scenario, what's the current behavior and your expected behavior is it a bug or an API functionality addition - to be able to call the load page without scrolling? Thanks

palVikas9 commented 3 years ago

Hi @idanatz ,

Yeah, sure.

inner class PagingModuleImpl : PagingModule() { init { config { layoutResource = R.layout.layout_progress_bar visibleThreshold = 4 } onLoadMore { currentPage -> profileDetailViewModel.postPage = currentPage + 1 profileDetailViewModel.callGetUserPostAPI(selfUserId, profileDetailViewModel.postPage) } } }

It is a functionality that when I get the response from API call for page 1, then API call for the page 2 should be trigged by PagingModule of oneAdapter without scrolling of the recyclerview.

Right now, is there any existing way that we can do that ?`

idanatz commented 3 years ago

You are right, it's a bug and will be fixed in the next version - the onLoad will be triggered automatically when the conditions for paging are met after each data submission.

Regarding a quick-fix, I haven't found a way around it... since the RecyclerView is not scrollable in this usecase, the scroll listener is not being invoked in any programmatically way I tried.

But, you can try and trigger your logic manually when detecting this usecase by using the getVisibleItems() and verifing it's the same number as Items you got in your API response. It's not the cleanest way and you won't get the currentPage param but from your description its safe to assume its happening in the first API response so it will be 1.

palVikas9 commented 3 years ago

Thanks.

For the time being, I have added a workaround in my code.

If the condition for next api call is satisfied then it is called and in the loadmore, I call currentPage+2 instead of 1.

It is a lovely library to work with. Have made my life so much easier.

idanatz commented 3 years ago

Thanks for the kind words! a fix has been released with v2.1.1, check it out.