package com.adealink.weparty.commonui.dialog

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import android.view.WindowManager
import com.adealink.frame.mvvm.view.viewBinding
import com.adealink.weparty.R
import com.adealink.weparty.commonui.dialogfragment.BaseDialogFragment
import com.adealink.weparty.commonui.ext.dp
import com.adealink.weparty.databinding.DialogLoadingBinding

class LoadingDialog : BaseDialogFragment(R.layout.dialog_loading) {

    private val binding by viewBinding(DialogLoadingBinding::bind)

    override var canceledOnTouchOutside: Boolean = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NO_TITLE, R.style.TipDialog)
    }

    override fun onStart() {
        super.onStart()
        resetDialogAttributes()
    }

    private fun resetDialogAttributes() {
        val dialog = dialog ?: return
        val window = dialog.window ?: return
        window.setLayout(
            120.dp(),
            WindowManager.LayoutParams.WRAP_CONTENT
        )
        window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        val attr = window.attributes
        attr.gravity = Gravity.CENTER
        attr.dimAmount = 0f
        window.attributes = attr
    }
}