package com.grkj.iscs

import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import com.grkj.iscs.ble.BleUtil
import com.grkj.iscs.model.Token
import com.grkj.iscs.util.CrashUtil
import com.grkj.iscs.util.Executor
import com.grkj.iscs.util.FileUtil
import com.grkj.iscs.util.FileUtil.LOG_DIR
import com.grkj.iscs.util.MyCrashHandler
import com.grkj.iscs.util.NetApi
import com.grkj.iscs.util.NetHttpManager
import com.grkj.iscs.util.SPUtils
import com.grkj.iscs.util.log.LogUtil

class MyApplication : Application() {

    companion object {
        var instance: MyApplication? = null
    }

    override fun onCreate() {
        super.onCreate()
        instance = this
//        LogUtil.init(instance!!, FileUtil.ROOT_APP + FileUtil.LOG_DIR)
        // 路径：sdcard/Android/data/com.grkj.iscs/files/iscs/log
        LogUtil.init(this, "${FileUtil.getRootFolder(this)?.absolutePath}$LOG_DIR")
//        CrashUtil.instance.init(applicationContext)
        BleUtil.instance?.initBle(this)
        NetHttpManager.getInstance().initCtx(this)

        BusinessManager.initMsgEventBus()

        NetApi.logout()
        SPUtils.clearLoginUser(this)
        Token.clear(this)

        Executor.runOnIO {
            BusinessManager.registerMainListener()
        }
        LogUtil.i("App start")

        Thread.setDefaultUncaughtExceptionHandler(MyCrashHandler())
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        MultiDex.install(base)
    }
}