package com.xty.base.utils

import android.app.Application
import android.content.Context


object ContextUtils {

    private var context: Context? = null
    private var mApplication: Application? = null

     fun ContextUtils() {
        throw UnsupportedOperationException("u can't instantiate me...")
    }

    /**
     * 初始化工具类
     *
     * @param context 上下文
     */
    fun init(context: Context) {
        ContextUtils.context = context.applicationContext
        if (context is Application) {
            mApplication = context.getApplicationContext() as Application
        }
    }

    /**
     * 获取ApplicationContext
     *
     * @return ApplicationContext
     */
    fun getContext(): Context {
        if (context != null) return context!!
        throw NullPointerException("u should init first")
    }


    /**
     * 获取ApplicationContext
     *
     * @return ApplicationContext
     */
    fun getApplication(): Application {
        if (mApplication != null) return mApplication!!
        throw NullPointerException("u should init first")
    }
}