This commit is contained in:
David Langley 2021-07-19 22:07:20 +01:00
parent a29ccda68e
commit 55902b58ac
1 changed files with 6 additions and 6 deletions

View File

@ -89,18 +89,19 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
private fun getNotificationIndexForRule(rule: PushRule): NotificationIndex? { private fun getNotificationIndexForRule(rule: PushRule): NotificationIndex? {
return NotificationIndex.values().firstOrNull { return NotificationIndex.values().firstOrNull {
// Get the actions for the index
val standardAction = getStandardAction(rule.ruleId, it) ?: return@firstOrNull false val standardAction = getStandardAction(rule.ruleId, it) ?: return@firstOrNull false
val indexActions = standardAction.actions ?: listOf() val indexActions = standardAction.actions ?: listOf()
// Check if the input rule matches a rule generated from the static rule definitions
val targetRule = rule.copy(enabled = standardAction != StandardAction.Disabled, actions = indexActions.toJson()) val targetRule = rule.copy(enabled = standardAction != StandardAction.Disabled, actions = indexActions.toJson())
val match = ruleMatches(rule, targetRule) ruleMatches(rule, targetRule)
match
} }
} }
private fun ruleMatches(rule: PushRule, targetRule: PushRule): Boolean { private fun ruleMatches(rule: PushRule, targetRule: PushRule): Boolean {
return (!rule.enabled && !targetRule.enabled) || //Rules match if both are disabled, or if both are enabled and their highlight/sound/notify actions match up.
(rule.enabled return (!rule.enabled && !targetRule.enabled)
|| (rule.enabled
&& targetRule.enabled && targetRule.enabled
&& rule.getHighlight() == targetRule.getHighlight() && rule.getHighlight() == targetRule.getHighlight()
&& rule.getNotificationSound() == targetRule.getNotificationSound() && rule.getNotificationSound() == targetRule.getNotificationSound()
@ -108,7 +109,6 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
&& rule.shouldNotNotify() == targetRule.shouldNotNotify()) && rule.shouldNotNotify() == targetRule.shouldNotNotify())
} }
private fun refreshDisplay() { private fun refreshDisplay() {
listView?.adapter?.notifyDataSetChanged() listView?.adapter?.notifyDataSetChanged()
} }