package com.sketch.ar.artdrawing

import android.app.Application
import android.content.Context
import android.util.Log
import com.ad.toponlibrary.AdManager
import com.ironsource.fa
import com.sketch.ar.artdrawing.utils.ObjectBoxHelper
import com.thinkup.core.api.TUSDK
import com.up.uploadlibrary.UpLoadManager

class MyApp : Application() {

    companion object {
        val TAG = "#################"
        var assetFolders = listOf<String>()
        lateinit var mInstance:MyApp
    }

    override fun onCreate() {
        super.onCreate()
        mInstance = this
        ObjectBoxHelper.init(this)
        assetFolders = getAssetFolders(this)

        AdManager.init(TAG,this,"h69099a00806d2","a41ab822e982dc7c0b84f2aab68bc14ca",
            "25e138876a3743aa9037e82dff40dcb657df7a6d",
            "n69099a45ad48c",
            "n69099a45757a5",
            "n69099a453ec89", false)
        UpLoadManager.init(this,TAG)
    }

    fun getAssetFolders(context: Context): List<String> {
        val assetManager = context.assets
        val folderNames = mutableListOf<String>()
        val excluded = setOf("images", "webkit")
        fun findFolders(path: String) {
            val list = assetManager.list(path) ?: return
            for (name in list) {
                if (excluded.contains(name)) continue
                if (!name.startsWith("kt_")) continue
                val fullPath = if (path.isEmpty()) name else "$path/$name"
                val children = assetManager.list(fullPath)
                if (!children.isNullOrEmpty()) {
                    folderNames.add(fullPath)
                    Log.d(TAG,"add name=$fullPath")
                    findFolders(fullPath) // 递归查找子文件夹
                }
            }
        }

        findFolders("")
        return folderNames
    }
}