diff --git a/app/src/main/java/li/songe/gkd/data/Rule.kt b/app/src/main/java/li/songe/gkd/data/Rule.kt index ad77951..03cbbcc 100644 --- a/app/src/main/java/li/songe/gkd/data/Rule.kt +++ b/app/src/main/java/li/songe/gkd/data/Rule.kt @@ -19,10 +19,6 @@ data class Rule( */ val matches: List = emptyList(), val excludeMatches: List = emptyList(), - /** - * 任意一个元素是上次点击过的 - */ - val preRules: Set = emptySet(), val actionCd: Long = defaultMiniCd, val actionDelay: Long = 0, val matchLauncher: Boolean = false, @@ -46,6 +42,11 @@ data class Rule( val app: SubscriptionRaw.AppRaw, val subsItem: SubsItem, ) { + /** + * 任意一个元素是上次点击过的 + */ + var preRules: Set = emptySet() + var actionDelayTriggerTime = 0L fun triggerDelay() { // 触发延迟, 一段时间内此规则不可利用 diff --git a/app/src/main/java/li/songe/gkd/util/SubsState.kt b/app/src/main/java/li/songe/gkd/util/SubsState.kt index 6733d56..9859016 100644 --- a/app/src/main/java/li/songe/gkd/util/SubsState.kt +++ b/app/src/main/java/li/songe/gkd/util/SubsState.kt @@ -64,7 +64,7 @@ val appIdToRulesFlow by lazy { // 筛选合法选择器的规则组, 如果一个规则组内某个选择器语法错误, 则禁用/丢弃此规则组 groupRaw.valid }.forEach { groupRaw -> - val ruleGroupList = mutableListOf() + val groupRuleList = mutableListOf() groupRaw.rules.forEachIndexed { ruleIndex, ruleRaw -> val activityIds = (ruleRaw.activityIds ?: groupRaw.activityIds ?: appRaw.activityIds @@ -106,7 +106,7 @@ val appIdToRulesFlow by lazy { val actionDelay = ruleRaw.actionDelay ?: groupRaw.actionDelay ?: appRaw.actionDelay ?: 0 - ruleGroupList.add( + groupRuleList.add( Rule( matchLauncher = matchLauncher, quickFind = quickFind, @@ -135,16 +135,15 @@ val appIdToRulesFlow by lazy { ) ) } - ruleGroupList.forEachIndexed { index, ruleConfig -> - ruleGroupList[index] = ruleConfig.copy( - preRules = ruleGroupList.filter { - (it.key != null) && ruleConfig.preKeys.contains( - it.key - ) - }.toSet() - ) + groupRuleList.forEach { ruleConfig -> + // 保留原始对象引用, 方便判断 lastTriggerRule 时直接使用 === + ruleConfig.preRules = groupRuleList.filter { otherRule -> + (otherRule.key != null) && ruleConfig.preKeys.contains( + otherRule.key + ) + }.toSet() } - rules.addAll(ruleGroupList) + rules.addAll(groupRuleList) } } }