package com.flowing.light.board.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.util.Log
import android.widget.ProgressBar
import com.flowing.light.board.BuildConfig
import com.flowing.light.board.FlowingLightBoard
import com.flowing.light.board.FlowingLightBoard.Companion.TAG
import com.flowing.light.board.R
import com.flowing.light.board.ironad.AdManager
import com.flowing.light.board.tools.Common
import com.unity3d.mediation.LevelPlay
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)
        Common.initFullScreen(this,true)
        progressBar = findViewById<ProgressBar>(R.id.nova_progress)
        init()

    }

    private fun init() {

        if (BuildConfig.DEBUG) {
            LevelPlay.validateIntegration(this)
        }
        timer = AdManager.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 toHome() {
        startActivity(Intent(this, HomeActivity::class.java))
        finish()
    }

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


}