package com.littlesparkle.growler.library.http;

import com.littlesparkle.growler.library.http.api.Api;

import rx.Subscriber;

public abstract class BaseHttpSubscriber<T> extends Subscriber<T> {
    private IProgress mProgress;
    private IToast mToast;

    public BaseHttpSubscriber() {
        this(null, null);
    }

    public BaseHttpSubscriber(IProgress progress, IToast toast) {
        mProgress = progress;
        mToast = toast;
    }

    @Override
    public void onStart() {
        super.onStart();
        if (mProgress != null) {
            mProgress.showProgress();
        }
    }

    @Override
    public void onCompleted() {
        if (isUnsubscribed()) {
            this.unsubscribe();
        }
        if (mProgress != null) {
            mProgress.dismissProgress();
        }
    }

    @Override
    public void onError(Throwable e) {
        if (isUnsubscribed()) {
            this.unsubscribe();
        }
        if (mProgress != null) {
            mProgress.dismissProgress();
        }
        onError(Api.handleError(e));
    }

    protected void onError(String errorMessage) {
        if (mToast != null) {
            mToast.showToast(errorMessage);
        }
    }

    public interface IProgress {
        void showProgress();

        void dismissProgress();
    }

    public interface IToast {
        void showToast(String msg);

        void dismissToast();
    }
}

@@ -96,16 +96,69 @@
 api.Api;
+%0Aimport com.littlesparkle.growler.library.log.Logger;
 %0A%0Aimport
@@ -1244,32 +1244,87 @@
 age);%0A        %7D%0A
+        Logger.e(%22Got error message:%22 + errorMessage);%0A
     %7D%0A%0A    publi

add a log