package insat.unotifier.util;

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

import org.json.JSONObject;

import insat.unotifier.common.Config;

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

    private ProgressDialog pDialog;
    private Context context;

    public ProcessRegisterView(Context context) {
        super();
        this.context = context;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        /*pDialog = new ProgressDialog(context);
        pDialog.setTitle("Contacting U-notifier Server");
        pDialog.setMessage("Loading ...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();*/
    }

    @Override
    protected JSONObject doInBackground(String... args) {
        String idMsg = args[0];
        DeviceFunctions deviceFunctions=new DeviceFunctions();
        JSONObject json = deviceFunctions.registerView(idMsg);
        return json;

    }

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

                String res = json.getString(Config.KEY_SUCCESS);
                String red = json.getString(Config.KEY_ERROR);

                if (Integer.parseInt(res) == 1) {
                    Toast.makeText(context, " Successfully Registered",
                            Toast.LENGTH_SHORT).show();

                    pDialog.dismiss();

                } else if (Integer.parseInt(red) == 400) {
                    pDialog.dismiss();
                    Toast.makeText(context,
                            "JSON Error occured in Registartion",
                            Toast.LENGTH_SHORT).show();
                } else if (Integer.parseInt(red) == 401) {
                    pDialog.dismiss();
                    Toast.makeText(context, "JSON ERROR", Toast.LENGTH_SHORT)
                            .show();                }

            } else {
                pDialog.dismiss();
                Toast.makeText(context, "Error occured in registration",
                        Toast.LENGTH_SHORT).show();
            }

        } catch (Exception e) {
            e.printStackTrace();

        }*/
    }
}