package com.apps.pixwall.view

import android.content.Intent
import android.health.connect.datatypes.units.Percentage
import android.os.Bundle
import android.os.CountDownTimer
import androidx.appcompat.app.AppCompatActivity
import com.ad.maxlibrary.WelComManager.initTimer
import com.apps.pixwall.databinding.ActivityLoadBinding


class LoadActivity : AppCompatActivity() {
    lateinit var binding: ActivityLoadBinding
    private var countDownTimer: CountDownTimer? = null
    private   val time: Long = 14000
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityLoadBinding.inflate(layoutInflater)
        setContentView(binding.root)

        countDownTimer = initTimer(this, time, { aLong: Long ->
            var progressPercentage = ((100 * aLong) / time)
            val i = (100 - progressPercentage).toInt()
            binding.progressbar.progress = i
            null
        }, {
            goMain()
            null
        })
    }

    private fun goMain(){
        binding.progressbar.progress = 100
        val intent= Intent(
            this@LoadActivity,
            MainActivity::class.java
        )
        startActivity(intent)
        finish()
    }

    override fun onDestroy() {
        super.onDestroy()


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