package com.keyboard.theme.app.keyboard

import android.app.Application
import android.graphics.Typeface
import android.util.Log
import com.anythink.core.api.ATSDK
import com.anythink.core.api.NetTrafficeCallback
import com.google.firebase.FirebaseApp
import com.keyboard.theme.app.keyboard.data.Info
import com.keyboard.theme.app.keyboard.topon.AdManager
import com.keyboard.theme.app.keyboard.utils.FileManager

class MyAppllication : Application() {

    private var  APPId = "h674429b34725d"
    private var  AppKey = "a08025202483213dea1c50c8a26d47a59"



    override fun onCreate() {
        super.onCreate()
        instance = this
        initTop()
        AdManager.loadAllAd()
        FileManager.getFileStr(assets.open("data.json")) {
            if (it != null) {
                requireNotNull(it.isNotEmpty())
                data = FileManager.getDataBean(it)
            }
        }
        font = Typeface.createFromAsset(assets,"myfont.ttf")
        if (FirebaseApp.getApps(this).isNotEmpty()) {
//            Log.d("TAG", "Firebase 初始化成功");
        } else {
//            Log.e("TAG", "Firebase 初始化失败");
        }


    }

    companion object {
        var data: List<Info> = mutableListOf()
        lateinit var instance: MyAppllication

        lateinit var font:Typeface
    }

    private fun initTop(){
        ATSDK.checkIsEuTraffic(this, object : NetTrafficeCallback {
            override fun onResultCallback(isEU: Boolean) {
                if (isEU && ATSDK.getGDPRDataLevel(this@MyAppllication) == ATSDK.UNKNOWN) {
                    ATSDK.showGdprAuth(this@MyAppllication)
                }
            }

            override fun onErrorCallback(errorMsg: String) {

            }
        })

        ATSDK.init( this, APPId, AppKey)
        //测试工具
//        ATDebuggerUITest.showDebuggerUI(this,debug_KEy);
    }
}