package com.key.board.journey.inputmethod.activity

import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.widget.ProgressBar
import androidx.appcompat.app.AppCompatActivity
import com.ad.toponlibrary.AdManager
import com.ad.toponlibrary.AdManager.mContext
import com.anythink.debug.api.ATDebuggerUITest
import com.key.board.journey.inputmethod.R
import com.key.board.journey.inputmethod.tools.Common
import kotlin.math.roundToInt

class WelActivity : 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.activity_wel)
        Common.initFullScreen(this,true)
        init()
        findView()

    }

    private fun init() {

        timer = AdManager.showWelcomeAd(this@WelActivity,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, MainActivity::class.java))
        finish()
    }

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


}