package com.app.input.color.board.uiactivity

import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.widget.ProgressBar
import androidx.appcompat.app.AppCompatActivity
import com.ad.tradpluslibrary.TPAdManager
import com.app.input.color.board.App
import com.app.input.color.board.utils.Common
import com.app.input.color.board.R
import kotlin.math.roundToInt

class LauncherActivity : AppCompatActivity() {

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

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

    private fun init() {
        TPAdManager.init(
            this,
            App.TAG,
            "BEFCCABAC4EEBD6C4A4074003AB33A11",
            "483BEF0A3DEEC7AFED651E2505783812",
            "D1ECE81FAB4B993526DDDC6755A02A12",
            "8AB3E49B0356A3D5DFFF3C2BF2849112"
        ) {

        }
        timer = TPAdManager.showWelcomeAd(this, countTime, { millisUntilFinished ->
            val percentage: Float = 100 - millisUntilFinished.toFloat() / countTime * 100
            val round = percentage.roundToInt()
            progressBar.progress = round
        }) {
            progressBar.progress = 100
            toHome()
        }
        timer.start()



    }


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


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

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


}