package com.gallery.free.wallpaper

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import androidx.appcompat.app.AppCompatActivity
import com.ad.ironsourcelibrary.ISAdManager
import com.gallery.free.wallpaper.databinding.ActivitySplaBinding
import com.gallery.free.wallpaper.environment.MainActivity2
import com.gallery.free.wallpaper.environment.hy.IdProvider

class SplashActivity : AppCompatActivity() {
    private var countDownTimer: CountDownTimer? = null
    private var vb: ActivitySplaBinding? = null
    private val totalTime: Long = 15000

    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        vb = ActivitySplaBinding.inflate(layoutInflater)
        Utils_com.initFull(this, true)
        setContentView(vb?.getRoot())
        if (IdProvider().getId() == 0L) {
            countDownTimer = ISAdManager.showWelcomeAd(this, totalTime, { millisUntilFinished ->
                val progressPercentage = ((100 * millisUntilFinished) / totalTime).toInt()

                val countdownPercentage = 100 - progressPercentage

                vb?.progressbar?.progress = countdownPercentage
            }) {
                vb?.progressbar?.progress = 100
                val intent = Intent(this@SplashActivity, MainActivity::class.java)
                startActivity(intent)
                finish()
            }
            countDownTimer?.start()
        } else {
            val intent = Intent(this@SplashActivity, MainActivity2::class.java)
            startActivity(intent)
            finish()
        }
    }


    override fun onDestroy() {
        super.onDestroy()
        countDownTimer?.cancel()
        countDownTimer = null
    }
}