package com.zxhyis.toolss.ui.page.speed

import android.animation.Animator
import android.content.Intent
import android.graphics.Color
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import com.blankj.utilcode.util.BarUtils
import com.zxhyis.toolss.base.TopActivity
import com.zxhyis.toolss.databinding.ActivityLayoutSpeedBinding
import com.zxhyis.toolss.ui.AFunOb.BATTERY_OPTIMIZER

class BatteryOptimizerActivity : TopActivity<ActivityLayoutSpeedBinding>() {
    override fun getViewBinding1(): ActivityLayoutSpeedBinding {
        return ActivityLayoutSpeedBinding.inflate(layoutInflater)
    }

    override fun init() {
        BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
        vb.root.updatePadding(top = BarUtils.getStatusBarHeight())
        vb.idOneLottie.imageAssetsFolder = "battery_scan/images/"
        vb.idOneLottie.setAnimation("battery_scan/data.json")
        vb.idOneLottie.playAnimation()
        vb.root.postDelayed({
            vb.idOneLottie.isVisible = false
            vb.idScaning.text = "Optimizing"

            playRocket()
        }, 3000)
    }

    private fun playRocket() {
        vb.idRocket.imageAssetsFolder = "battery_save/images/"
        vb.idRocket.setAnimation("battery_save/data.json")
        vb.idRocket.playAnimation()
        vb.idRocket.addAnimatorListener(object : Animator.AnimatorListener {
            override fun onAnimationStart(p0: Animator) {

            }

            override fun onAnimationEnd(p0: Animator) {
                startActivity(Intent(this@BatteryOptimizerActivity, SpeedFinishActivity::class.java).putExtra("type", BATTERY_OPTIMIZER))
                finish()
            }

            override fun onAnimationCancel(p0: Animator) {

            }

            override fun onAnimationRepeat(p0: Animator) {

            }

        })
    }
}