I'm using Paging library to load date directly from network. Do I have to implement logic to stop fetching data? In my case, that can be when received item count is lower than page size. Currently when I reach end of list lib keeps loading new pages.
Paging library - Can't stop loading items
Are you using Room + DataSource.Factory with BoundaryCallback, or item keyed data source? –
Heaney
@Heaney I'm using PageKeyedDataSource. Data is fetched directly from network without storing it locally. –
Nanice
Theoretically, PageKeyedDataSource has a result callback,
PageKeyedDataSource.LoadCallback
And that has an onResult
method, where the docs says
Pass an empty list if there is no more data to load.
Pass the key for the subsequent page to load to adjacentPageKey. For example, if you've loaded a page in loadBefore(LoadParams, LoadCallback), pass the key for the previous page, or null if the loaded page is the first. If in loadAfter(LoadParams, LoadCallback), pass the key for the next page, or null if the loaded page is the last.
So it says you should pass an empty list, and null
for adjacent page key, and it should work.
I already tried with empty list and it is working, but last data chunk is not shown in the list. Let me try with null as adjacentPageKey. –
Nanice
Yep, that's it. Thanks. –
Nanice
What if url don't have any page number to pass?@Heaney@Nanice –
Yeomanry
Well if the api paginates then the question is what parameter you can send in to do that. If you can't, then there's probably no paging. If you get full dataset then you can save to disk then use positional datasource (Room can generate it) –
Heaney
Is there any way to keep loading even though the list is empty or less the requestLoadSize? My page size is 10, and if the endpoint I call has less than 10 items, it loads, stops and do not call the next endpoint. I would like to keep calling the endpoints even though I received a list less than 10 in size. Any hint? –
Gunplay
© 2022 - 2024 — McMap. All rights reserved.