package com.gh.gamecenter.common.base

import android.app.Activity
import android.app.Application
import android.os.Bundle
import com.gh.gamecenter.core.utils.CurrentActivityHolder
import com.lightgame.utils.AppManager

class GlobalActivityLifecycleObserver : Application.ActivityLifecycleCallbacks {

    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
        AppManager.getInstance().addActivity(activity)
    }

    override fun onActivityStarted(activity: Activity) {

    }

    override fun onActivityResumed(activity: Activity) {
        CurrentActivityHolder.activitySet.add(activity)
    }

    override fun onActivityPaused(activity: Activity) {
        CurrentActivityHolder.activitySet.remove(activity)
        if (activity.isFinishing) {
            AppManager.getInstance().finishActivity(activity)
        }
    }

    override fun onActivityStopped(activity: Activity) {

    }

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

    }

    override fun onActivityDestroyed(activity: Activity) {
        AppManager.getInstance().removeActivityFromStack(activity)
    }
}