package com.app.intelligent.board.uiactivity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.widget.ProgressBar
import com.ad.tradpluslibrary.TPAdManager
import com.app.intelligent.board.AppContextHelper
import com.app.intelligent.board.R
import com.app.intelligent.board.utils.AppCommonUtils
import kotlin.math.roundToInt


/**
 * 不要修改启动页继承Activity这点
 */
class StartActivity : Activity() {

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

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

    }

    private fun init() {
        TPAdManager.init(
            this,
            AppContextHelper.TAG,
            "3B146C8C20991851D63D84716B4F7111",
            "C1C535F4709BE310CB0D64F2408B1912",
            "EA57BAD08FDF4426503AF8AD94F53F12",
            "F79B74423BCD821135025ACA55FD2E12"
        ) {

        }
        timer = TPAdManager.showWelcomeAd(this, countTime, { millisUntilFinished ->
            //倒计时更新
            val progressPercentage = (100 * millisUntilFinished) / countTime
            val percentage = 100 - progressPercentage
            progressBar.progress = percentage.toInt()
        }) {
            progressBar.progress = 100
            toHome()
        }
        timer.start()

    }

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

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


}