I've been trying to use the android paging library to get a full set of data from a paginated REST API by making multiple calls to the API and storing the returned data in a Room database for later use. The data doesn't ever need to be displayed directly in the UI, and this can all be done in the background.
I thought the paging library might work for this, but every example I've seen seems to involve lazy loading the data to the UI usually via LiveData and RecyclerView.
I've tried to follow some available examples (including android/architecture-components-samples PagingWithNetworkSample) and created a PageKeyedDataSource, a DataSource.Factory and a PagedList.
PagedList.build() triggers loadInitial() in the PageKeyedDataSource, but I seem to be stuck on how to trigger loadAfter() to make the subsequent api calls to get the full set of data.
It seems like calls to PagedList.loadAround() are the way to go, but I've been struggling to implement it, and wondering whether or not this is just a less than ideal use case for the paging library since there is no UI view component.
Executor fetchExecutor = Executors.newFixedThreadPool(5);
Executor notifyExecutor = Executors.newFixedThreadPool(5);
TrackAPIDataSourceFactory trackAPIDataSourceFactory =
new trackAPIDataSourceFactory(apiToken);
DataSource<Integer, Track> dataSource = trackAPIDataSourceFactory.create();
PagedList.Config pagedListConfig =
new PagedList.Config.Builder()
.setEnablePlaceholders(false)
.setPageSize(50).build();
PagedList<Track> pagedList =
new PagedList.Builder<>(dataSource, pagedListConfig)
.setFetchExecutor(fetchExecutor)
.setNotifyExecutor(notifyExecutor)
.build();