package com.base.appzxhy.ui.guide

import android.util.Log
import com.base.appzxhy.R
import com.base.appzxhy.base.BaseActivity
import com.base.appzxhy.base.jumpAction
import com.base.appzxhy.bean.FeatureBean.Companion.BATTERY_INFO
import com.base.appzxhy.bean.FeatureBean.Companion.JUNK_CLEAN
import com.base.appzxhy.bean.FeatureBean.Companion.LARGE_FILE_CLEAN
import com.base.appzxhy.bean.FeatureBean.Companion.PHOTO_COMPRESSION
import com.base.appzxhy.bean.FeatureBean.Companion.SCREENSHOT_CLEAN
import com.base.appzxhy.bean.FeatureBean.Companion.SIMILAR_PHOTOS
import com.base.appzxhy.bean.FeatureBean.Companion.UNINSTALL_APP
import com.base.appzxhy.business.ads.AdsMgr
import com.base.appzxhy.databinding.ActivityGuideExperienceBinding
import com.base.appzxhy.ui.dialog.StoragePermissionDialog
import com.base.appzxhy.utils.PermissionUtils.requestStoragePermission

class GuideExperienceActivity : BaseActivity<ActivityGuideExperienceBinding>(
    ActivityGuideExperienceBinding::inflate
) {


    override fun initView() {
        super.initView()
        val appName = getString(R.string.app_name)
        binding.tvTip.text = getString(R.string.app_function_experience_tip, appName)
        AdsMgr.showNative(binding.flAd, R.layout.layout_admob_native_custom)
    }

    override fun handleBackCallBack() {

    }

    override fun initListener() {
        super.initListener()

        binding.tvBtn.setOnClickListener {

            val dialog = StoragePermissionDialog(this)

            dialog.action = {
                requestStoragePermission(launcher) {
                    Log.e(TAG, "requestStoragePermission callback")
                    if (it) {
                        val key = arrayOf(JUNK_CLEAN, SCREENSHOT_CLEAN, LARGE_FILE_CLEAN, PHOTO_COMPRESSION, SIMILAR_PHOTOS).random()
                        jumpAction(key)
                    } else {
                        val key = arrayOf(BATTERY_INFO, UNINSTALL_APP).random()
                        jumpAction(key)
                    }
                }
            }
            dialog.dialog.setOnDismissListener {
                if (!dialog.actionEd) {
                    val key = arrayOf(BATTERY_INFO, UNINSTALL_APP).random()
                    jumpAction(key)
                }
            }
            dialog.showDialog()

        }
    }
}