|
|
@ -16,6 +16,7 @@ object LifecycleHelp : Application.ActivityLifecycleCallbacks { |
|
|
|
|
|
|
|
|
|
|
|
private val activities: MutableList<WeakReference<Activity>> = arrayListOf() |
|
|
|
private val activities: MutableList<WeakReference<Activity>> = arrayListOf() |
|
|
|
private val services: MutableList<WeakReference<BaseService>> = arrayListOf() |
|
|
|
private val services: MutableList<WeakReference<BaseService>> = arrayListOf() |
|
|
|
|
|
|
|
private var finishedListener: (() -> Unit)? = null |
|
|
|
|
|
|
|
|
|
|
|
fun activitySize(): Int { |
|
|
|
fun activitySize(): Int { |
|
|
|
return activities.size |
|
|
|
return activities.size |
|
|
@ -51,6 +52,10 @@ object LifecycleHelp : Application.ActivityLifecycleCallbacks { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun setOnFinishedListener(finishedListener: (() -> Unit)) { |
|
|
|
|
|
|
|
this.finishedListener = finishedListener |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityPaused(activity: Activity) { |
|
|
|
override fun onActivityPaused(activity: Activity) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -65,6 +70,9 @@ object LifecycleHelp : Application.ActivityLifecycleCallbacks { |
|
|
|
for (temp in activities) { |
|
|
|
for (temp in activities) { |
|
|
|
if (temp.get() != null && temp.get() === activity) { |
|
|
|
if (temp.get() != null && temp.get() === activity) { |
|
|
|
activities.remove(temp) |
|
|
|
activities.remove(temp) |
|
|
|
|
|
|
|
if (services.size == 0 && activities.size == 0) { |
|
|
|
|
|
|
|
onFinished() |
|
|
|
|
|
|
|
} |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -93,8 +101,15 @@ object LifecycleHelp : Application.ActivityLifecycleCallbacks { |
|
|
|
for (temp in services) { |
|
|
|
for (temp in services) { |
|
|
|
if (temp.get() != null && temp.get() === service) { |
|
|
|
if (temp.get() != null && temp.get() === service) { |
|
|
|
services.remove(temp) |
|
|
|
services.remove(temp) |
|
|
|
|
|
|
|
if (services.size == 0 && activities.size == 0) { |
|
|
|
|
|
|
|
onFinished() |
|
|
|
|
|
|
|
} |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun onFinished() { |
|
|
|
|
|
|
|
finishedListener?.invoke() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |