package com.zxhyis.toolss.ui.dialog

import android.content.DialogInterface
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.airbnb.lottie.LottieAnimationView
import com.zxhyis.toolss.R
import com.zxhyis.toolss.logic.DialogDismissListener

class LoadingDialog:DialogFragment() {

    private lateinit var loadVIew:View
    private var dismissListener: DialogDismissListener? = null
    fun setDismissListener(listener: DialogDismissListener) {
        dismissListener = listener
    }


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

    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.3).toInt() //设置宽度
        dialog?.window!!.attributes = lp

        loadVIew.findViewById<LottieAnimationView>(R.id.lav_load).playAnimation()
    }

    override fun onDismiss(dialog: DialogInterface) {
        super.onDismiss(dialog)
        dismissListener?.onDialogDismissed()
    }


}