package com.photo.keyboard.themes

import android.app.Application
import android.graphics.Typeface
import com.anythink.core.api.ATSDK
import com.anythink.core.api.NetTrafficeCallback
import com.photo.keyboard.themes.data.Parent
import com.photo.keyboard.themes.manager.FileDeal
import com.photo.keyboard.themes.topon.AdManager

class App : Application() {

    override fun onCreate() {
        super.onCreate()
        instance = this
        initAd()

        FileDeal.getFileStr(assets.open("themes.json")) {
            if (it != null) {
                requireNotNull(it.isNotEmpty())
                data = FileDeal.getDataBean(it)
            }
        }
        font = Typeface.createFromAsset(assets, "myfont.ttf")
        com.photo.keyboard.themes.manager.DbManager.init(this)


    }

    companion object {
        var data: List<Parent> = mutableListOf()
        lateinit var instance: App

        lateinit var font: Typeface

        const val TAG = "============="
    }

    private fun initAd() {
        ATSDK.checkIsEuTraffic(this, object : NetTrafficeCallback {
            override fun onResultCallback(isEU: Boolean) {

                if (isEU && ATSDK.getGDPRDataLevel(this@App) == ATSDK.UNKNOWN) {
                    ATSDK.showGdprAuth(this@App)
                }
            }

            override fun onErrorCallback(errorMsg: String) {

            }
        })
        val APPId = "h67d11483b0378"
        val AppKey = "a93991341a41d40221ddada4c4675e7d2"
        ATSDK.init(this, APPId, AppKey)
        AdManager.loadAllAd()
        //测试工具
//        ATDebuggerUITest.showDebuggerUI(this,debug_KEy);
    }
}