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();
}
}
当使用expenseAdapter.refresh() 刷新适配器 时,当Pager 期望创建一个新实例时,重新使用了一个PagingSource 实例。确保传递给 Pager 的 pagingSourceFactory 总是返回一个新的 PagingSource 实例。 这是我用来获取数据的可流动对象。
任何帮助将不胜感激。