homeViewModel.pagingDataFlow.subscribe(expensesPagingData -> {
expenseAdapter.submitData(getLifecycle(), expensesPagingData);
}, throwable -> Log.e(TAG, "onCreate: " + throwable.getMessage()));
// ViewModel
private void init() {
pagingDataFlow = homeRepository.init();
CoroutineScope coroutineScope = ViewModelKt.getViewModelScope(this);
PagingRx.cachedIn(pagingDataFlow, coroutineScope);
}
// Repository
public Flowable<PagingData<ExpensesModel>> init() {
// Define Paging Source
expensePagingSource = new ExpensePagingSource(feDataService);
// Create new Pager
Pager<Integer, ExpensesModel> pager = new Pager<Integer, ExpensesModel>(
new PagingConfig(10,
10,
false,
10,
100),
() -> expensePagingSource); // set paging source
// inti Flowable
pagingDataFlow = PagingRx.getFlowable(pager);
return pagingDataFlow;
}
I have tried to invalidate still not working.
public void invalidatePageSource() {
if (expensePagingSource != null) {
expensePagingSource.invalidate();
}
}
When refreshing the adapter using expenseAdapter.refresh() An instance of PagingSource was re-used when Pager expected to create a newinstance. Ensure that the pagingSourceFactory passed to Pager always returns a new instance of PagingSource. This my floawable object which I am using to get data.
Any help will be appreciated.
So instead of
val pagingSource = PagingSource()
return Pager() {
pagingSource
}.flow
Use this
return Pager() {
PagingSource()
}.flow
Basically it helps store the reference of paging resource which is later used by adapter to call invalidate on it when you call refresh().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With