package com.base.browserwhite

import android.app.Activity
import android.app.Application
import android.os.Bundle
import com.base.browserwhite.utils.ActivityManagerUtils

class MyApplication : Application() {

    companion object {
        lateinit var context: MyApplication
    }

    override fun onCreate() {
        super.onCreate()
        context = this
        initLifeListener()
    }

    private fun initLifeListener() {
        registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
            private var count = 0
            override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
                ActivityManagerUtils.getInstance().addActivity(activity)
            }

            override fun onActivityStarted(activity: Activity) {
//                LogEx.logDebug(TAG, "onActivityStarted")

//                count++
//                lastTimeResume = System.currentTimeMillis()
//                if (count == 1 && isHotLaunch()) {
//
//                    val topActivity: Activity? = ActivityManagerUtils.getInstance().topActivity
//
//                    var flag = if (topActivity == null) {
//                        true
//                    } else {
//                        com.base.filerecoveryblack.ConfigHelper.noLoadingActivities.all {
//                            !topActivity.localClassName.contains(it, true)
//                        }
//                    }
//
//                    if (activity.localClassName.contains("AppLovinFullscreenActivity")) {
//                        flag = false
//                    }
//                    LogEx.logDebug(TAG, "flag=$flag" + "   activity:" + activity.localClassName)
//
//                    if (flag && !isInterOpenShowing) {
//                        if (AdmobMaxHelper.isOpenAdLoaded()) {
//                            var loaded: Boolean = true
//                            AdmobMaxHelper.admobMaxShowOpenAd(activity, {
//                                loaded = it
//                            }, {
//                                val sp = AppPreferences.getInstance().getString("splashShowInter", "0").toInt()
//                                if (sp == 1 && !loaded) {
//                                    AdmobMaxHelper.admobMaxShowInterstitialAd(activity)
//                                }
//                            })
//                        } else {
//                            topActivity?.startActivity(
//                                Intent(
//                                    topActivity,
//                                    SplashActivity::class.java
//                                ).apply {
//                                    putExtra("isHotLaunch", true)
//                                    putExtra("type", -1)
//                                })
//                        }
//                    }
//                }
//                lastTimeResume = 0
            }

            override fun onActivityResumed(activity: Activity) {
//                LogEx.logDebug(TAG, "onActivityResumed")
//                PAUSED_VALUE = 1
            }


            override fun onActivityPaused(activity: Activity) {
//                LogEx.logDebug(TAG, "onActivityPaused")
//                PAUSED_VALUE = 2
//                lastTimePause = System.currentTimeMillis()
            }

            override fun onActivityStopped(activity: Activity) {
                count--
            }

            override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}

            override fun onActivityDestroyed(activity: Activity) {
                ActivityManagerUtils.getInstance().removeActivity(activity)
            }
        })
    }
}