I am trying to implement the new paging library from android architecture components. Basic functions are working fine but I need to add a retry function for loadRange()
or loadAfter()
. I need to retry these in case a network error occurs or if the device is offline. I already tried dataSource.invalidate()
which throws away the whole data source which seems like a waste. Is there a way to do this?
Here is my code:
public class MyDataSource extends PositionalDataSource<Item> {
...
@Override
public void loadInitial(@NonNull LoadInitialParams params, @NonNull LoadInitialCallback<Item> callback) {
ArrayList<Item> items = executeCall(1, params.requestedLoadSize);
if (items != null) {
callback.onResult(items, 0, totalCount);
} else {
callback.onResult(new ArrayList<Item>(), 0);
}
}
@Override
public void loadRange(@NonNull LoadRangeParams params, @NonNull LoadRangeCallback<Item> callback) {
ArrayList<Item> items = executeCall(params.startPosition, params.loadSize);
if (items != null) {
callback.onResult(items);
} else {
callback.onResult(new ArrayList<Item>());
}
}
...
}