package com.rich.keyboard.skin.uiactivity

import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.widget.ProgressBar
import androidx.appcompat.app.AppCompatActivity
import com.rich.keyboard.skin.R
import com.rich.keyboard.skin.ad.AdManager
import com.rich.keyboard.skin.utils.MyCommon
import kotlin.math.roundToInt

class SplashUi : AppCompatActivity() {

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

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_wel)
        MyCommon.initFullScreen(this,true)
        progressBar = findViewById<ProgressBar>(R.id.nova_progress)
        init()

    }

    private fun init() {

        timer = AdManager.showWelcomeAd(this@SplashUi,countTime,{
            val percentage: Float = 100 - it.toFloat() / countTime * 100
            val round = percentage.roundToInt()
            progressBar.progress = round
        }){
            progressBar.progress = 100
            toHome()
        }
        timer.start()

    }





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

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


}