package com.zxbw.modulemain.activity

import android.text.TextUtils
import android.util.Log
import android.view.View
import com.umeng.analytics.MobclickAgent
import com.zx.ad.AdManager
import com.zx.ad.callback.SplashAdListener
import com.zxbw.modulemain.R
import com.zxbw.modulemain.contract.SplashContract
import com.zxbw.modulemain.presenter.SplashPresenter
import com.zxhl.cms.common.Constant
import com.zxhl.cms.common.NetConfig
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.box.AppInEntity
import com.zxhl.cms.router.RounterApi
import com.zxhl.cms.router.RounterBus
import com.zxhl.cms.utils.EventUtils
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.cms.widget.CenterDialog
import kotlinx.android.synthetic.main.activity_splash.*

class SplashBackgroundActivity: BaseActivity() {

    override fun onClick(v: View?) {
    }

    override fun layoutID(): Int = R.layout.activity_splash

    private var mPresenter: SplashContract.Presenter? = null


    override fun init() {
        if (!isTaskRoot) {
            finish()
            return
        }

            initSplashAd()


    }

    private fun initSplashAd() {

        AdManager.loadSplashAd(this,id_splash_view,object : SplashAdListener {
            override fun onAdShow() {

            }

            override fun onAdSkip() {

            }

            override fun onError(errorMsg: String?) {
                Log.e("MXL","MSG:"+errorMsg)
                jumpMainPage()
            }
        })
    }

     fun jumpMainPage() {
        val user = SettingPreference.getUserInfoData()
        val token = SettingPreference.getUserToken()
        if (user == null && TextUtils.isEmpty(token)) {
            JumpUtils.loginJump()
        } else {
            JumpUtils.activityJump(
                RounterBus.getRounter(RounterApi::class.java).getIntentActivityMain()
            )
        }
        finish()
    }



    private var isPause = false


    override fun onResume() {
        super.onResume()
        MobclickAgent.onResume(this)
    }

    override fun onPause() {
        super.onPause()
        MobclickAgent.onPause(this)
    }


}