package com.design.mischiefgo.ui

import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import com.design.mischiefgo.databinding.ActivityAdShowBinding
import com.design.mischiefgo.ut.EvenTopUtils

class AdShowActivity : AppCompatActivity() {
    private lateinit var binding : ActivityAdShowBinding
    private var handler: Handler = Handler()
    private var countDownTimer: CountDownTimer? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        EvenTopUtils.setStatusBar(this.window)
        EvenTopUtils.setLightStatusBar(this.window, true)
        binding = ActivityAdShowBinding.inflate(layoutInflater)
        setContentView(binding.root)
        handler.postDelayed({
            val intent= Intent(
                this@AdShowActivity,
                NavigationActivity::class.java
            )
            startActivity(intent)
            finish()
        }, 4000)
        countDownTimer = object : CountDownTimer(4000, 100) {
            override fun onTick(millisUntilFinished: Long) {
                val progress = ((4000 - millisUntilFinished) / 4000f * 100).toInt()
                binding.loadingPb.progress = progress
            }

            override fun onFinish() {
                binding.loadingPb.progress = 100
            }
        }.start()
    }

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

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