package com.bjzc.bhzhgd.weight;



import android.app.Dialog;
import android.content.Context;
import androidx.annotation.NonNull;
import android.text.TextUtils;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bjzc.bhzhgd.R;


/**
 * Created by Rehome-rjb1 on 2017/5/31.
 * 是否审核的对话框
 */

public class LlsjDialog extends Dialog {

    TextView tvTitle;

    TextView tvMsg;

    TextView dialogCancel;

    TextView dialogCommit;

    LinearLayout layDialogCancel;

    EditText et_notice;

    private AuditDialogListener listener;

    public LlsjDialog(@NonNull Context context, String msg, AuditDialogListener listener) {
        super(context);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        setContentView(R.layout.layout_dqgz_llsj_dialog);
        findView();
        Window window = getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = (getScreenWidth(context)) * 3 / 4;
        window.setGravity(Gravity.CENTER);
        this.listener = listener;
        setCancelable(false);
        setTvMsg(msg);
    }

    private void findView() {
        tvTitle = findViewById(R.id.tv_title);
        tvMsg = findViewById(R.id.tv_msg);
        dialogCancel = findViewById(R.id.dialog_cancel);
        dialogCommit = findViewById(R.id.dialog_commit);
        layDialogCancel = findViewById(R.id.lay_dialog_cancel);
        et_notice = findViewById(R.id.et_notice);

        dialogCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (listener != null) {
                    listener.cancel();
                }
            }
        });

        dialogCommit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (listener != null) {
                    listener.confirm(et_notice.getText().toString().trim());
                }
            }
        });
    }


    public void setTvMsg(String msg) {
        if (!TextUtils.isEmpty(msg)) {
            tvMsg.setText(msg);
        }
    }

    public void setTvTitle(String title) {
        if (!TextUtils.isEmpty(title)) {
            tvTitle.setText(title);
        }
    }

    public void setNotice(String notice) {
        if (!TextUtils.isEmpty(notice)) {
            et_notice.setText(notice);
        }
    }

    public void hideNotice(String notice) {
        if (!TextUtils.isEmpty(notice)) {
            et_notice.setText(notice);
        }
    }

    //获取屏幕宽度
    public static int getScreenWidth(Context context) {
        WindowManager manager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        return display.getWidth();
    }

    public interface AuditDialogListener {
        void confirm(String notice);
        void cancel();
    }
}