rename global -> default, address comments

This commit is contained in:
David Langley 2021-07-27 20:21:40 +01:00
parent 7091de9942
commit 73bf50b93c
8 changed files with 25 additions and 26 deletions

View file

@ -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)

View file

@ -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<String, String>
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,

View file

@ -26,8 +26,7 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
override val preferenceXmlRes = R.xml.vector_settings_notification_mentions_and_keywords
override val prefKeyToPushRuleId: Map<String, String>
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

View file

@ -26,8 +26,7 @@ class VectorSettingsOtherNotificationPreferenceFragment
override val preferenceXmlRes = R.xml.vector_settings_notification_other
override val prefKeyToPushRuleId: Map<String, String>
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,

View file

@ -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<String, String>
/**
* 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<VectorCheckboxPreference>(preferenceKey)!!
@ -139,5 +142,4 @@ abstract class VectorSettingsPushRuleNotificationPreferenceFragment
listView?.adapter?.notifyDataSetChanged()
}
abstract val prefKeyToPushRuleId: Map<String, String>
}

View file

@ -1087,7 +1087,7 @@
<string name="settings_notification_advanced">Advanced Notification Settings</string>
<string name="settings_notification_by_event">Notification importance by event</string>
<string name="settings_notification_global">Global Notifications</string>
<string name="settings_notification_default">Default Notifications</string>
<string name="settings_notification_mentions_and_keywords">Mentions and Keywords</string>
<string name="settings_notification_other">Other</string>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<im.vector.app.core.preference.VectorPreferenceCategory
android:key="SETTINGS_OTHER"
android:key="SETTINGS_DEFAULT"
android:title="@string/settings_notification_notify_me_for">
<im.vector.app.core.preference.VectorCheckboxPreference

View file

@ -31,10 +31,10 @@
<im.vector.app.core.preference.VectorPreference
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
android:key="SETTINGS_NOTIFICATION_GLOBAL_PREFERENCE_KEY"
android:key="SETTINGS_NOTIFICATION_DEFAULT_PREFERENCE_KEY"
android:persistent="false"
android:title="@string/settings_notification_global"
app:fragment="im.vector.app.features.settings.notifications.VectorSettingsGlobalNotificationPreferenceFragment"
android:title="@string/settings_notification_default"
app:fragment="im.vector.app.features.settings.notifications.VectorSettingsDefaultNotificationPreferenceFragment"
app:isPreferenceVisible="@bool/useNotificationSettingsV2"/>
<im.vector.app.core.preference.VectorPreference