package ai.pai.lensman.utils;

import android.os.AsyncTask;

import com.android.common.http.HttpUtils;

import java.util.HashMap;

import ai.pai.lensman.BuildConfig;


public  class HttpPostTask extends AsyncTask<String,Integer,Boolean> {


    private HashMap<String,String> httpParams;

    public HttpPostTask(HashMap<String,String> httpParams){
        this.httpParams = httpParams;
    }

    @Override
    protected Boolean doInBackground(String... params) {
        String rootUrl = params[0];
        if(rootUrl.contains("?")){
            rootUrl+="&platform=android";
        }else{
            rootUrl+="?platform=android";
        }
        rootUrl+="&version="+ BuildConfig.VERSION_NAME;
        rootUrl+="&channel="+"guanwang";
        String response= HttpUtils.doHttpPost(rootUrl,httpParams);
        return parseResponse(response);
    }

    @Override
    protected void onPostExecute(Boolean result) {
        super.onPostExecute(result);
        if(result){
            onPostSuccess();
        }else{
            onPostFail();
        }
    }

    protected  boolean parseResponse(String response){return true;}

    protected void onPostFail(){ }

    protected  void onPostSuccess(){ }



}
