package com.adpro.pixelshow.look

import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import com.ad.maxlibrary.WelComManager
import com.adpro.pixelshow.databinding.ActivityInitBinding
import com.adpro.pixelshow.util.TopBarUtils

class InitActivity : AppCompatActivity() {
    lateinit var binding: ActivityInitBinding
    private var handler: Handler = Handler()
    private var countDownTimer: CountDownTimer? = null
    private val time = 12000L

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityInitBinding.inflate(layoutInflater)
        setContentView(binding.root)


        TopBarUtils.setStatusBar(this.window)
        TopBarUtils.setLightStatusBar(this.window,true)
        countDownTimer = WelComManager.initTimer(this, time, { millisUntilFinished ->
            val v: Float =
                100 - millisUntilFinished.toFloat() / time * 100
            val v1 = v.toInt()
            binding.progressbar.progress =  v1

        }) {
            val intent= Intent(
                this@InitActivity,
                FirstSelActivity::class.java
            )
            startActivity(intent)
            finish()
        }

    }

    override fun onDestroy() {
        super.onDestroy()
        handler.removeCallbacksAndMessages(null)

        if (countDownTimer != null) {
            countDownTimer!!.cancel()
        }
    }
}