//package com.tool.zxdemo
//
//import android.Manifest
//import android.content.Intent
//import android.os.Build
//import android.os.Bundle
//import android.widget.Toast
//import androidx.activity.result.contract.ActivityResultContracts
//import androidx.appcompat.app.AppCompatActivity
//import androidx.core.view.isVisible
//import com.applovin.sdk.AppLovinSdk
//import com.reyun.solar.engine.SolarEngineConfig
//import com.reyun.solar.engine.SolarEngineManager
//import com.tool.zxdemo.admob.com.zxdemo.admob.AdmobHelper
//import com.tool.zxdemo.databinding.ActivityMainBinding
//import com.tool.zxdemo.http.com.zxdemo.http.ZxHttp
//import com.tool.zxdemo.service.com.zxdemo.service.PermanentNotifyService
//import com.tool.zxdemo.service.com.zxdemo.service.PermanentNotifyService.Companion.startOmgNotification
//import com.tool.zxdemo.utils.com.zxdemo.utils.GlobalTimer
//import com.tool.zxdemo.utils.com.zxdemo.utils.SpUtils
//import java.util.Random
//
//class MainActivity : AppCompatActivity() {
//
//    private val binding by lazy {
//        ActivityMainBinding.inflate(layoutInflater)
//    }
//
//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//        setContentView(binding.root)
//        SolarEngineManager.getInstance().preInit(this, "f3ea1ff055365453")//（归因）同意隐私之前进行预加载
//        var config = SolarEngineConfig.Builder().build()//同意之后再进行初始化
//        SolarEngineManager.getInstance()
//            .initialize(this, "APP_KEY", config)
//        if (Build.VERSION.SDK_INT >= 33) {
//            registerForActivityResult(ActivityResultContracts.RequestPermission()) {}.launch(
//                Manifest.permission.POST_NOTIFICATIONS
//            )
//        }
//        startOmgNotification()
//
//        val random = Random()
//        val randomNumber = random.nextInt(5)
//        var sTimer = com.zxdemo.utils.SpUtils.getInstance().getBoolean("sTimer", false)
//        binding.sTimer.isChecked = sTimer
////        if (sTimer) {
////            com.zxdemo.utils.GlobalTimer.getInstance()
////                .scheduleTask(3 * 1000L, 5 * 1000L)
////        }
//
//        var sNotify = com.zxdemo.utils.SpUtils.getInstance().getBoolean("sNotify", false)
//        binding.sNotify.isChecked = sNotify
//        binding.sAd.isChecked = com.zxdemo.admob.AdmobHelper.useAdmob
//        binding.sAd.setOnCheckedChangeListener { buttonView, isChecked ->
//            com.zxdemo.admob.AdmobHelper.useAdmob = isChecked
//            com.zxdemo.admob.AdmobHelper.init(this, {}, {})
//            if (isChecked) {
//                binding.buttonAppApplovin.isVisible = false
//            } else {
//                binding.buttonAppApplovin.apply {
//                    setOnClickListener {
//                        AppLovinSdk.getInstance(context).showMediationDebugger()
//                    }
//                }.isVisible = true
//            }
//        }
//        binding.sTimer.setOnCheckedChangeListener { buttonView, isChecked ->
//            if (isChecked) {
//                com.zxdemo.utils.GlobalTimer
//                    .scheduleTask(3 * 1000L, 20 * 1000L)
//            } else {
//                com.zxdemo.utils.GlobalTimer.stopTaskTimer()
//            }
//            com.zxdemo.utils.SpUtils.getInstance().putBoolean("sTimer", isChecked)
//        }
//        binding.sNotify.setOnCheckedChangeListener { buttonView, isChecked ->
//            if (isChecked) {
//                startOmgNotification()
//            } else {
//                val serviceIntent = Intent(this, com.zxdemo.service.PermanentNotifyService::class.java)
//                stopService(serviceIntent)
//            }
//            com.zxdemo.utils.SpUtils.getInstance().putBoolean("sNotify", isChecked)
//        }
//
//        binding.buttonAppOpen.setOnClickListener {
//            if (com.zxdemo.admob.AdmobHelper.isLoadingAppOpenAd) {
//                Toast.makeText(this, "请求开屏广告中请稍后", Toast.LENGTH_SHORT).show()
//                return@setOnClickListener
//            }
//            com.zxdemo.admob.AdmobHelper.showAppOpenAd(this, failed = {
//                Toast.makeText(this, "显示开屏广告失败", Toast.LENGTH_SHORT).show()
//            })
//        }
//        binding.buttonInterstitial.setOnClickListener {
//            if (com.zxdemo.admob.AdmobHelper.isLoadingInterstitialAd) {
//                Toast.makeText(this, "请求插屏广告中请稍后", Toast.LENGTH_SHORT).show()
//                return@setOnClickListener
//            }
//            com.zxdemo.admob.AdmobHelper.showInterstitialAd(this, failed = {
//                Toast.makeText(this, "显示插屏广告失败", Toast.LENGTH_SHORT).show()
//            })
//        }
//        binding.buttonBanner.setOnClickListener {
//            Toast.makeText(this, "请求Banner广告中请稍后...", Toast.LENGTH_SHORT).show()
//            binding.buttonBanner.isClickable = false
//            com.zxdemo.admob.AdmobHelper.showBannerAd(
//                this,
//                binding.frameBanner,
//                completed = {
//                    binding.buttonBanner.isClickable = true
//                    println()
//                },
//                failed = {
//                    binding.buttonBanner.isClickable = true
//                    Toast.makeText(this, "显示Banner广告失败", Toast.LENGTH_SHORT).show()
//                }
//            )
//        }
//        binding.buttonNative.setOnClickListener {
//            Toast.makeText(this, "请求原生广告中请稍后...", Toast.LENGTH_SHORT).show()
//            binding.buttonNative.isClickable = false
//            com.zxdemo.admob.AdmobHelper.showNativeAd(
//                this,
//                { nativeAd ->
//                    binding.buttonNative.isClickable = true
//                    binding.adNative.setNativeAd(nativeAd)
//                },
//                { nativeAdLoader, nativeMaxAd ->
//                    binding.buttonNative.isClickable = true
//                    binding.adNative.setNativeAd(nativeAdLoader, nativeMaxAd)
//                },
//                {
//                    binding.buttonNative.isClickable = true
//                    Toast.makeText(this, "显示原生广告失败", Toast.LENGTH_SHORT).show()
//                }
//            )
//        }
//        com.zxdemo.http.ZxHttp.getHttpConfig { }
//        com.zxdemo.http.ZxHttp.getBlacklist { com.zxdemo.admob.AdmobHelper.blacklist = it }
//        com.zxdemo.admob.AdmobHelper.init(this, {}, {})
//        if (!com.zxdemo.admob.AdmobHelper.useAdmob) {
//            binding.buttonAppApplovin.apply {
//                setOnClickListener {
//                    AppLovinSdk.getInstance(context).showMediationDebugger()
//                }
//            }.isVisible = true
//        }
//    }
//}