package com.miraclegarden.smsmessage;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.miraclegarden.smsmessage.databinding.DialogDeleteConfirmBinding;


/**
 * 通用弹窗
 */
public class DeleteConfirmDialog extends Dialog {
    DialogDeleteConfirmBinding dialogActionConfirmBinding;
    OnToActionListener onToActionListener;
    MessageInfo messageInfo;
    public interface OnToActionListener {
        void toSumbit();
    }

    public void setOnToActionListener(OnToActionListener onNextCallListener) {
        this.onToActionListener = onNextCallListener;
    }


    public DeleteConfirmDialog(Context context, MessageInfo messageInfo) {
        super(context, R.style.MaterialDesignDialog);
        this.messageInfo = messageInfo;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        dialogActionConfirmBinding = DialogDeleteConfirmBinding.inflate(getLayoutInflater());
        setContentView(dialogActionConfirmBinding.getRoot());
        dialogActionConfirmBinding.contentTv.setText("删除"+messageInfo.getAppName()+"监听");

        dialogActionConfirmBinding.sumbitTv.setOnClickListener(v -> {
            dismiss();
            if(onToActionListener!=null){
                onToActionListener.toSumbit();
            }
        });
        dialogActionConfirmBinding.cancelTv.setOnClickListener(v -> {
            dismiss();
        });

        Window window = getWindow();
        WindowManager.LayoutParams wlp = window.getAttributes();
        wlp.gravity = Gravity.CENTER;
        wlp.width = WindowManager.LayoutParams.WRAP_CONTENT;
        wlp.height = WindowManager.LayoutParams.WRAP_CONTENT;

        window.setAttributes(wlp);
    }

}
