package com.duben.happyplaylet.manager

import android.app.Application
import com.duben.happyplaylet.BuildConfig
import com.duben.happyplaylet.utils.MateUtils
import com.umeng.analytics.MobclickAgent
import com.umeng.commonsdk.UMConfigure
object UmengManager {

    private val TAG = UmengManager::class.java.simpleName

    fun preInit(application: Application, channel: String) {
        UMConfigure.preInit(
            application,
            MateUtils.getAppMetaData(application, "UMENG_KEY"),
            channel
        )
    }

    /**
     * 友盟初始化
     */
    fun initUm(application: Application, channel: String) {
        try {
            /*
             * 参数4:设备类型，必须参数，传参数为UMConfigure.DEVICE_TYPE_PHONE则表示手机；传参数为UMConfigure.DEVICE_TYPE_BOX则表示盒子；默认为手机。
             * 参数5:Push推送业务的secret，需要集成Push功能时必须传入Push的secret，否则传空。
             */
            UMConfigure.init(
                application,
                MateUtils.getAppMetaData(application, "UMENG_KEY"),
                channel,
                UMConfigure.DEVICE_TYPE_PHONE,
                ""
            )
            UMConfigure.setLogEnabled(BuildConfig.DEBUG)
            MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.LEGACY_MANUAL)
        } catch (e: java.lang.Exception) {
            e.printStackTrace()
        }
    }

}