package com.duben.microtribe.manager

import android.app.Application
import android.content.Context
import com.duben.microtribe.BuildConfig
import com.duben.microtribe.utils.MateUtils
import com.tendcloud.tenddata.TCAgent

/**
 * TalkingData
 */
object TalkingDataManager {

    private const val APP_KEY =BuildConfig.RELEASE_TALKING_DATA_KEY


    fun init(application:Application) {
        try {
            //打开日志
            TCAgent.LOG_ON = BuildConfig.LOG_DEBUG
            /**
             * 动态获取渠道ID（类似友盟）
             * AppID说是xml文件里的密钥？
             */
            TCAgent.init(application, APP_KEY
                    , MateUtils.getAppMetaData(application, "CHANNEL_NAME"))
            /**
             * true-开启自动捕获错误
             */
            TCAgent.setReportUncaughtExceptions(true)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    fun onResume(cxt:Context,name:String){
        TCAgent.onPageStart(cxt, name)
    }

    fun onPause(cxt:Context,name:String){
        TCAgent.onPageEnd(cxt, name)
    }
}