package com.zxhyis.toolss.ui.page.photocompress.photo

import android.content.Intent
import android.graphics.Color
import androidx.activity.OnBackPressedCallback
import androidx.core.view.updatePadding
import com.blankj.utilcode.util.BarUtils
import com.blankj.utilcode.util.ToastUtils
import com.zxhyis.toolss.ad.AdmobUtils
import com.zxhyis.toolss.base.TopActivity
import com.zxhyis.toolss.databinding.ActivityStartCompressionPhotoBinding
import com.zxhyis.toolss.logic.setOnClick


class StartCompressionPhotoActivity : TopActivity<ActivityStartCompressionPhotoBinding>() {

    override fun getViewBinding1(): ActivityStartCompressionPhotoBinding {
        return ActivityStartCompressionPhotoBinding.inflate(layoutInflater)
    }

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

    override fun onPermissionsResult(isGranted: Boolean) {
        if (isGranted) {

        } else {
            finishToMain()
        }
    }

    override fun init() {
        BarUtils.setStatusBarLightMode(this, true)
        BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
        vb.root.updatePadding(top = BarUtils.getStatusBarHeight())
        vb.fanhui.setOnClick(javaClass.simpleName) {
            onBackPressedDispatcher.onBackPressed()
        }

        onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
            override fun handleOnBackPressed() {
                finishToMain()
            }
        })
        vb.btnStarted.setOnClick(javaClass.simpleName) {
            AdmobUtils.showInterstitialAd(this) {
                val mList = ImagesMediaUtils.getAlbums(this)
                if (mList.isNotEmpty()) {
                    startActivity(Intent(this, CompressionPhotoListActivity::class.java))
                    finish()
                } else {
                    ToastUtils.showShort("Album photos not detected, no compression required.")
                }

            }

        }

    }
}
