From 2c1f0ccfbd63aba70fa3b62a737d4d6634e76427 Mon Sep 17 00:00:00 2001 From: lisonge Date: Sat, 28 Oct 2023 13:58:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20index=3D0=20=E7=9A=84=20rule=20=E7=9A=84?= =?UTF-8?q?=20preRules=20=E4=B8=8D=E7=94=9F=E6=95=88=20=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88=20(#213)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/li/songe/gkd/data/Rule.kt | 9 ++++---- .../main/java/li/songe/gkd/util/SubsState.kt | 21 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) 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 ad779519a..03cbbccad 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 6733d56c1..98590164e 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) } } }