package com.cartoon.wallpapers.live.ui

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.cartoon.wallpapers.live.databinding.DialogErrorBinding

class DialogError(private var mClickType: () -> Unit) : DialogFragment() {
    private lateinit var vb: DialogErrorBinding
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        vb = DialogErrorBinding.inflate(layoutInflater)
        init()
        return vb.root
    }

    override fun onStart() {
        super.onStart()
        val dialog = dialog
        if (dialog != null) {
            dialog.setCanceledOnTouchOutside(false)
            val window = dialog.window
            if (window != null) {
                window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
                window.setGravity(Gravity.CENTER)
                window.setLayout(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT
                )
            }
        }
    }

    private fun init() {
        vb.run {
            tvOk.setOnClickListener {
                dismiss()
                mClickType.invoke()
            }

        }

    }



}