package com.littlesparkle.growler.library.http;

import com.littlesparkle.growler.library.http.api.Api;
import com.littlesparkle.growler.library.http.api.ApiException;
import com.littlesparkle.growler.library.log.Logger;

import rx.Subscriber;

public abstract class BaseHttpSubscriber<T> extends Subscriber<T> {
    public BaseHttpSubscriber() {
    }

    @Override
    public void onCompleted() {
        if (isUnsubscribed()) {
            this.unsubscribe();
        }
    }

    @Override
    public void onError(Throwable e) {
        Logger.e("onError: " + e.getMessage());
        if (isUnsubscribed()) {
            this.unsubscribe();
        }
        onError(Api.handleError(e));
    }

    protected abstract void onError(String errorMessage);
}

@@ -101,250 +101,671 @@
 pi;%0A
+%0A
 import 
-com.littlesparkle.growler.library.http.api.ApiException;%0Aimport com.littlesparkle.growler.library.log.Logger;%0A%0Aimport rx.Subscriber;%0A%0Apublic abstract class BaseHttpSubscriber%3CT%3E extends Subscriber%3CT%3E %7B%0A    public BaseHttpSubscriber() %7B
+rx.Subscriber;%0A%0Apublic abstract class BaseHttpSubscriber%3CT%3E extends Subscriber%3CT%3E %7B%0A    private IProgress mProgress;%0A    private IToast mToast;%0A%0A    public BaseHttpSubscriber() %7B%0A        this(null, null);%0A    %7D%0A%0A    public BaseHttpSubscriber(IProgress progress) %7B%0A        this(progress, null);%0A    %7D%0A%0A    public BaseHttpSubscriber(IToast toast) %7B%0A        this(null, toast);%0A    %7D%0A%0A    public BaseHttpSubscriber(IProgress progress, IToast toast) %7B%0A        mProgress = progress;%0A        mToast = toast;%0A    %7D%0A%0A    @Override%0A    public void onStart() %7B%0A        super.onStart();%0A        if (mProgress != null) %7B%0A            mProgress.showProgress();%0A        %7D
 %0A   
@@ -880,32 +880,116 @@
 be();%0A        %7D%0A
+        if (mProgress != null) %7B%0A            mProgress.dismissProgress();%0A        %7D%0A
     %7D%0A%0A    @Over
@@ -1036,56 +1036,8 @@
 ) %7B%0A
-        Logger.e(%22onError: %22 + e.getMessage());%0A
     
@@ -1098,32 +1098,116 @@
 be();%0A        %7D%0A
+        if (mProgress != null) %7B%0A            mProgress.dismissProgress();%0A        %7D%0A
         onError(
@@ -1248,25 +1248,16 @@
 otected 
-abstract 
 void onE
@@ -1281,12 +1281,308 @@
 Message)
-;
+ %7B%0A        if (mToast != null) %7B%0A            mToast.showToast(errorMessage);%0A        %7D%0A    %7D%0A%0A    public interface IProgress %7B%0A        void showProgress();%0A%0A        void dismissProgress();%0A    %7D%0A%0A    public interface IToast %7B%0A        void showToast(String msg);%0A%0A        void dismissToast();%0A    %7D
 %0A%7D%0A

add Progress&Toast in subscriber