package com.img.rabbit

import android.app.Application
import android.util.Log
import com.img.rabbit.utils.NetworkMonitor
import com.g.gysdk.GYManager
import com.img.rabbit.config.Constants
import com.tencent.mmkv.MMKV
import com.umeng.analytics.MobclickAgent
import com.umeng.commonsdk.UMConfigure
import com.umeng.socialize.PlatformConfig


class BaseApplication : Application() {
    private val TAG = "BaseApplication"

    override fun onCreate() {
        super.onCreate()
        // 初始化网络状态监控
        NetworkMonitor.initialize(this)
        // 初始化MMKV
        initMMKV()
        // 初始化个推SDK
        initGeTuiOneKeyLogin()
        // 初始化友盟
        initUM()
    }

    /**
     * 初始化友盟
     */
    private fun initUM() {
        UMConfigure.setLogEnabled(true)

        PlatformConfig.setFileProvider("${BuildConfig.APPLICATION_ID}.fileprovider")
        PlatformConfig.setWeixin(Constants.WechatAppId, Constants.WechatAppSecret)
        MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO)

        UMConfigure.setProcessEvent(true)
    }

    private fun initGeTuiOneKeyLogin() {
        GYManager.getInstance().preInit(this.applicationContext)
    }

    private fun initMMKV() {
        val rootDir = MMKV.initialize(this)
        Log.i(TAG, "MMKV root dir: $rootDir")
    }

}