package com.example.base.common

import android.app.Activity
import java.util.LinkedList


/**
 * 单例数据共享
 */
class ActivityManager {

    companion object {

        private val mActivityList: LinkedList<Activity> by lazy { LinkedList<Activity>() }

        fun addActivity(activity: Activity): Boolean {
            return mActivityList.add(activity)
        }

        fun removeActivity(activity: Activity): Boolean {
            return mActivityList.remove(activity)
        }

        fun hasActivity(clazz: Class<out Activity>): Boolean {
            return mActivityList.find { it.javaClass == clazz } != null
        }

        fun lastOrNull(): Activity? {
            return mActivityList.lastOrNull()
        }

        fun getAllActivity(): LinkedList<Activity>  {
            return mActivityList
        }

        fun clear() {
            return mActivityList.clear()
        }

        fun exitApp() {
            mActivityList.forEach {
                it.finish()
            }
        }
    }
}