package com.color.keyboard.black.activity

import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.widget.ProgressBar
import androidx.appcompat.app.AppCompatActivity
import com.color.keyboard.black.R
import com.color.keyboard.black.manager.Common
import com.color.keyboard.black.max.MaxManager
import com.color.keyboard.black.max.WelComManager
import kotlin.math.roundToInt

class LauncherActivity : AppCompatActivity() {

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

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_launcher)
        Common.initFullScreen(this,true)

        MaxManager.onLoadAd()

        init()
        findView()
    }

    private fun init() {
        val timer = WelComManager.initTimer(
            activity = this,
            countTime = countTime,
            countAction = { millisUntilFinished ->
                val percentage: Float = 100 - millisUntilFinished.toFloat() / countTime * 100
                val round = percentage.roundToInt()
                progressBar.progress = round
            },
            goMainAction = {
                progressBar.progress = 100
                toHome()
            }
        )
        timer.start()
    }


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


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

    override fun onDestroy() {
        super.onDestroy()
        timer?.cancel()
        timer = null
    }


}