package insat.unotifier.util;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;

import insat.unotifier.RegisterActivity;
import insat.unotifier.Unotifier;
import insat.unotifier.common.Config;

import org.json.JSONObject;

public class ProcessRegister extends AsyncTask<String, String, JSONObject> {

    private ProgressDialog pDialog;
    private Context context;

    public ProcessRegister(Context context) {
        super();
        this.context = context;
    }
    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        /*pDialog = new ProgressDialog(context);
        pDialog.setTitle("Contacting Servers");
        pDialog.setMessage("Registering ...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();*/
    }

    @Override
    protected JSONObject doInBackground(String... args) {
        String token = args[1];
        String identifiant = args[0];
        Device device =new Device(identifiant,token);
        DeviceFunctions deviceFunctions = new DeviceFunctions();
        JSONObject json = deviceFunctions.registerUser(device);
        return json;

    }

    @Override
    protected void onPostExecute(JSONObject json) {
        /**
         * Checks for success message.
         **/
   /*     try {
            if (json.getString(Config.KEY_ERROR) != null) {

                String res = json.getString(Config.KEY_ERROR);
                    Unotifier.msg=json.getString(Config.KEY_ERROR);
                    Unotifier.notFirstUse = true;
            }
        } catch (Exception e) {
            e.printStackTrace();

        }*/
    }
}