package com.ydl.ydlcommon.ui

import android.content.Context
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentActivity

object Loading {

    private var loadingDialogFragment: DialogFragment? = null

    fun show(context: Context?, msg: String? = null) {
        if (context !is FragmentActivity) return

        if (loadingDialogFragment == null) {
            loadingDialogFragment = LoadingDialogFragment2.newInstance(msg)
        }
        if (loadingDialogFragment?.isAdded!!) {
            return
        }
//        if (Looper.myLooper() == Looper.getMainLooper()) {
            loadingDialogFragment?.show(context.supportFragmentManager, Loading::class.java.simpleName)
//        } else
//            context.runOnUiThread {
//                loadingDialogFragment?.show(context.supportFragmentManager, Loading::class.java.simpleName)
//            }
    }


    fun close() {
        loadingDialogFragment?.dismissAllowingStateLoss()
    }
}
