Loading.kt 984 Bytes
Newer Older
万齐军 committed
1 2 3 4 5 6 7 8 9
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
万齐军 committed
10 11

    fun show(context: Context?, msg: String? = null) {
万齐军 committed
12 13 14
        if (context !is FragmentActivity) return

        if (loadingDialogFragment == null) {
万齐军 committed
15
            loadingDialogFragment = LoadingDialogFragment2.newInstance(msg)
万齐军 committed
16 17 18 19
        }
        if (loadingDialogFragment?.isAdded!!) {
            return
        }
万齐军 committed
20 21 22 23 24 25
//        if (Looper.myLooper() == Looper.getMainLooper()) {
            loadingDialogFragment?.show(context.supportFragmentManager, Loading::class.java.simpleName)
//        } else
//            context.runOnUiThread {
//                loadingDialogFragment?.show(context.supportFragmentManager, Loading::class.java.simpleName)
//            }
万齐军 committed
26 27
    }

万齐军 committed
28

万齐军 committed
29 30 31 32
    fun close() {
        loadingDialogFragment?.dismissAllowingStateLoss()
    }
}