package com.zxhyis.toolss.ui.dialog

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.appcompat.widget.AppCompatTextView
import androidx.fragment.app.DialogFragment
import com.zxhyis.toolss.R
import com.zxhyis.toolss.logic.ActivityCollector
import com.zxhyis.toolss.logic.setOnClick

class ExitDialog : DialogFragment() {

    private lateinit var exitView: View

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        exitView = inflater.inflate(R.layout.dialog_exit, container, false)
        return exitView
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        val window = dialog?.window
        window?.setGravity(Gravity.CENTER)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        val windowManager = activity?.windowManager
        val display = windowManager?.defaultDisplay
        val lp = dialog?.window!!.attributes
        lp.width = (display?.width!! * 0.73).toInt() //设置宽度
        dialog?.window!!.attributes = lp

        exitView.findViewById<AppCompatTextView>(R.id.tv_cancle).setOnClick(javaClass.simpleName) {
            dialog?.dismiss()
        }

        exitView.findViewById<AppCompatTextView>(R.id.tv_confirm).setOnClick(javaClass.simpleName) {
            ActivityCollector.finishAll()
        }

       // MaxAdUtils.showMaxNativeAd(activity, exitView.findViewById<FrameLayout>(R.id.fl_ad), slotname = "native_slot")


    }


}