package com.miraclegarden.smsmessage;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.miraclegarden.smsmessage.databinding.DialogDeleteConfirmBinding;

/**
 * 删除确认弹窗
 */
public class DeleteConfirmDialog extends Dialog {
    DialogDeleteConfirmBinding dialogActionConfirmBinding;
    OnConfirmListener onConfirmListener;
    private String title;
    private String content;

    public interface OnConfirmListener {
        void onConfirm();
    }

    public void setOnConfirmListener(OnConfirmListener listener) {
        this.onConfirmListener = listener;
    }

    public DeleteConfirmDialog(Context context, MessageInfo messageInfo) {
        super(context, R.style.MaterialDesignDialog);
        this.title = "删除确认";
        this.content = "删除" + messageInfo.getAppName() + "监听";
    }

    public DeleteConfirmDialog(Context context, String title, String content) {
        super(context, R.style.MaterialDesignDialog);
        this.title = title;
        this.content = content;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        dialogActionConfirmBinding = DialogDeleteConfirmBinding.inflate(getLayoutInflater());
        setContentView(dialogActionConfirmBinding.getRoot());
        dialogActionConfirmBinding.contentTv.setText(content);

        dialogActionConfirmBinding.sumbitTv.setOnClickListener(v -> {
            dismiss();
            if(onConfirmListener != null){
                onConfirmListener.onConfirm();
            }
        });
        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);
    }
}
