package com.hongyegroup.nucleicacidtest.ui

import android.os.Bundle
import com.guadou.cs_cptservices.Constants
import com.guadou.cs_cptservices.base.activity.YYBaseVDBActivity
import com.guadou.cs_router.YYRouterService
import com.guadou.lib_baselib.base.vm.EmptyViewModel
import com.guadou.lib_baselib.bean.DataBindingConfig
import com.guadou.lib_baselib.ext.SP
import com.guadou.lib_baselib.utils.BitmapUtils
import com.guadou.lib_baselib.utils.CheckUtil
import com.guadou.lib_baselib.utils.CommUtils
import com.hongyegroup.nucleicacidtest.R
import com.hongyegroup.nucleicacidtest.databinding.ActivitySplashBinding


class SplashActivity : YYBaseVDBActivity<EmptyViewModel, ActivitySplashBinding>() {

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

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

    override fun startObserve() {

    }

    override fun init(savedInstanceState: Bundle?) {

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

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


    }

    private fun navLoginOrMain() {

        CommUtils.getHandler().postDelayed({

            if (CheckUtil.isEmpty(SP().getString(Constants.SP_KEY_TOKEN, ""))) {
                //指引页面
                YYRouterService.mainComponentServer?.startChooseRoleActivity()
            } else {

                if (SP().getBoolean(Constants.SP_KEY_IS_BUSINESS, false)) {
                    YYRouterService.businessComponentServer?.startBusinessMainActivity()
                } else {
                    YYRouterService.pensonalComponentServer?.startPensonalMainActivity()
                }
            }

            finish()

        }, SPLASH_DELAY_MILLISEC)

    }

}