Short question:
What is the correct way to handle database + network on the Paging library from Architecture components, using an API that uses page + size to load a new page and the BoundaryCallback
class?
Research and explanation
Currently the class BoundaryCallback
used in the paging library for architecture components, receives as parameter the instance of an element in the list without actual context of where this element is at. It happens in onItemAtFrontLoaded
and onItemAtEndLoaded
.
My Api is supposed to receive the page and the size of the page to load the next chunk of data. Boundary callback, added as part of the paged list builder, is supposed to tell you when to load the next page of data based on prefetch distance and page size.
Since the Api needs the page number and the size of the page to provide, I don't see a way to send that to the Api just by receiving one of the elements from the list as offered in onItemAtFrontLoaded
and onItemAtEndLoaded
. Checking the google examples in this link, they use the name of the last element to get the next one, but that doesn't fit an Api with page + size.
They also have another example with only network that uses PagedKeyedDatasource
, but there is no sample or clue on how to mix that with the database and the BoundaryCallback.
Edit: Only solutions I have found so far is to store the last loaded page on the shared preferences, but that sounds like a dirty trick.
Refer to https://github.com/googlesamples/android-architecture-components/issues/252#issuecomment-392119468 for official input on it.
pageIndex
-based API into DB long-term? – Subtractivepage
&pages
. when it uses keys to get the next page, this seems to be optimized for noSQL - while for SQL this does not necessarily make sense... and when following the logic from the GitHub comments; what if the key had meanwhile be deleted? – Gotthelf