Skip to content

Instantly share code, notes, and snippets.

@PhamNgocPhi
Created March 13, 2020 09:09
Show Gist options
  • Save PhamNgocPhi/20544d347a511de093f16f1bc55f4366 to your computer and use it in GitHub Desktop.
Save PhamNgocPhi/20544d347a511de093f16f1bc55f4366 to your computer and use it in GitHub Desktop.
void callApi() {
disposable.add(apiService.callApi()
.doOnSubscribe(it -> {
// thông báo cho view hiển thị loading
mViewState.setValue(Define.ViewState.SHOW_LOADING)
})
.doFinally(() -> {
// thông báo cho view ẩn loading vì chúng ta đã call api xong
mViewState.setValue(Define.ViewState.HIDE_LOADING)
})
.subscribe(response -> {
// call api success
// làm 1 vài bước biến đổi response hoặc gửi dữ liệu tới view để hiện thị
}, throwable -> {
handleThrowable(throwable);
// thông báo cho view ẩn loading và show lỗi
mViewState.setValue(Define.ViewState.SHOW_ERROR)
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment