package com.joyful.euphoria.board.xmlactivity

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.joyful.euphoria.board.EuphoriaBoard
import com.joyful.euphoria.board.R
import com.joyful.euphoria.board.utils.Normal
import kotlin.math.roundToInt


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

    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_begin_xml)
        Normal.initFullScreen(this,true)
        progressBar = findViewById<ProgressBar>(R.id.nova_progress)
        init()

    }

    private fun init() {
        TPAdManager.init(
            this,
            EuphoriaBoard.TAG,
            "0050AC0F82A15B4B5CCEC0E7A5B07A11",
            "5C25F9904EF67322F495A33F1303DB12",
            "02E0F4693311CCA2990355F2BEF35E12",
            "5E4C791BFA1E30844C2FE209130B2912"
        ) {

        }
        timer = TPAdManager.showWelcomeAd( this@BeginXML,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 toHome() {
        startActivity(Intent(this, HomePageXML::class.java))
        finish()
    }

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


}