package com.wdkl.app.ncs.application

import com.enation.javashop.android.jrouter.JRouter
import com.wdkl.ncs.android.lib.base.BaseApplication
import com.enation.javashop.net.engine.config.NetEngineConfig
import com.enation.javashop.net.engine.plugin.exception.RestfulExceptionInterceptor
import com.enation.javashop.utils.base.config.BaseConfig
import com.wdkl.lcd_board.helper.AnrFcExceptionUtil
import com.wdkl.lcd_board.helper.NetHelper

/**
 * @author LDD
 * @Date   2018/1/11 下午12:48
 * @From   com.enation.javashop.android.application
 * @Note   应用Application
 */
class Application : BaseApplication() {


    /**
     * @author LDD
     * @From   Application
     * @Date   2018/1/11 下午12:50
     * @Note   应用启动时调用
     */
    override fun onCreate() {
        super.onCreate()
        initRouter()
        initFrame()
        initLeaks()
    }

    /**
     * @author  LDD
     * @From    Application
     * @Date   2018/1/11 下午12:50
     * @Note   初始化路由
     * @return rx观察者
     */
    private fun initRouter() {
        JRouter.init(this)
        JRouter.openDebug()
        JRouter.openLog()
        JRouter.prepare().create("/welcome/launch").seek()
        JRouter.prepare().create("/extra/launch").seek()
        JRouter.prepare().create("/lcd_board/launch").seek()
    }

    /**
     * @author  LDD
     * @From    Application
     * @Date   2018/1/11 下午12:50
     * @Note   初始化内存检测器
     * @return rx观察者
     */
    private fun initLeaks() {

    }

    /**
     * @author  LDD
     * @From    Application
     * @Date   2018/1/11 下午12:50
     * @Note   初始化内部框架
     * @return rx观察者
     */
    private fun initFrame() {
        //禁止滑掉退出
        BaseConfig.getInstance().addActivity("MainActivity", "AppUpdateActivity", "WelcomeActivity")

        NetEngineConfig.init(baseContext)
                .openLogger()
                .addNetInterceptor(RestfulExceptionInterceptor())

        //init
        NetHelper.getInstance().init()

        //anr catcher
        AnrFcExceptionUtil.getInstance(this).initFCException()
    }
}