package com.base.datarecovery.activity.appmanager

import android.annotation.SuppressLint
import android.content.Intent
import android.view.View
import android.widget.Toast
import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope
import com.base.datarecovery.ads.AdmobMaxHelper
import com.base.datarecovery.databinding.ActivityAppManagerAnimationBinding
import com.base.datarecovery.help.BaseActivity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.random.Random

class AppManagerAnimationActivity : BaseActivity<ActivityAppManagerAnimationBinding>() {

    override val binding: ActivityAppManagerAnimationBinding by lazy {
        ActivityAppManagerAnimationBinding.inflate(layoutInflater)
    }

    override fun initView() {
        playLottie()
    }

    override fun initListener() {
        onBackPressedDispatcher.addCallback {
            Toast.makeText(this@AppManagerAnimationActivity, "wait a moment", Toast.LENGTH_SHORT).show()
        }
    }

    @SuppressLint("SetTextI18n")
    private fun playLottie() {
        binding.lottie.imageAssetsFolder = "app_manager/images/"
        binding.lottie.setAnimation("app_manager/data.json")
        binding.lottie.playAnimation()
        lifecycleScope.launch(Dispatchers.Main) {
            delay(Random.nextLong(4000, 6000))
            binding.lottie.visibility = View.GONE
            binding.lottieCompleted.visibility = View.VISIBLE
            binding.lottieCompleted.playAnimation()
            binding.tv.text = "Completed!"
            delay(1000)

            AdmobMaxHelper.admobMaxShowInterstitialAd(this@AppManagerAnimationActivity){
                startActivity(Intent(this@AppManagerAnimationActivity, AppManagerActivity::class.java))
                finish()
            }

        }
    }

}