Commit 4f55f2fe by sikang

update HttpOberver

parent 5e2e515d
...@@ -54,7 +54,7 @@ public class BasePresenter<T> { ...@@ -54,7 +54,7 @@ public class BasePresenter<T> {
observable.subscribeOn(Schedulers.io()) observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.compose(view.<T>bindToLifecycle()) .compose(view.<T>bindToLifecycle())
.subscribe(new HttpObserver<T>() { .subscribe(new HttpObserver<T>(action) {
@Override @Override
public void onStart() { public void onStart() {
view.onHttpStart(action, true); view.onHttpStart(action, true);
......
...@@ -9,9 +9,11 @@ import io.reactivex.disposables.Disposable; ...@@ -9,9 +9,11 @@ import io.reactivex.disposables.Disposable;
import retrofit2.HttpException; import retrofit2.HttpException;
import tech.starwin.R; import tech.starwin.R;
import tech.starwin.LibConfig; import tech.starwin.LibConfig;
import com.common.bean.BasicAck; import com.common.bean.BasicAck;
import com.common.bean.ResponseErrorBody; import com.common.bean.ResponseErrorBody;
import com.common.bean.UpdateBean; import com.common.bean.UpdateBean;
import tech.starwin.network.Error; import tech.starwin.network.Error;
import tech.starwin.utils.LogUtils; import tech.starwin.utils.LogUtils;
import tech.starwin.utils.LoginManager; import tech.starwin.utils.LoginManager;
...@@ -21,6 +23,16 @@ import tech.starwin.utils.LoginManager; ...@@ -21,6 +23,16 @@ import tech.starwin.utils.LoginManager;
* HTTP请求回调 * HTTP请求回调
*/ */
public abstract class HttpObserver<T> implements Observer<T> { public abstract class HttpObserver<T> implements Observer<T> {
private String action;
public HttpObserver() {
}
public HttpObserver(String action) {
this.action = action;
}
private Disposable disposable; private Disposable disposable;
public abstract void onStart(); public abstract void onStart();
...@@ -48,7 +60,7 @@ public abstract class HttpObserver<T> implements Observer<T> { ...@@ -48,7 +60,7 @@ public abstract class HttpObserver<T> implements Observer<T> {
public void onError(Throwable throwable) { public void onError(Throwable throwable) {
onFinish(); onFinish();
String msg = throwable.getMessage(); String msg = throwable.getMessage();
LogUtils.d("HttpObserver", "error msg : " + msg); LogUtils.d("HttpObserver", action+" -> error msg : " + msg);
try { try {
if (throwable != null) { if (throwable != null) {
if (isNetworkError(msg)) { if (isNetworkError(msg)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment