package com.gh.gamecenter.common.base

import android.app.Activity
import com.gh.gamecenter.common.entity.PageEntity
import java.lang.ref.WeakReference
import java.util.*

object GlobalActivityManager {
    private var mCurrentActivityWeakRef: WeakReference<Activity>? = null

    var currentActivity: Activity?
        get() = mCurrentActivityWeakRef?.get()
        set(activity) {
            mCurrentActivityWeakRef = WeakReference<Activity>(activity)
        }

    val pageStack = Stack<PageEntity>()

    @JvmStatic
    fun getCurrentPageEntity(): PageEntity = if (pageStack.isNotEmpty()) {
        pageStack.peek()
    } else {
        PageEntity()
    }

    @JvmStatic
    fun getLastPageEntity(): PageEntity = if (pageStack.size >= 2) {
        pageStack[pageStack.size - 2]
    } else {
        PageEntity()
    }
}