package com.rgt.superr.ui.guide

import android.util.Log
import com.rgt.superr.R
import com.rgt.superr.base.BaseActivity
import com.rgt.superr.base.jumpAction
import com.rgt.superr.bean.FeatureBean.Companion.BATTERY_INFO
import com.rgt.superr.bean.FeatureBean.Companion.JUNK_CLEAN
import com.rgt.superr.bean.FeatureBean.Companion.LARGE_FILE_CLEAN
import com.rgt.superr.bean.FeatureBean.Companion.PHOTO_COMPRESSION
import com.rgt.superr.bean.FeatureBean.Companion.SCREENSHOT_CLEAN
import com.rgt.superr.bean.FeatureBean.Companion.SIMILAR_PHOTOS
import com.rgt.superr.bean.FeatureBean.Companion.UNINSTALL_APP
import com.rgt.superr.business.ads.AdsMgr
import com.rgt.superr.databinding.ActivityGuideExperienceBinding
import com.rgt.superr.ui.dialog.StoragePermissionDialog
import com.rgt.superr.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()

        }
    }
}