Search in sources :

Example 1 with BlogResponse

use of com.mindorks.framework.mvp.data.network.model.BlogResponse in project android-mvp-architecture by MindorksOpenSource.

the class BlogPresenter method onViewPrepared.

@Override
public void onViewPrepared() {
    getMvpView().showLoading();
    getCompositeDisposable().add(getDataManager().getBlogApiCall().subscribeOn(getSchedulerProvider().io()).observeOn(getSchedulerProvider().ui()).subscribe(new Consumer<BlogResponse>() {

        @Override
        public void accept(@NonNull BlogResponse blogResponse) throws Exception {
            if (blogResponse != null && blogResponse.getData() != null) {
                getMvpView().updateBlog(blogResponse.getData());
            }
            getMvpView().hideLoading();
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(@NonNull Throwable throwable) throws Exception {
            if (!isViewAttached()) {
                return;
            }
            getMvpView().hideLoading();
            // handle the error here
            if (throwable instanceof ANError) {
                ANError anError = (ANError) throwable;
                handleApiError(anError);
            }
        }
    }));
}
Also used : Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) BlogResponse(com.mindorks.framework.mvp.data.network.model.BlogResponse) ANError(com.androidnetworking.error.ANError)

Aggregations

ANError (com.androidnetworking.error.ANError)1 BlogResponse (com.mindorks.framework.mvp.data.network.model.BlogResponse)1 NonNull (io.reactivex.annotations.NonNull)1 Consumer (io.reactivex.functions.Consumer)1