All examples of the new paging library have been with Room library and Room creates a Data Source for us. In my own case, I need to create my custom data source.
Here is
I think this can help:
1. countItems() should return DataSource.COUNT_UNDEFINED
2. loadRange(int startPosition, int count): You can directly execute your query.
3. So now you can delete result global variable
Also, turnoff placeholders:
listLiveData = p.create(0,new PagedList.Config.Builder()
.setPageSize(5) //number of items loaded at once
.setPrefetchDistance(10) //Must be >0 since placeholders are off
.setEnablePlaceholders(false)
.build());
Here is the updated code for Data Class:
public class DataClass extends TiledDataSource {
@Override
public int countItems() {
return DataSource.COUNT_UNDEFINED;
}
@Override
public List loadRange(int startPosition, int count) {
Call call = NetworkModule.providesWebService().makeRequest();
Response response = call.execute();
return parseJson(response.body());
}
You can check an example project here: https://github.com/brainail/.samples/tree/master/ArchPagingLibraryWithNetwork