package com.apps.quicksketchtrace.activity

import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import com.apps.quicksketchtrace.databinding.ActivityMainStartBinding

class StartMainActivity : AppCompatActivity() {
    private lateinit var binding:ActivityMainStartBinding
    private lateinit var countDownTimer: CountDownTimer
    private val handler = Handler(Looper.getMainLooper())
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding=ActivityMainStartBinding.inflate(layoutInflater)
        setContentView(binding.root)
        handler.postDelayed({
            startActivity(Intent(this@StartMainActivity, MainActivity::class.java))
            finish()
        }, 4000)
        countDownTimer = object : CountDownTimer(4000, 100) {
            override fun onTick(millisUntilFinished: Long) {
                val progress = ((4000 - millisUntilFinished) / 4000f * 100).toInt()
                binding.progressbar.progress = progress
            }

            override fun onFinish() {
                binding.progressbar.progress = 100
            }
        }.start()
    }
    override fun onDestroy() {
        super.onDestroy()
        handler.removeCallbacksAndMessages(null)
        countDownTimer.cancel()
    }
}