package cn.yyxx.eyuangame.base

import android.annotation.TargetApi
import android.app.Application
import android.content.Context
import android.os.Build
import android.os.LocaleList
import cn.yyxx.support.multidex.MultiDex
import java.util.*

/**
 * @author #Suyghur.
 * Created on 2021/06/09
 */
open class EYuanGameApplication : Application() {

    override fun attachBaseContext(base: Context) {
        val context = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            updateResources(base)
        } else {
            base
        }
        super.attachBaseContext(context)
//        MultiDex.install(context)
        EYuanGame.getInstance().attachBaseContext(this, context)
    }

    override fun onCreate() {
        super.onCreate()
        EYuanGame.getInstance().initApplication(this)
    }

    @TargetApi(Build.VERSION_CODES.N)
    private fun updateResources(context: Context): Context {
        val resources = context.resources
        val locale = Locale.forLanguageTag("vi-VN")
        val configuration = resources.configuration
        configuration.setLocale(locale)
        configuration.setLocales(LocaleList(locale))
        return context.createConfigurationContext(configuration)
    }

//    override fun createConfigurationContext(overrideConfiguration: Configuration): Context {
//        val locale = Locale("vi")
//        Locale.setDefault(locale)
////        val config = resources.configuration
////        config.setLocale(locale)
////        resources.updateConfiguration(config)
//        overrideConfiguration.setLocale(locale)
//        return super.createConfigurationContext(overrideConfiguration)
//    }
}