package importantedto.appliededto.surgeonedto.promiseedto.prospectedto.consumptionedto.blameedto

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.AntennaedtoBinding
import importantedto.admireedto.sweptedto.Differenceedto
import importantedto.afteredto.constitutionaledto.Murderedto
import importantedto.appliededto.surgeonedto.promiseedto.Halcyonedto
import importantedto.concreteedto.cameedto.Hateedto.JUNK_CLEANER
import importantedto.gallonedto.Shoulderedto
import importantedto.gallonedto.Transcendedto
import importantedto.gallonedto.Youthedto
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import kotlin.random.Random

/**
 * 实际清理页面
 */
class Confusionedto : Murderedto<AntennaedtoBinding>() {

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

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

        MainScope().launch(Dispatchers.IO) {
            try {
                listPath.forEach {
                    runCatching { Shoulderedto.delete(it) }
                }
                Youthedto.updateMediaStore(this@Confusionedto, listPath)
            } catch (_: Exception) {
            } finally {

            }

        }
        playAnm()
    }

    override fun initListener() {
        onBackPressedDispatcher.addCallback {
            Toast.makeText(this@Confusionedto, "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.wereedto.rotation = it.animatedValue as Float
            }
            start()
        }
        ValueAnimator.ofInt(0, 100).run {
            duration = Random.nextLong(7000, 8000)
            interpolator = LinearInterpolator()
            addUpdateListener {
                binding.truckedto.text = "${it.animatedValue as Int}"
            }
            doOnEnd {
                Differenceedto.admobMaxShowInterstitialAd(this@Confusionedto,false) {
                    startActivity(
                        Intent(this@Confusionedto, Halcyonedto::class.java).putExtra("from", JUNK_CLEANER)
                            .putExtra("clean_size", intentSize)
                    )
                    finish()
                }
            }
            start()
        }
    }
}