package rowedto.jockeyedto.sheetedto.atticedto.directionedto.noxiousedto.batedto

import android.animation.ValueAnimator
import android.content.Intent
import android.graphics.Color
import android.view.animation.LinearInterpolator
import android.widget.Toast
import androidx.activity.addCallback
import androidx.core.animation.doOnEnd
import androidx.core.view.updatePadding
import com.base.datarecovery.databinding.CerealedtoBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import rowedto.jockeyedto.sheetedto.atticedto.Softedto
import rowedto.jockeyedto.sheetedto.knewedto.economicedto.copyrightedto.Crossingedto
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Flameedto
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Responsibilityedto
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Spareedto
import rowedto.jockeyedto.sheetedto.strangeedto.pyramidedto.particlesedto.Scandaledto
import kotlin.random.Random

/**
 * 实际清理页面
 */
class Negativeedto : Crossingedto<CerealedtoBinding>() {

    override val binding: CerealedtoBinding by lazy {
        CerealedtoBinding.inflate(layoutInflater)
    }
    private val intentSize by lazy {
        intent.getLongExtra("size", -1)
    }
    private val listPath by lazy {
        intent.getStringArrayExtra("list") ?: arrayOf()
    }
    private val type by lazy {
        intent.getStringExtra("type") ?: ""
    }

    override fun initView() {
        Spareedto.setStatusBarColor(this, Color.TRANSPARENT)
        binding.root.updatePadding(top = Spareedto.getStatusBarHeight())
        Scandaledto.admobMaxShowNativeAd(this,binding.tooledto,1)
        MainScope().launch(Dispatchers.IO) {
            try {
                listPath.forEach {
                    runCatching { Flameedto.delete(it) }
                }
                Responsibilityedto.updateMediaStore(this@Negativeedto, listPath)
            } catch (_: Exception) {
            } finally {

            }

        }
        playAnm()
    }

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

    private fun playAnm() {
        ValueAnimator.ofFloat(0f, 360f).run {
            duration = 1000
            repeatMode = ValueAnimator.RESTART
            repeatCount = ValueAnimator.INFINITE
            interpolator = LinearInterpolator()
            addUpdateListener {
                binding.pressureedto.rotation = it.animatedValue as Float
            }
            start()
        }
        ValueAnimator.ofInt(0, 100).run {
            duration = Random.nextLong(7000, 8000)
            interpolator = LinearInterpolator()
            addUpdateListener {
                binding.costedto.text = "${it.animatedValue as Int}"
            }
            doOnEnd {
                Scandaledto.admobMaxShowInterstitialAd(this@Negativeedto,false) {
                    startActivity(
                        Intent(this@Negativeedto, Softedto::class.java)
                            .putExtra("from", type)
                            .putExtra("clean_size", intentSize)
                    )
                    finish()
                }
            }
            start()
        }
    }
}