package com.bbitcn.silk.ui.dialog;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;

import com.bbitcn.silk.base.BaseDialog;
import com.bbitcn.silk.databinding.DialogCustomBinding;

/**
 * @Description 获得确认通用弹窗
 * @Author DuanKaiji
 * @CreateTime 2024年03月13日 13:57
 */
public class ConfirmDialog extends BaseDialog<DialogCustomBinding> {
    Runnable runnable;

    public ConfirmDialog(@NonNull Context context, String title, String message, Runnable runnable) {
        super(context);
        this.runnable = runnable;
        binding.tvTitle.setText(title);
        binding.tvMessage.setText(message);
        if (runnable != null) {
            //询问确定执行的弹窗
            binding.btnYes.setOnClickListener(view -> {
                runnable.run();
                dismiss();
            });
            binding.btnNo.setOnClickListener(v -> dismiss());
        } else {
            //通知显示的弹窗
            binding.btnYes.setOnClickListener(view -> dismiss());
            binding.btnNo.setVisibility(View.GONE);
        }
    }

}
