package com.convenient.android.common.base.view

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import com.google.android.gms.analytics.GoogleAnalytics

/**
 * @classname BaseActivityLifecycleEvents
 * @author LiuXiaoLong
 * @date 2022-07-27 PM
 * @description BaseActivity 生命周期监听，在对应生命周期执行特定方法
 */
open class BaseActivityLifecycleEvents(var activity: BaseActivity) : LifecycleEventObserver {
    override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
        when (event) {
            Lifecycle.Event.ON_CREATE -> {
            }
            Lifecycle.Event.ON_RESUME -> {
                activity.isCurrentFront = true
            }
            Lifecycle.Event.ON_PAUSE -> {
                activity.isCurrentFront = false
            }
            Lifecycle.Event.ON_START -> {
                GoogleAnalytics.getInstance(activity).reportActivityStart(activity)
            }
            Lifecycle.Event.ON_STOP -> {
                GoogleAnalytics.getInstance(activity).reportActivityStop(activity)
            }
            Lifecycle.Event.ON_DESTROY -> {
                activity.mImmersionBar = null
                activity.handler.removeCallbacksAndMessages(null)
            }
            Lifecycle.Event.ON_ANY -> {
                //Other
            }
        }
    }
}