package com.base.appzxhy.ui.malware

import android.app.Activity
import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog
import com.base.appzxhy.databinding.DialogMalwareTipBinding

class MalwareDialog(
    val activity: Activity
) {

    val dialog = AlertDialog.Builder(activity).create()
    val binding = DialogMalwareTipBinding.inflate(LayoutInflater.from(activity))

    var action: (() -> Unit)? = null

    fun showDialog() {
        dialog.setView(binding.root)
        dialog.setCanceledOnTouchOutside(false)
        dialog.show()

        val params = dialog.window?.attributes
//        params?.width = ConstraintLayout.LayoutParams.MATCH_PARENT
//        params?.width = activity.resources.getDimensionPixelSize(R.dimen.dp_295)
//        params?.height = ConstraintLayout.LayoutParams.WRAP_CONTENT
//        params?.gravity = Gravity.BOTTOM
        dialog.window?.attributes = params
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)

        binding.tvCancel.setOnClickListener {
            dialog.dismiss()
        }
        binding.tvSure.setOnClickListener {
            dialog.dismiss()
            action?.invoke()
        }
    }
}