package com.bjzc.bhzhgd.utils;



import com.yolanda.nohttp.rest.OnResponseListener;
import com.yolanda.nohttp.rest.Request;
import com.yolanda.nohttp.rest.Response;
import java.text.ParseException;

/**
 * NoHttp的封装
 */
public class HttpResponseListenerNoProgress<T> implements OnResponseListener {


    /**
     * 当前请求
     */
    private Request<T> mRequest;

    /**
     * 请求回调
     */
    private HttpListener<T> callback;



    /**
     * @param mRequest  请求
     * @param callback  请求回调
     */
    public HttpResponseListenerNoProgress(final Request<T> mRequest, HttpListener<T> callback) {
        this.mRequest = mRequest;
        this.callback = callback;
    }

    /**
     * 请求开始
     *
     * @param what
     */
    @Override
    public void onStart(int what) {

    }

    /**
     * 成功回调
     *
     * @param what
     * @param response
     */
    @Override
    public void onSucceed(int what, Response response) {
        if (callback != null) {
            try {
                callback.onSucceed(what, response);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 失败回调
     *
     * @param what
     * @param response
     */
    @Override
    public void onFailed(int what, Response response) {
        if (callback != null)
            callback.onFailed(what, response);
    }

    /**
     * 请求结束
     *
     * @param what
     */
    @Override
    public void onFinish(int what) {
    }
}