package com.themes.fancy.keyboard.keyboard.viewui

import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.widget.ProgressBar
import androidx.appcompat.app.AppCompatActivity
import com.themes.fancy.keyboard.keyboard.R
import com.themes.fancy.keyboard.keyboard.helper.Common
import com.themes.fancy.keyboard.keyboard.max.WelComManager

import kotlin.math.roundToInt

class LaunchActivity : AppCompatActivity() {

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

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

    private fun init() {

        timer = WelComManager.initTimer(this@LaunchActivity, countTime, {
            val percentage: Float = 100 - it.toFloat() / countTime * 100
            val round = percentage.roundToInt()
            progressBar.progress = round
        }, {
            progressBar.progress = 100
            toHome()
        })
    }


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


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

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


}