package com.ubt.jimu.base.http; import android.accounts.NetworkErrorException; import com.ubt.jimu.R; import com.ubt.jimu.widgets.LoadingView; import com.ubtrobot.log.ALog; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; /* loaded from: classes.dex */ public abstract class ApiObserver implements Observer { public static final int SHOW_LOADING = 1; public static final int SHOW_NO_LOADING = 0; private String TAG; private ApiErrorListener apiErrorListener; private boolean isRefrshing; private RequestComplete mComplete; private NetErrorListener mErrorListener; private int mLoading; private LoadingView mLoadingView; public interface ApiErrorListener { void onError(ApiResultException apiResultException); } public interface NetErrorListener { void onError(Throwable th); } public interface RequestComplete { void onComplete(); } public ApiObserver(LoadingView loadingView) { this(loadingView, 0); } @Override // io.reactivex.Observer public void onComplete() { ALog.a(this.TAG).d("ApiObserver onComplete"); LoadingView loadingView = this.mLoadingView; if (loadingView != null) { loadingView.b(); } RequestComplete requestComplete = this.mComplete; if (requestComplete != null) { requestComplete.onComplete(); } } @Override // io.reactivex.Observer public void onError(Throwable th) { try { ALog.a(this.TAG).d("t====" + th.getMessage()); if (this.mLoadingView != null) { this.mLoadingView.f(); } if (th instanceof NetworkErrorException) { if (this.mLoadingView != null) { this.mLoadingView.setServiceLoadingError(R.drawable.ic_network_error); this.mLoadingView.setServiceTextError(R.string.loading_error); } } else if (th instanceof NullPointerException) { if (this.mLoadingView != null) { this.mLoadingView.setServiceLoadingError(R.drawable.ic_network_error); this.mLoadingView.setServiceTextError(R.string.loading_error); } } else if (th instanceof ApiResultException) { ApiResultException apiResultException = (ApiResultException) th; if (this.apiErrorListener != null) { this.apiErrorListener.onError(apiResultException); } } else if (this.mLoadingView != null) { this.mLoadingView.setServiceLoadingError(R.drawable.ic_try_reload); this.mLoadingView.setServiceTextError(R.string.loading_service_error); } if (this.mErrorListener != null) { this.mErrorListener.onError(th); } } catch (Exception e) { e.printStackTrace(); } } @Override // io.reactivex.Observer public void onNext(T t) { } @Override // io.reactivex.Observer public void onSubscribe(Disposable disposable) { LoadingView loadingView = this.mLoadingView; if (loadingView != null && !this.isRefrshing) { loadingView.g(); } ALog.a(this.TAG).d(disposable.toString()); } public ApiObserver refreshOrLoad(boolean z) { this.isRefrshing = z; return this; } public ApiObserver setApiErrorListener(ApiErrorListener apiErrorListener) { this.apiErrorListener = apiErrorListener; return this; } public ApiObserver setNetErrorListener(NetErrorListener netErrorListener) { this.mErrorListener = netErrorListener; return this; } public ApiObserver setRequestComplete(RequestComplete requestComplete) { this.mComplete = requestComplete; return this; } public ApiObserver(LoadingView loadingView, int i) { this.TAG = "ApiObserver"; this.mLoading = 0; this.mLoading = i; this.mLoadingView = loadingView; } }