package com.remax.visualnovel.ui.splash


import android.os.CountDownTimer
import com.alibaba.android.arouter.facade.annotation.Route
import com.remax.visualnovel.app.base.BaseBindingActivity
import com.remax.visualnovel.utils.Routers
import com.remax.visualnovel.utils.StatusBarUtils
import com.remax.visualnovel.databinding.ActivitySplashBinding
import com.remax.visualnovel.ui.main.MainActivity
import com.remax.visualnovel.utils.TimeUtils
import dagger.hilt.android.AndroidEntryPoint



@AndroidEntryPoint
@Route(path = Routers.SPLASH)
class SplashActivity : BaseBindingActivity<ActivitySplashBinding>() {

    private var mCountDownTimer: CountDownTimer? = null

    override fun initView() {
        StatusBarUtils.setStatusBarAndNavBarIsLight(this, false)
        StatusBarUtils.setTransparent(this)

        with(binding) {

        }
    }

    override fun initData() {
        startCountDown()
    }

    private fun startCountDown() {
        mCountDownTimer?.cancel()
        mCountDownTimer = object : CountDownTimer(TimeUtils.ONE_SECOND * 1, 1000) {
            override fun onTick(millisUntilFinished: Long) {

            }
            override fun onFinish() {
                gotoMain()
            }
        }
        mCountDownTimer?.start()
    }

    private fun gotoMain() {
        MainActivity.start()
        finish()
    }


    override fun onDestroy() {
        super.onDestroy()
        mCountDownTimer?.cancel()
    }



}