package com.design.zenspace.preview

import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import com.ad.tradpluslibrary.TPAdManager
import com.design.zenspace.DApplication
import com.design.zenspace.databinding.ActivityComeInBinding
import com.design.zenspace.tools.TopBarUtils

class ComeInActivity : AppCompatActivity() {
    lateinit var binding: ActivityComeInBinding
    private var handler: Handler = Handler()
    private var time: Long = 14000
    private var countDownTimer: CountDownTimer? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityComeInBinding.inflate(layoutInflater)
        setContentView(binding.root)
        TPAdManager.init(
            this,
            DApplication.TAG,
            "B40C100CB1E175ED81EFC575BFFB3511",
            "99E134664DC9E21D796BDF7747FCFF12",
            "0B01387BA902075D61D1265B59099412",
            "43A0C367BC57777A6DA8B22FF2A1F312"
        ) {

        }
        TopBarUtils.setStatusBar(this.window)
        TopBarUtils.setLightStatusBar(this.window,true)

        countDownTimer = TPAdManager.showWelcomeAd(
            this@ComeInActivity,
            time,
            { aLong ->
                val progressPercentage = (100 * aLong) / time
                val percentage = 100 - progressPercentage
                binding.progressbar.progress = percentage.toInt()
            },
            {
                val intent= Intent(
                    this@ComeInActivity,
                    CateAndLikActivity::class.java
                )
                startActivity(intent)
                finish()
            }
        )
        countDownTimer?.start()
    }

    override fun onDestroy() {
        super.onDestroy()
        handler.removeCallbacksAndMessages(null)

        if (countDownTimer != null) {
            countDownTimer!!.cancel()
        }
    }
}