- DataSource
extends RxPagingSource
@NotNull
@Override
public Single<LoadResult<Integer, L>> loadSingle(@NotNull LoadParams<Integer> params) {
nextPageNumber = params.getKey();
if (nextPageNumber == null) {
nextPageNumber = 1;
}
return getApiRequest(nextPageNumber, params.getLoadSize())
.subscribeOn(Schedulers.io())
.map(d -> toLoadResult(params, d))
.onErrorReturn(LoadResult.Error::new);
}
protected LoadResult<Integer, L> toLoadResult(LoadParams<Integer> params, D response) {}
- Handle datasource in ViewModel
Flowable<PagingData<PojoPassengerData>> flowable = PagingRx.getFlowable(
new Pager<>(new PagingConfig(TOTAL_PAGES), () -> new FakeTestSource(mApiService)));
PagingRx.cachedIn(flowable, viewModelScope);
mCompositeDisposable.add(
flowable.subscribe(pagingData -> dataPagingData = pagingData));
- Handle in Fragment
adapter.submitData(getViewLifeCycle(), mViewModel.dataPagingData);
- Not refresh data by called here
private void onRefresh() {
mViewModel.showSwipeRefresh();
adapter.refresh();
}
I'm using Paging3 (3.0.1 Latest) and setup with Recycler view.
Load more working Retry working (with is called as
adapter.retry()
)
NOTE: Setup paging in RxJava so comment based on that.
Thanks in advance.