package com.drawing.drawsketch

import android.app.Application
import android.content.Context
import android.util.Log
import com.ad.maxlibrary.MaxInitManager
import com.up.uploadlibrary.UpLoadManager

class App : Application() {

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

    override fun onCreate() {
        super.onCreate()
        mInstance = this
        DbBase.init(this)

        MaxInitManager.init(
            this,
            "VVN64VW3_CeQrIZ9sSUMQAWAS4XI14L2etylkN_E2IkJpZrsF6Xt26aMuwBGOboUiFvkTVJ28EbPW53NL_6SPT",
            "4b395fbe56938e55",
            "1333fd8414ece2be",
            "41633fd274e1e91c",
            TAG
        )
        UpLoadManager.init(this,TAG)
        assetFolders = getAssetFolders(this)
    }

    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(App.TAG,"add name=$fullPath")
                    findFolders(fullPath) // 递归查找子文件夹
                }
            }
        }

        findFolders("")
        return folderNames
    }
}