use of com.example.android.architecture.blueprints.todoapp.data.source.TasksDataSource in project todo-mvp-rxjava by albertizzy.
the class TasksPresenter method loadTasks.
/**
* @param forceUpdate Pass in true to refresh the data in the {@link TasksDataSource}
* @param showLoadingUI Pass in true to display a loading icon in the UI
*/
private void loadTasks(final boolean forceUpdate, final boolean showLoadingUI) {
if (showLoadingUI) {
mTasksView.setLoadingIndicator(true);
}
if (forceUpdate) {
mTasksRepository.refreshTasks();
}
// The network request might be handled in a different thread so make sure Espresso knows
// that the app is busy until the response is handled.
// App is busy until further notice
EspressoIdlingResource.increment();
mCompositeDisposable.clear();
Disposable disposable = mTasksRepository.getTasks().flatMap(Flowable::fromIterable).filter(task -> {
switch(mCurrentFiltering) {
case ACTIVE_TASKS:
return task.isActive();
case COMPLETED_TASKS:
return task.isCompleted();
case ALL_TASKS:
default:
return true;
}
}).toList().subscribeOn(mSchedulerProvider.io()).observeOn(mSchedulerProvider.ui()).doFinally(() -> {
if (!EspressoIdlingResource.getIdlingResource().isIdleNow()) {
// Set app as idle.
EspressoIdlingResource.decrement();
}
}).subscribe(// onNext
tasks -> {
processTasks(tasks);
mTasksView.setLoadingIndicator(false);
}, // onError
throwable -> mTasksView.showLoadingTasksError());
mCompositeDisposable.add(disposable);
}
Aggregations