/*
 * Copyright (c) 2015. Ncomz. All Rights Reserved
 */

package com.ntels.kneet.v3.view.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;

import com.ntels.kneet.v3.common.AppConfig;
public class CustomDialog {

    private AppConfig appConfig;
    private static final String  TAG             = CustomDialog.class.getSimpleName();
    public static final  long    DEFAULT_TIMEOUT = 5000;
    public final static  int     ENC_NOT         = 10200;
    public final static  int     ENC_AES         = 10201;
    private              boolean bDialog         = true;
    private OnMsgAlterToResult _msg_result_event;
    private Dialog             dialog;

    public CustomDialog() {

    }

    //    public void MsgAlert(Context ctx, final int iMsgNo) {
    //    public void MsgAlert(Context ctx, final int iMsgNo, int iMsgTitle) {
    //    public void MsgAlert(Context ctx, final int iMsgNo, int iMsgTitle, String sPositiveText, String sNegativeText) {
    //    public void MsgAlert(Context ctx, final int iMsgNo, String sMsg) {
    //    public void MsgAlert(Context ctx, final int iMsgNo, String sMsg, int iMsgTitle) {
    //    public void MsgAlert(Context ctx, final int iMsgNo, String sMsg, int iMsgTitle, String sPositiveText, String sNegativeText) {

    /**
     * <PRE>
     * 1. MethodName: MsgAlert
     * 2. ClassName :
     * 3. Comment   : message box dialog
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    public void MsgAlert(Context ctx, final int iMsgNo) {

        try {
            Dialog_Custom.Builder dialog_builder;
            dialog_builder = new Dialog_Custom.Builder(ctx);
            if ( iMsgNo != 0 ) {
                dialog_builder.setErrNo("MSG" + iMsgNo);
            }
            dialog_builder.setPositiveButton(new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 1);
                }
            });
            dialog_builder.setNegativeButton(new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 2);
                }
            });
            dialog_builder.setOnCancelListener(new AlertDialog.OnCancelListener() {
                @Override public void onCancel(DialogInterface dialog) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 2);
                }
            });
            dialog_builder.create().show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * <PRE>
     * 1. MethodName: MsgAlert
     * 2. ClassName :
     * 3. Comment   : message box dialog
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    public void MsgAlert(Context ctx, final int iMsgNo, String sMsg) {

        try {
            Dialog_Custom.Builder dialog_builder;
            dialog_builder = new Dialog_Custom.Builder(ctx);
            if ( iMsgNo != 0 ) {
                dialog_builder.setErrNo("MSG" + iMsgNo);
            }
            if ( !sMsg.equals("") ) {
                dialog_builder.setMessage(sMsg);
            }
            dialog_builder.setPositiveButton(new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 1);
                }
            });
            dialog_builder.setNegativeButton(new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 2);
                }
            });
            dialog_builder.setOnCancelListener(new AlertDialog.OnCancelListener() {
                @Override public void onCancel(DialogInterface dialog) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 2);
                }
            });
            dialog_builder.create().show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * <PRE>
     * 1. MethodName: MsgAlert
     * 2. ClassName :
     * 3. Comment   : message box dialog
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    public void MsgAlert(Context ctx, final int iMsgNo, int iMsgTitle) {

        try {
            Dialog_Custom.Builder dialog_builder;
            dialog_builder = new Dialog_Custom.Builder(ctx);
            if ( iMsgNo != 0 ) {
                dialog_builder.setErrNo("MSG" + iMsgNo);
            }
            dialog_builder.setTitle(iMsgTitle);
            dialog_builder.setPositiveButton(new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 1);
                }
            });
            dialog_builder.setNegativeButton(new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 2);
                }
            });
            dialog_builder.setOnCancelListener(new AlertDialog.OnCancelListener() {
                @Override public void onCancel(DialogInterface dialog) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 2);
                }
            });
            dialog_builder.create().show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * <PRE>
     * 1. MethodName: MsgAlert
     * 2. ClassName :
     * 3. Comment   : message box dialog
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    public void MsgAlert(Context ctx, final int iMsgNo, String sMsg, int iMsgTitle) {

        try {
            Dialog_Custom.Builder dialog_builder;
            dialog_builder = new Dialog_Custom.Builder(ctx);
            if ( iMsgNo != 0 ) {
                dialog_builder.setErrNo("MSG" + iMsgNo);
            }
            if ( !sMsg.equals("") ) {
                dialog_builder.setMessage(sMsg);
            }
            dialog_builder.setTitle(iMsgTitle);
            dialog_builder.setPositiveButton(new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 1);
                }
            });
            dialog_builder.setNegativeButton(new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 2);
                }
            });
            dialog_builder.setOnCancelListener(new AlertDialog.OnCancelListener() {
                @Override public void onCancel(DialogInterface dialog) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 2);
                }
            });
            dialog_builder.create().show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * <PRE>
     * 1. MethodName: MsgAlert
     * 2. ClassName :
     * 3. Comment   : message box dialog
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    public void MsgAlert(Context ctx, final int iMsgNo, int iMsgTitle, String sPositiveText, String sNegativeText) {

        try {
            Dialog_Custom.Builder dialog_builder;
            dialog_builder = new Dialog_Custom.Builder(ctx);
            if ( iMsgNo != 0 ) {
                dialog_builder.setErrNo("MSG" + iMsgNo);
            }
            dialog_builder.setTitle(iMsgTitle);

            dialog_builder.setPositiveButton(sPositiveText, new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 1);
                }
            });
            dialog_builder.setNegativeButton(sNegativeText, new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 2);
                }
            });
            dialog_builder.setOnCancelListener(new AlertDialog.OnCancelListener() {
                @Override public void onCancel(DialogInterface dialog) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 2);
                }
            });
            dialog_builder.create().show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * <PRE>
     * 1. MethodName: MsgAlert
     * 2. ClassName :
     * 3. Comment   : message box dialog
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    public void MsgAlert(Context ctx, final int iMsgNo, String sMsg, int iMsgTitle, String sPositiveText, String sNegativeText) {

        try {
            Dialog_Custom.Builder dialog_builder;
            dialog_builder = new Dialog_Custom.Builder(ctx);
            if ( iMsgNo != 0 ) {
                dialog_builder.setErrNo("MSG" + iMsgNo);
            }
            if ( !sMsg.equals("") ) {
                dialog_builder.setMessage(sMsg);
            }
            dialog_builder.setTitle(iMsgTitle);

            dialog_builder.setPositiveButton(sPositiveText, new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 1);
                }
            });
            dialog_builder.setNegativeButton(sNegativeText, new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 2);
                }
            });

            dialog_builder.setOnCancelListener(new AlertDialog.OnCancelListener() {
                @Override public void onCancel(DialogInterface dialog) {

                    dialog.dismiss();
                    _msg_result_event.resultCustomDialogResponse(iMsgNo, 2);
                }
            });
            dialog_builder.create().show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public interface OnMsgAlterToResult {

        public void resultCustomDialogResponse(int iMsgID, int iBtnResult);
    }

    public void setOnMsgAlterToResultEvent(OnMsgAlterToResult _event) {

        if ( _event != null ) {
            this._msg_result_event = _event;
        }
    }
}
