package com.base.scanqrclear.ui.main

import androidx.activity.addCallback
import com.base.scanqrclear.ads.AdsMgr
import com.base.scanqrclear.ads.AdsShowCallBack
import com.base.scanqrclear.base.BaseActivity
import com.base.scanqrclear.bean.config.AdConfigBean
import com.base.scanqrclear.databinding.ActivityScanBinding
import com.base.scanqrclear.qr.CameraUtils

/**
 *Create by SleepDog on 2025-01-20
 */
class ScanAc : BaseActivity<ActivityScanBinding>(ActivityScanBinding::inflate) {
    var cameraUtils: CameraUtils? = null

    override fun initView() {
        super.initView()
        cameraUtils = CameraUtils(this)
    }

    override fun onResumeOneShoot() {
        super.onResumeOneShoot()
        if (AdConfigBean.adsConfigBean.functionInShowAd) {
            AdsMgr.showInsert(this, false, object : AdsShowCallBack() {
                override fun close(where: Int) {
                }

                override fun failed(where: Int) {
                }

                override fun googleFailed(where: Int) {
                }
            })
        }
    }

    override fun initListener() {
        super.initListener()
        onBackPressedDispatcher.addCallback {
            if (AdConfigBean.adsConfigBean.functionBackShowAd) {
                AdsMgr.showInsert(this@ScanAc, false, object : AdsShowCallBack() {
                    override fun close(where: Int) {
                        finishToMainTop()
                    }

                    override fun failed(where: Int) {
                        finishToMainTop()
                    }

                    override fun googleFailed(where: Int) {
                        finishToMainTop()
                    }
                })
            }
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        cameraUtils?.unBind()
        cameraUtils = null
    }
}