package com.base.datarecovery.activity.whatsapp

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.ActivityWhatsAppCleanerAnimationBinding
import com.base.datarecovery.help.BaseActivity
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.random.Random

class WhatsAppCleanerAnimationActivity : BaseActivity<ActivityWhatsAppCleanerAnimationBinding>() {


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

    override fun initView() {
        playLottie()
    }

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

    @SuppressLint("SetTextI18n")
    private fun playLottie() {
        binding.lottie.imageAssetsFolder = "junk_scan/images/"
        binding.lottie.setAnimation("junk_scan/data.json")
        binding.lottie.playAnimation()
        lifecycleScope.launch {
            delay(Random.nextLong(3500, 4500))
            binding.lottie.cancelAnimation()
            binding.lottie.visibility = View.GONE
            binding.lottieCompleted.visibility = View.VISIBLE
            binding.lottieCompleted.playAnimation()
            binding.tv.text="Completed!"
            delay(1000)
            AdmobMaxHelper.admobMaxShowInterstitialAd(this@WhatsAppCleanerAnimationActivity){
                startActivity(Intent(this@WhatsAppCleanerAnimationActivity, WhatsAppCleanerActivity::class.java))
                finish()
            }
        }

    }


}