package rowedto.jockeyedto.sheetedto.atticedto.teacheredto.characteristicedto

import android.content.Intent
import android.widget.Toast
import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope
import com.base.datarecovery.databinding.ValidedtoBinding
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import rowedto.jockeyedto.sheetedto.knewedto.economicedto.copyrightedto.Crossingedto
import rowedto.jockeyedto.sheetedto.strangeedto.pyramidedto.particlesedto.Scandaledto
import kotlin.random.Random

class Surroundedto : Crossingedto<ValidedtoBinding>() {

    override val binding: ValidedtoBinding by lazy {
        ValidedtoBinding.inflate(layoutInflater)
    }
    private var job: Job? = null

    override fun initView() {
        Scandaledto.admobMaxShowNativeAd(this,binding.tooledto,1)
    }

    fun jumpJob() = lifecycleScope.launch {
        delay(Random.nextLong(3000, 4500))
        Scandaledto.admobMaxShowInterstitialAd(this@Surroundedto) {
            startActivity(Intent(this@Surroundedto, Cattleedto::class.java))
            finish()
        }
    }

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

    override fun onResume() {
        super.onResume()
        if (job?.isActive == false || job == null) {
            job = jumpJob()
        }
    }

    override fun onPause() {
        super.onPause()
        job?.cancel()
        job = null
    }

}