From 73bf50b93c37f190725ff30990899e8f7346f95d Mon Sep 17 00:00:00 2001 From: David Langley Date: Tue, 27 Jul 2021 20:21:40 +0100 Subject: [PATCH] rename global -> default, address comments --- .../preference/VectorCheckboxPreference.kt | 2 +- ...sDefaultNotificationPreferenceFragment.kt} | 9 ++++--- ...dMentionsNotificationPreferenceFragment.kt | 3 +-- ...ingsOtherNotificationPreferenceFragment.kt | 3 +-- ...sPushRuleNotificationPreferenceFragment.kt | 24 ++++++++++--------- vector/src/main/res/values/strings.xml | 2 +- ... vector_settings_notification_default.xml} | 2 +- .../res/xml/vector_settings_notifications.xml | 6 ++--- 8 files changed, 25 insertions(+), 26 deletions(-) rename vector/src/main/java/im/vector/app/features/settings/notifications/{VectorSettingsGlobalNotificationPreferenceFragment.kt => VectorSettingsDefaultNotificationPreferenceFragment.kt} (89%) rename vector/src/main/res/xml/{vector_settings_notification_global.xml => vector_settings_notification_default.xml} (94%) diff --git a/vector/src/main/java/im/vector/app/core/preference/VectorCheckboxPreference.kt b/vector/src/main/java/im/vector/app/core/preference/VectorCheckboxPreference.kt index b66ea77bdd..13b65e11b4 100644 --- a/vector/src/main/java/im/vector/app/core/preference/VectorCheckboxPreference.kt +++ b/vector/src/main/java/im/vector/app/core/preference/VectorCheckboxPreference.kt @@ -22,7 +22,7 @@ import android.widget.TextView import androidx.preference.CheckBoxPreference import androidx.preference.PreferenceViewHolder -open class VectorCheckboxPreference : CheckBoxPreference { +class VectorCheckboxPreference : CheckBoxPreference { // Note: @JvmOverload does not work here... constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsGlobalNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsDefaultNotificationPreferenceFragment.kt similarity index 89% rename from vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsGlobalNotificationPreferenceFragment.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsDefaultNotificationPreferenceFragment.kt index 7fe4c4b87d..7d6b74b093 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsGlobalNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsDefaultNotificationPreferenceFragment.kt @@ -19,15 +19,14 @@ package im.vector.app.features.settings.notifications import im.vector.app.R import org.matrix.android.sdk.api.pushrules.RuleIds -class VectorSettingsGlobalNotificationPreferenceFragment +class VectorSettingsDefaultNotificationPreferenceFragment : VectorSettingsPushRuleNotificationPreferenceFragment() { - override var titleRes: Int = R.string.settings_notification_global + override var titleRes: Int = R.string.settings_notification_default - override val preferenceXmlRes = R.xml.vector_settings_notification_global + override val preferenceXmlRes = R.xml.vector_settings_notification_default - override val prefKeyToPushRuleId: Map - get() = mapOf( + override val prefKeyToPushRuleId = mapOf( "SETTINGS_PUSH_RULE_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY" to RuleIds.RULE_ID_ONE_TO_ONE_ROOM, "SETTINGS_PUSH_RULE_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY" to RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS, "SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_ONE_ONE_CHAT_PREFERENCE_KEY" to RuleIds.RULE_ID_ONE_TO_ONE_ENCRYPTED_ROOM, diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsKeywordAndMentionsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsKeywordAndMentionsNotificationPreferenceFragment.kt index 149b176e09..37acc1d898 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsKeywordAndMentionsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsKeywordAndMentionsNotificationPreferenceFragment.kt @@ -26,8 +26,7 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment override val preferenceXmlRes = R.xml.vector_settings_notification_mentions_and_keywords - override val prefKeyToPushRuleId: Map - get() = mapOf( + override val prefKeyToPushRuleId = mapOf( "SETTINGS_PUSH_RULE_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY" to RuleIds.RULE_ID_CONTAIN_DISPLAY_NAME, "SETTINGS_PUSH_RULE_CONTAINING_MY_USER_NAME_PREFERENCE_KEY" to RuleIds.RULE_ID_CONTAIN_USER_NAME, "SETTINGS_PUSH_RULE_MESSAGES_CONTAINING_AT_ROOM_PREFERENCE_KEY" to RuleIds.RULE_ID_ROOM_NOTIF diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsOtherNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsOtherNotificationPreferenceFragment.kt index db25d46e10..42203fb613 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsOtherNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsOtherNotificationPreferenceFragment.kt @@ -26,8 +26,7 @@ class VectorSettingsOtherNotificationPreferenceFragment override val preferenceXmlRes = R.xml.vector_settings_notification_other - override val prefKeyToPushRuleId: Map - get() = mapOf( + override val prefKeyToPushRuleId = mapOf( "SETTINGS_PUSH_RULE_INVITED_TO_ROOM_PREFERENCE_KEY" to RuleIds.RULE_ID_INVITE_ME, "SETTINGS_PUSH_RULE_CALL_INVITATIONS_PREFERENCE_KEY" to RuleIds.RULE_ID_CALL, "SETTINGS_PUSH_RULE_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY" to RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS, diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceFragment.kt index 4e3d8692b7..7f5ed0084d 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceFragment.kt @@ -31,16 +31,7 @@ import org.matrix.android.sdk.api.pushrules.rest.PushRuleAndKind abstract class VectorSettingsPushRuleNotificationPreferenceFragment : VectorSettingsBaseFragment() { - /** - * @return the bing rule status boolean - */ - fun ruleStatusIndexFor(ruleAndKind: PushRuleAndKind): Boolean { - val rule = ruleAndKind.pushRule - if (rule.ruleId == RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS) { - return rule.shouldNotify() || rule.shouldNotNotify() && !rule.enabled - } - return rule.enabled && !rule.shouldNotNotify() - } + abstract val prefKeyToPushRuleId: Map /** * Create a push rule with the updated checkbox status. @@ -90,6 +81,18 @@ abstract class VectorSettingsPushRuleNotificationPreferenceFragment } } + /** + * @return the bing rule status boolean + */ + private fun ruleStatusIndexFor(ruleAndKind: PushRuleAndKind): Boolean { + val rule = ruleAndKind.pushRule + if (rule.ruleId == RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS) { + return rule.shouldNotify() || rule.shouldNotNotify() && !rule.enabled + } + return rule.enabled && !rule.shouldNotNotify() + } + + override fun bindPref() { for (preferenceKey in prefKeyToPushRuleId.keys) { val preference = findPreference(preferenceKey)!! @@ -139,5 +142,4 @@ abstract class VectorSettingsPushRuleNotificationPreferenceFragment listView?.adapter?.notifyDataSetChanged() } - abstract val prefKeyToPushRuleId: Map } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 38a2c21f0c..3ead8b009e 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -1087,7 +1087,7 @@ Advanced Notification Settings Notification importance by event - Global Notifications + Default Notifications Mentions and Keywords Other diff --git a/vector/src/main/res/xml/vector_settings_notification_global.xml b/vector/src/main/res/xml/vector_settings_notification_default.xml similarity index 94% rename from vector/src/main/res/xml/vector_settings_notification_global.xml rename to vector/src/main/res/xml/vector_settings_notification_default.xml index 64d0c131b7..fb565d2230 100644 --- a/vector/src/main/res/xml/vector_settings_notification_global.xml +++ b/vector/src/main/res/xml/vector_settings_notification_default.xml @@ -1,7 +1,7 @@