package com.example.smart119.views

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import com.example.smart119.App
import com.example.smart119.R

object LoadingDialog : Dialog(App.instance) {
    private var dialog: Dialog? = null

    fun showDlg(context: Context) {
        // Context가 유효한지 확인
        if (dialog?.isShowing == true) return


        // Context가 유효하지 않다면 종료
        if (context !is android.app.Activity || context.isFinishing || context.isDestroyed) return

        dialog = Dialog(context).apply {
            setContentView(R.layout.dialog_loading)
            setCancelable(false)
            window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
            show()
        }

        println("show Loading dialog")
    }

    fun hideDlg() {
        dialog?.hide()
    }

    fun dismissDlg() {
        dialog?.dismiss()
        dialog = null
    }

}