package com.hongyegroup.zhurijob.ui

import android.annotation.SuppressLint
import android.os.Bundle
import com.guadou.cs_cptservices.YYConstants
import com.guadou.cs_cptservices.base.activity.YYBaseVDBActivity
import com.guadou.lib_baselib.base.vm.EmptyViewModel
import com.guadou.lib_baselib.bean.DataBindingConfig
import com.guadou.lib_baselib.engine.SP
import com.guadou.lib_baselib.ext.checkEmpty
import com.guadou.lib_baselib.engine.getString
import com.guadou.lib_baselib.utils.BitmapUtils
import com.guadou.lib_baselib.utils.CommUtils
import com.guadou.lib_baselib.utils.log.YYLogUtils
import com.hongyegroup.cpt_auth.ui.UserLoginActivity
import com.hongyegroup.cpt_main.ui.MainActivity
import com.hongyegroup.zhurijob.R
import com.hongyegroup.zhurijob.databinding.ActivitySplashBinding

@SuppressLint("CustomSplashScreen")
class SplashActivity : YYBaseVDBActivity<EmptyViewModel, ActivitySplashBinding>() {

    companion object {
        //起始页面延迟的时间
        const val SPLASH_DELAY_TIMESTAMP: Long = 1000
    }

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.activity_splash)
    }

    override fun startObserve() {

    }

    override fun init(savedInstanceState: Bundle?) {

        //清除BitmapUtil的缓存图片
        BitmapUtils.getInstance(mContext).deleteBitmapCacheDir()

        //开启倒计时，还是直接启动
        navLoginOrMain()

        YYLogUtils.w("viewmodel:$mViewModel")
    }

    private fun navLoginOrMain() {

        CommUtils.getHandler().postDelayed({

            if (SP().getString(YYConstants.SP_KEY_TOKEN, "").checkEmpty()) {
                //登录
                UserLoginActivity.startInstance()
            } else {
                //首页
                MainActivity.startInstance()
            }

            finish()

        }, SPLASH_DELAY_TIMESTAMP)

    }

}