package com.zhaohaoting.framework.requset;

import com.zhaohaoting.framework.mvchelper.okhttp.exception.RequestException;
import com.zhaohaoting.framework.mvchelper.task.Code;
import com.zhaohaoting.framework.mvchelper.task.imp.SimpleCallback;
import com.zhaohaoting.framework.utils.ToastUtils;

/**
 * author：Created by ZHT on 2017/12/8 10:32
 * email：526309416@qq.com
 * desc：数据回调 此处做了请求取消判断
 */
public abstract class NewNetWorkCallBack<DATA> extends SimpleCallback<DATA> {

    @Override
    public void onPostExecute(Object task, Code code, RequestException exception, DATA data) {
        if (code == Code.CANCEL) return;
        if (code == Code.SUCCESS) {
            onPostExecuteSuccess(task, data);
        } else {
            onPostExecuteFailed(task, exception);
        }
    }

    protected abstract void onPostExecuteFailed(Object task, RequestException exception);

    protected abstract void onPostExecuteSuccess(Object task, DATA data);

    protected void showException(RequestException exception) {
        ToastUtils.show(exception.getMessage());

    }

}
