package com.danding.yang800.View;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.danding.yang800.R;

public class MyDialog extends Dialog {

    private Context context = null;

    private TextView msgText;
    private TextView msg_remark;
    private TextView titleText;
    private TextView okBtn;
    private TextView cancelBtn;

    public static MyDialog createBuilder(Context context) {
        return new MyDialog(context);
    }

    public MyDialog(Context context) {
        this(context, R.style.CustomDialog);
        this.context = context;

    }

    public MyDialog(Context context, boolean cancelable,
                    OnCancelListener cancelListener) {

        super(context, cancelable, cancelListener);
        this.context = context;
    }

    public MyDialog(Context context, int theme) {

        super(context, theme);
        this.context = context;
        setDialogContentView();
    }

    private void setDialogContentView() {

        View view = LayoutInflater.from(context).inflate(R.layout.showdialog_ok_cancel, null);
        titleText = (TextView) view.findViewById(R.id.title_text);
        msgText = (TextView) view.findViewById(R.id.msg_text);
        msg_remark = (TextView) view.findViewById(R.id.msg_remark);
        okBtn = (TextView) view.findViewById(R.id.ok_btn);
        cancelBtn = (TextView) view.findViewById(R.id.cancel_btn);
        cancelBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                MyDialog.this.dismiss();
            }
        });
        okBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                MyDialog.this.dismiss();
            }
        });
        setContentView(view);

    }

    public void setOKOnClickListener(View.OnClickListener listener) {
        okBtn.setOnClickListener(listener);
    }

    public void setOnCancelListener(View.OnClickListener listener) {
        cancelBtn.setOnClickListener(listener);
    }


    public MyDialog setMsg(String msg) {

        if (null != msgText) {
            msgText.setText(msg);
        }
        return this;
    }

    public MyDialog setRemark(String msg) {

        if (null != msg_remark) {
            msg_remark.setVisibility(View.VISIBLE);
            msg_remark.setText(msg);
        }
        return this;
    }

    public MyDialog setMsg(int resId) {

        if (null != msgText) {
            msgText.setText(context.getString(resId));
        }
        return this;
    }

    public MyDialog setAlertTitle(String t) {

        if (null != titleText) {
            titleText.setText(t);
        }
        return this;
    }

    public MyDialog setAlertTitle(int resId) {

        if (null != titleText) {
            titleText.setText(context.getString(resId));
        }

        return this;

    }

}