package com.keyboard.bubble.skin.keyboard.ui

import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.widget.ProgressBar
import androidx.appcompat.app.AppCompatActivity
import com.keyboard.bubble.skin.keyboard.R
import com.keyboard.bubble.skin.keyboard.utils.MyUtils
import kotlin.math.roundToInt

class WelcomeActivity : AppCompatActivity() {

    private lateinit var progressBar: ProgressBar
    private var countTime = 1000L
    private lateinit var timer: CountDownTimer

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_launch)
        MyUtils.initFullScreen(this)
        init()
        findView()
    }

    private fun init() {

        timer = object : CountDownTimer(countTime, 100) {
            override fun onTick(millisUntilFinished: Long) {
                val percentage: Float = 100 - millisUntilFinished.toFloat() / countTime * 100
                val round = percentage.roundToInt()
                progressBar.progress = round
            }

            override fun onFinish() {
                progressBar.progress = 100
                toHome()
            }

        }
        timer.start()

    }


    private fun findView() {
        progressBar = findViewById<ProgressBar>(R.id.nova_progress)
    }


    private fun toHome() {
        startActivity(Intent(this, MainActivity::class.java))
        finish()
    }

    override fun onDestroy() {
        super.onDestroy()
        timer.cancel()
    }


}