package fsir.tqqe

import android.content.Intent
import android.graphics.Color
import android.os.Handler
import androidx.activity.OnBackPressedCallback
import androidx.core.view.updatePadding
import com.blankj.utilcode.util.BarUtils
import com.blankj.utilcode.util.ToastUtils
import com.test.basd.supercleanermax.R
import com.test.basd.supercleanermax.databinding.XtietnBinding
import pxds.lmmd.zmwf.Bpfw
import pxds.lmmd.zmwf.Khko.string
import pxds.lmmd.zmwf.jyyf.hwbn.wzxb.Utdc
import kotlin.random.Random

class Ausa : Bpfw<XtietnBinding>() {

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

    var isplay = 0

    override fun initView() {
        BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
        binding.root.updatePadding(top = BarUtils.getStatusBarHeight())

        onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
            override fun handleOnBackPressed() {
                finishToMain()
            }
        })

    }

    override fun onPermissionsResult(isGranted: Boolean) {
        if (isGranted) {
            isplay += 1
            if (isplay == 1) {
                playLottie()
            }
        } else {
            finishToMain()
        }
    }

    private fun playLottie(){
        binding.gxzycvd.imageAssetsFolder = R.string.ކޠކޟނ_D.string()
        binding.gxzycvd.setAnimation(R.string.ސހޓށދ_D.string())
        binding.gxzycvd.playAnimation()
        Handler().postDelayed({
            Utdc.showInterstitialAd(this) {
                val mList = Lpgx.getAlbums(this)
                if (mList.isNotEmpty()) {
                    startActivity(Intent(this, Mhoo::class.java))
                    finish()
                } else {
                    ToastUtils.showShort(R.string.ޛހވޚތ_D.string())
                }
            }
        },Random.nextLong(3000,4000))
    }

    override fun onStart() {
        super.onStart()
        checkPermission()
    }
}