package com.aves.google_cast


import android.app.Activity
import android.app.Application
import android.os.Bundle

/**
 * Fornisce sempre l'Activity corrente.
 * Necessario per Cast dialog.
 */
object CastActivityProvider : Application.ActivityLifecycleCallbacks {

    var currentActivity: Activity? = null
        private set

    override fun onActivityResumed(activity: Activity) {
        currentActivity = activity
    }

    override fun onActivityPaused(activity: Activity) {}
    override fun onActivityStarted(activity: Activity) {}
    override fun onActivityDestroyed(activity: Activity) {
        if (currentActivity === activity) {
            currentActivity = null
        }
    }

    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
    override fun onActivityStopped(activity: Activity) {}
    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}
}

