package com.bjzc.zjdxj.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.LinearLayout;
import android.widget.TextView;
import com.bjzc.zjdxj.R;


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

public class AllCheckDialog extends Dialog {

    TextView tvTitle;

    TextView tvMsg;

    TextView dialogCancel;

    TextView dialogCommit;

    LinearLayout layDialogCancel;

    private AuditDialogListener listener;

    public AllCheckDialog(@NonNull Context context, String msg, AuditDialogListener listener) {
        super(context);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        setContentView(R.layout.layout_allcheck_dialog);
        findView();
        Window window = getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = (getScreenWidth(context)) * 2 / 3;
        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);
        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();
                }
            }
        });
    }

    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 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();

        void cancel();
    }
}