fix: activityId 概率复用错误

This commit is contained in:
lisonge 2023-11-24 23:12:51 +08:00
parent a1518c70ad
commit bc506ff599

View File

@ -28,15 +28,18 @@ data class ActivityRule(
val activityRuleFlow by lazy { MutableStateFlow(ActivityRule()) }
private val lastActivityIdCacheMap by lazy { mutableMapOf<String, String>() }
private var lastTopActivity: TopActivity? = null
private fun getFixTopActivity(): TopActivity? {
val top = topActivityFlow.value ?: return null
if (top.activityId == null) {
topActivityFlow.value = top.copy(activityId = lastActivityIdCacheMap[top.appId])
if (lastTopActivity?.appId == top.appId) {
// 当从通知栏上拉返回应用等时, activityId 的无障碍事件不会触发, 此时复用上一次获得的 activityId 填充
topActivityFlow.value = lastTopActivity
}
} else {
// 当从通知栏上拉返回应用等时, activityId 的无障碍事件不会触发, 此时使用上一次获得的 activityId 填充
lastActivityIdCacheMap[top.appId] = top.activityId
// 仅保留最近的有 activityId 的单个 TopActivity
lastTopActivity = top
}
return topActivityFlow.value
}