package com.ym.modulecommon.utils

import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.content.ContextWrapper
import android.os.Build
import androidx.annotation.RequiresApi

object DialogUtils {
    @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    fun dismiss(mDialog: Dialog?) {
        try {
            if (mDialog != null) {
                if (mDialog?.isShowing!!) {
                    val context: Context =
                        (mDialog?.context as ContextWrapper).baseContext
                    if (context is Activity) {
                        if (!context.isFinishing && !context.isDestroyed) mDialog?.dismiss()
                    } else {
                        mDialog?.dismiss()
                    }
                }
            }
        } catch (e: Exception) {

        } finally {
//            mLoading = null
        }
    }

    @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    fun show(mDialog: Dialog?) {
        try {
            if (mDialog != null) {
                if (!mDialog?.isShowing) {
                    val context: Context =
                        (mDialog?.context as ContextWrapper).baseContext
                    if (context is Activity) {
                        if (!context.isFinishing && !context.isDestroyed) mDialog?.show()
                    }
                }
            }
        } catch (e: Exception) {

        } finally {
//            mLoading = null
        }
    }
}