package com.atmob.keyboard_android.util

import android.os.Handler
import android.os.Looper
import com.blankj.utilcode.util.ToastUtils

/**
 * Toast工具类
 */
class ToastUtil private constructor() {
    companion object {
        private val mMainHandler = Handler(Looper.getMainLooper())

        /**
         * 显示Toast
         */
        fun showToast(msg: String?) {
            if (msg == null || msg.isBlank()) {
                return
            }
            val action = {
                ToastUtils.showShort(msg)
                // 三星手机，如果不自定义Toast，后台显示Toast会显示不出来
                // Toast.makeText(ContextUtil.getContext(), msg, Toast.LENGTH_SHORT).show()
            }
            if (Thread.currentThread() == Looper.getMainLooper().thread) {
                action.invoke()
            } else {
                mMainHandler.post(action)
            }
        }
    }
}