mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Merge pull request #3673 from vector-im/feature/dla/reorg_account_notification_settings
Reorganise Account Notification Settings
This commit is contained in:
commit
a538014935
19 changed files with 452 additions and 88 deletions
1
changelog.d/3646.feature
Normal file
1
changelog.d/3646.feature
Normal file
|
@ -0,0 +1 @@
|
|||
Reorganise Advanced Notifications in to Default Notifications, Keywords and Mentions, Other (This feature is hidden in the release ui until a future release date.)
|
|
@ -142,6 +142,10 @@ android {
|
|||
resValue "bool", "useLoginV1", "true"
|
||||
resValue "bool", "useLoginV2", "false"
|
||||
|
||||
// NotificationSettingsV2 is disabled. To be released in conjunction with iOS/Web
|
||||
resValue "bool", "useNotificationSettingsV1", "true"
|
||||
resValue "bool", "useNotificationSettingsV2", "false"
|
||||
|
||||
buildConfigField "im.vector.app.features.crypto.keysrequest.OutboundSessionKeySharingStrategy", "outboundSessionKeySharingStrategy", "im.vector.app.features.crypto.keysrequest.OutboundSessionKeySharingStrategy.WhenTyping"
|
||||
|
||||
buildConfigField "Long", "VOICE_MESSAGE_DURATION_LIMIT_MS", "120_000L"
|
||||
|
|
15
vector/src/main/java/im/vector/app/core/preference/PushRulePreference.kt
Executable file → Normal file
15
vector/src/main/java/im/vector/app/core/preference/PushRulePreference.kt
Executable file → Normal file
|
@ -22,19 +22,10 @@ import android.view.View
|
|||
import android.widget.RadioGroup
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import im.vector.app.R
|
||||
import im.vector.app.features.settings.notifications.NotificationIndex
|
||||
|
||||
class PushRulePreference : VectorPreference {
|
||||
|
||||
enum class NotificationIndex(val index: Int) {
|
||||
OFF(0),
|
||||
SILENT(1),
|
||||
NOISY(2);
|
||||
|
||||
companion object {
|
||||
fun fromInt(index: Int) = values().first { it.index == index }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the selected push rule index
|
||||
*/
|
||||
|
@ -66,7 +57,7 @@ class PushRulePreference : VectorPreference {
|
|||
*/
|
||||
private fun refreshSummary() {
|
||||
summary = context.getString(when (index) {
|
||||
NotificationIndex.OFF -> R.string.notification_off
|
||||
NotificationIndex.OFF -> R.string.notification_off
|
||||
NotificationIndex.SILENT -> R.string.notification_silent
|
||||
NotificationIndex.NOISY, null -> R.string.notification_noisy
|
||||
})
|
||||
|
@ -83,7 +74,7 @@ class PushRulePreference : VectorPreference {
|
|||
radioGroup?.setOnCheckedChangeListener(null)
|
||||
|
||||
when (index) {
|
||||
NotificationIndex.OFF -> {
|
||||
NotificationIndex.OFF -> {
|
||||
radioGroup?.check(R.id.bingPreferenceRadioBingRuleOff)
|
||||
}
|
||||
NotificationIndex.SILENT -> {
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.core.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
import androidx.preference.CheckBoxPreference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
|
||||
class VectorCheckboxPreference : CheckBoxPreference {
|
||||
// Note: @JvmOverload does not work here...
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
init {
|
||||
// Set to false to remove the space when there is no icon
|
||||
isIconSpaceReserved = true
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
// display the title in multi-line to avoid ellipsis.
|
||||
(holder.findViewById(android.R.id.title) as? TextView)?.isSingleLine = false
|
||||
super.onBindViewHolder(holder)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.settings.notifications
|
||||
|
||||
import org.matrix.android.sdk.api.pushrules.rest.PushRule
|
||||
import org.matrix.android.sdk.api.pushrules.toJson
|
||||
|
||||
enum class NotificationIndex {
|
||||
OFF,
|
||||
SILENT,
|
||||
NOISY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a push rule determine the NotificationIndex by comparing it to the static push rule definitions.
|
||||
* Used when determining the selected state of the PushRulePreference.
|
||||
*/
|
||||
val PushRule.notificationIndex: NotificationIndex? get() =
|
||||
NotificationIndex.values().firstOrNull {
|
||||
// Get the actions for the index
|
||||
val standardAction = getStandardAction(this.ruleId, it) ?: return@firstOrNull false
|
||||
val indexActions = standardAction.actions ?: listOf()
|
||||
// Check if the input rule matches a rule generated from the static rule definitions
|
||||
val targetRule = this.copy(enabled = standardAction != StandardActions.Disabled, actions = indexActions.toJson())
|
||||
ruleMatches(this, targetRule)
|
||||
}
|
||||
|
||||
/**
|
||||
* A check to determine if two push rules should be considered a match.
|
||||
*/
|
||||
private fun ruleMatches(rule: PushRule, targetRule: PushRule): Boolean {
|
||||
// Rules match if both are disabled, or if both are enabled and their highlight/sound/notify actions match up.
|
||||
return (!rule.enabled && !targetRule.enabled)
|
||||
|| (rule.enabled
|
||||
&& targetRule.enabled
|
||||
&& rule.getHighlight() == targetRule.getHighlight()
|
||||
&& rule.getNotificationSound() == targetRule.getNotificationSound()
|
||||
&& rule.shouldNotify() == targetRule.shouldNotify()
|
||||
&& rule.shouldNotNotify() == targetRule.shouldNotNotify())
|
||||
}
|
|
@ -16,76 +16,75 @@
|
|||
|
||||
package im.vector.app.features.settings.notifications
|
||||
|
||||
import im.vector.app.core.preference.PushRulePreference
|
||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||
|
||||
fun getStandardAction(ruleId: String, index: PushRulePreference.NotificationIndex): StandardActions? {
|
||||
fun getStandardAction(ruleId: String, index: NotificationIndex): StandardActions? {
|
||||
return when (ruleId) {
|
||||
RuleIds.RULE_ID_CONTAIN_DISPLAY_NAME ->
|
||||
when (index) {
|
||||
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
|
||||
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||
PushRulePreference.NotificationIndex.NOISY -> StandardActions.HighlightDefaultSound
|
||||
NotificationIndex.OFF -> StandardActions.Disabled
|
||||
NotificationIndex.SILENT -> StandardActions.Notify
|
||||
NotificationIndex.NOISY -> StandardActions.HighlightDefaultSound
|
||||
}
|
||||
RuleIds.RULE_ID_CONTAIN_USER_NAME ->
|
||||
when (index) {
|
||||
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
|
||||
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||
PushRulePreference.NotificationIndex.NOISY -> StandardActions.HighlightDefaultSound
|
||||
NotificationIndex.OFF -> StandardActions.Disabled
|
||||
NotificationIndex.SILENT -> StandardActions.Notify
|
||||
NotificationIndex.NOISY -> StandardActions.HighlightDefaultSound
|
||||
}
|
||||
RuleIds.RULE_ID_ROOM_NOTIF ->
|
||||
when (index) {
|
||||
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
|
||||
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||
PushRulePreference.NotificationIndex.NOISY -> StandardActions.Highlight
|
||||
NotificationIndex.OFF -> StandardActions.Disabled
|
||||
NotificationIndex.SILENT -> StandardActions.Notify
|
||||
NotificationIndex.NOISY -> StandardActions.Highlight
|
||||
}
|
||||
RuleIds.RULE_ID_ONE_TO_ONE_ROOM ->
|
||||
when (index) {
|
||||
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
|
||||
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||
NotificationIndex.OFF -> StandardActions.DontNotify
|
||||
NotificationIndex.SILENT -> StandardActions.Notify
|
||||
NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||
}
|
||||
RuleIds.RULE_ID_ONE_TO_ONE_ENCRYPTED_ROOM ->
|
||||
when (index) {
|
||||
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
|
||||
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||
NotificationIndex.OFF -> StandardActions.DontNotify
|
||||
NotificationIndex.SILENT -> StandardActions.Notify
|
||||
NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||
}
|
||||
RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS ->
|
||||
when (index) {
|
||||
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
|
||||
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||
NotificationIndex.OFF -> StandardActions.DontNotify
|
||||
NotificationIndex.SILENT -> StandardActions.Notify
|
||||
NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||
}
|
||||
RuleIds.RULE_ID_ENCRYPTED ->
|
||||
when (index) {
|
||||
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
|
||||
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||
NotificationIndex.OFF -> StandardActions.DontNotify
|
||||
NotificationIndex.SILENT -> StandardActions.Notify
|
||||
NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||
}
|
||||
RuleIds.RULE_ID_INVITE_ME ->
|
||||
when (index) {
|
||||
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
|
||||
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||
NotificationIndex.OFF -> StandardActions.Disabled
|
||||
NotificationIndex.SILENT -> StandardActions.Notify
|
||||
NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||
}
|
||||
RuleIds.RULE_ID_CALL ->
|
||||
when (index) {
|
||||
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
|
||||
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyRingSound
|
||||
NotificationIndex.OFF -> StandardActions.Disabled
|
||||
NotificationIndex.SILENT -> StandardActions.Notify
|
||||
NotificationIndex.NOISY -> StandardActions.NotifyRingSound
|
||||
}
|
||||
RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS ->
|
||||
when (index) {
|
||||
PushRulePreference.NotificationIndex.OFF -> StandardActions.DontNotify
|
||||
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Disabled
|
||||
PushRulePreference.NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||
NotificationIndex.OFF -> StandardActions.DontNotify
|
||||
NotificationIndex.SILENT -> StandardActions.Disabled
|
||||
NotificationIndex.NOISY -> StandardActions.NotifyDefaultSound
|
||||
}
|
||||
RuleIds.RULE_ID_TOMBSTONE ->
|
||||
when (index) {
|
||||
PushRulePreference.NotificationIndex.OFF -> StandardActions.Disabled
|
||||
PushRulePreference.NotificationIndex.SILENT -> StandardActions.Notify
|
||||
PushRulePreference.NotificationIndex.NOISY -> StandardActions.Highlight
|
||||
NotificationIndex.OFF -> StandardActions.Disabled
|
||||
NotificationIndex.SILENT -> StandardActions.Notify
|
||||
NotificationIndex.NOISY -> StandardActions.Highlight
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
|
|
|
@ -18,16 +18,13 @@ package im.vector.app.features.settings.notifications
|
|||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.Preference
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.preference.PushRulePreference.NotificationIndex
|
||||
import im.vector.app.core.preference.PushRulePreference
|
||||
import im.vector.app.core.preference.VectorPreference
|
||||
import im.vector.app.core.utils.toast
|
||||
import im.vector.app.features.settings.VectorSettingsBaseFragment
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||
import org.matrix.android.sdk.api.pushrules.rest.PushRule
|
||||
import org.matrix.android.sdk.api.pushrules.rest.PushRuleAndKind
|
||||
import org.matrix.android.sdk.api.pushrules.toJson
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
|
||||
|
@ -41,7 +38,6 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
|
|||
for (preferenceKey in prefKeyToPushRuleId.keys) {
|
||||
val preference = findPreference<VectorPreference>(preferenceKey)
|
||||
if (preference is PushRulePreference) {
|
||||
// preference.isEnabled = null != rules && isConnected && pushManager.areDeviceNotificationsAllowed()
|
||||
val ruleAndKind: PushRuleAndKind? = session.getPushRules().findDefaultRule(prefKeyToPushRuleId[preferenceKey])
|
||||
|
||||
if (ruleAndKind == null) {
|
||||
|
@ -49,7 +45,7 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
|
|||
preference.isVisible = false
|
||||
} else {
|
||||
preference.isVisible = true
|
||||
val initialIndex = getNotificationIndexForRule(ruleAndKind.pushRule)
|
||||
val initialIndex = ruleAndKind.pushRule.notificationIndex
|
||||
preference.setIndex(initialIndex)
|
||||
preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
val newIndex = newValue as NotificationIndex
|
||||
|
@ -87,28 +83,6 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
|
|||
}
|
||||
}
|
||||
|
||||
private fun getNotificationIndexForRule(rule: PushRule): NotificationIndex? {
|
||||
return NotificationIndex.values().firstOrNull {
|
||||
// Get the actions for the index
|
||||
val standardAction = getStandardAction(rule.ruleId, it) ?: return@firstOrNull false
|
||||
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 != StandardActions.Disabled, actions = indexActions.toJson())
|
||||
ruleMatches(rule, targetRule)
|
||||
}
|
||||
}
|
||||
|
||||
private fun ruleMatches(rule: PushRule, targetRule: PushRule): Boolean {
|
||||
// Rules match if both are disabled, or if both are enabled and their highlight/sound/notify actions match up.
|
||||
return (!rule.enabled && !targetRule.enabled)
|
||||
|| (rule.enabled
|
||||
&& targetRule.enabled
|
||||
&& rule.getHighlight() == targetRule.getHighlight()
|
||||
&& rule.getNotificationSound() == targetRule.getNotificationSound()
|
||||
&& rule.shouldNotify() == targetRule.shouldNotify()
|
||||
&& rule.shouldNotNotify() == targetRule.shouldNotNotify())
|
||||
}
|
||||
|
||||
private fun refreshDisplay() {
|
||||
listView?.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.settings.notifications
|
||||
|
||||
import im.vector.app.R
|
||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||
|
||||
class VectorSettingsDefaultNotificationPreferenceFragment
|
||||
: VectorSettingsPushRuleNotificationPreferenceFragment() {
|
||||
|
||||
override var titleRes: Int = R.string.settings_notification_default
|
||||
|
||||
override val preferenceXmlRes = R.xml.vector_settings_notification_default
|
||||
|
||||
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,
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_GROUP_CHAT_PREFERENCE_KEY" to RuleIds.RULE_ID_ENCRYPTED
|
||||
)
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.settings.notifications
|
||||
|
||||
import im.vector.app.R
|
||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||
|
||||
class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
|
||||
: VectorSettingsPushRuleNotificationPreferenceFragment() {
|
||||
|
||||
override var titleRes: Int = R.string.settings_notification_mentions_and_keywords
|
||||
|
||||
override val preferenceXmlRes = R.xml.vector_settings_notification_mentions_and_keywords
|
||||
|
||||
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
|
||||
)
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.settings.notifications
|
||||
|
||||
import im.vector.app.R
|
||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||
|
||||
class VectorSettingsOtherNotificationPreferenceFragment
|
||||
: VectorSettingsPushRuleNotificationPreferenceFragment() {
|
||||
|
||||
override var titleRes: Int = R.string.settings_notification_other
|
||||
|
||||
override val preferenceXmlRes = R.xml.vector_settings_notification_other
|
||||
|
||||
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,
|
||||
"SETTINGS_PUSH_RULE_ROOMS_UPGRADED_KEY" to RuleIds.RULE_ID_TOMBSTONE
|
||||
)
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.settings.notifications
|
||||
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.Preference
|
||||
import im.vector.app.core.preference.VectorCheckboxPreference
|
||||
import im.vector.app.core.utils.toast
|
||||
import im.vector.app.features.settings.VectorSettingsBaseFragment
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.pushrules.rest.PushRuleAndKind
|
||||
|
||||
abstract class VectorSettingsPushRuleNotificationPreferenceFragment
|
||||
: VectorSettingsBaseFragment() {
|
||||
|
||||
abstract val prefKeyToPushRuleId: Map<String, String>
|
||||
|
||||
override fun bindPref() {
|
||||
for (preferenceKey in prefKeyToPushRuleId.keys) {
|
||||
val preference = findPreference<VectorCheckboxPreference>(preferenceKey)!!
|
||||
val ruleAndKind: PushRuleAndKind? = session.getPushRules().findDefaultRule(prefKeyToPushRuleId[preferenceKey])
|
||||
if (ruleAndKind == null) {
|
||||
// The rule is not defined, hide the preference
|
||||
preference.isVisible = false
|
||||
} else {
|
||||
preference.isVisible = true
|
||||
val initialIndex = ruleAndKind.pushRule.notificationIndex
|
||||
preference.isChecked = initialIndex != NotificationIndex.OFF
|
||||
preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
val newIndex = if (newValue as Boolean) NotificationIndex.NOISY else NotificationIndex.OFF
|
||||
val standardAction = getStandardAction(ruleAndKind.pushRule.ruleId, newIndex) ?: return@OnPreferenceChangeListener false
|
||||
val enabled = standardAction != StandardActions.Disabled
|
||||
val newActions = standardAction.actions
|
||||
displayLoadingView()
|
||||
|
||||
lifecycleScope.launch {
|
||||
val result = runCatching {
|
||||
session.updatePushRuleActions(ruleAndKind.kind,
|
||||
ruleAndKind.pushRule.ruleId,
|
||||
enabled,
|
||||
newActions)
|
||||
}
|
||||
if (!isAdded) {
|
||||
return@launch
|
||||
}
|
||||
hideLoadingView()
|
||||
result.onSuccess {
|
||||
preference.isChecked = newValue
|
||||
}
|
||||
result.onFailure { failure ->
|
||||
// Restore the previous value
|
||||
refreshDisplay()
|
||||
activity?.toast(errorFormatter.toHumanReadable(failure))
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshDisplay() {
|
||||
listView?.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
|
@ -35,11 +35,6 @@ class TestPushRulesSettings @Inject constructor(private val activeSessionHolder:
|
|||
RuleIds.RULE_ID_ONE_TO_ONE_ROOM,
|
||||
RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS)
|
||||
|
||||
val ruleSettingsName = arrayOf(R.string.settings_containing_my_display_name,
|
||||
R.string.settings_containing_my_user_name,
|
||||
R.string.settings_messages_in_one_to_one,
|
||||
R.string.settings_messages_in_group_chat)
|
||||
|
||||
override fun perform(activityResultLauncher: ActivityResultLauncher<Intent>) {
|
||||
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
||||
val pushRules = session.getPushRules().getAllRules()
|
||||
|
|
|
@ -76,4 +76,3 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
|
|
@ -1088,6 +1088,12 @@
|
|||
<string name="settings_notification_advanced">Advanced Notification Settings</string>
|
||||
<string name="settings_notification_by_event">Notification importance by event</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>
|
||||
|
||||
<string name="settings_notification_notify_me_for">Notify me for</string>
|
||||
|
||||
<string name="settings_notification_privacy">Notification privacy</string>
|
||||
<string name="settings_notification_troubleshoot">Troubleshoot Notifications</string>
|
||||
<string name="settings_troubleshoot_diagnostic">Troubleshooting diagnostics</string>
|
||||
|
@ -1196,15 +1202,28 @@
|
|||
<string name="settings_silent_notifications_preferences">Configure Silent Notifications</string>
|
||||
<string name="settings_system_preferences_summary">Choose LED color, vibration, sound…</string>
|
||||
|
||||
|
||||
<string name="settings_messages_in_e2e_one_to_one">Encrypted messages in one-to-one chats</string>
|
||||
<string name="settings_messages_in_e2e_group_chat">Encrypted messages in group chats</string>
|
||||
<string name="settings_when_rooms_are_upgraded">When rooms are upgraded</string>
|
||||
<string name="settings_containing_my_display_name">Msgs containing my display name</string>
|
||||
<string name="settings_containing_my_user_name">Msgs containing my user name</string>
|
||||
<string name="settings_messages_in_one_to_one">Msgs in one-to-one chats</string>
|
||||
<string name="settings_messages_in_group_chat">Msgs in group chats</string>
|
||||
<string name="settings_invited_to_room">When I’m invited to a room</string>
|
||||
<string name="settings_call_invitations">Call invitations</string>
|
||||
<string name="settings_messages_sent_by_bot">Messages sent by bot</string>
|
||||
|
||||
<string name="settings_messages_containing_display_name">Messages containing my display name</string>
|
||||
<string name="settings_messages_containing_username">Messages containing my username</string>
|
||||
<string name="settings_messages_direct_messages">Direct messages</string>
|
||||
<string name="settings_encrypted_direct_messages">Encrypted direct messages</string>
|
||||
<string name="settings_group_messages">Group messages</string>
|
||||
<string name="settings_encrypted_group_messages">Encrypted group messages</string>
|
||||
<string name="settings_messages_at_room">Messages containing @room</string>
|
||||
<string name="settings_room_invitations">Room invitations</string>
|
||||
<string name="settings_call_invitations">Call invitations</string>
|
||||
<string name="settings_messages_by_bot">Messages by bot</string>
|
||||
<string name="settings_room_upgrades">Room upgrades</string>
|
||||
|
||||
<string name="settings_background_sync">Background synchronization</string>
|
||||
<string name="settings_background_fdroid_sync_mode">Background Sync Mode</string>
|
||||
<string name="settings_background_fdroid_sync_mode_battery">Optimized for battery</string>
|
||||
|
@ -2966,10 +2985,6 @@
|
|||
<string name="error_failed_to_import_keys">Failed to import keys</string>
|
||||
|
||||
<string name="settings_notification_configuration">Notifications configuration</string>
|
||||
<string name="settings_messages_at_room">Messages containing @room</string>
|
||||
<string name="settings_messages_in_e2e_one_to_one">Encrypted messages in one-to-one chats</string>
|
||||
<string name="settings_messages_in_e2e_group_chat">Encrypted messages in group chats</string>
|
||||
<string name="settings_when_rooms_are_upgraded">When rooms are upgraded</string>
|
||||
<string name="settings_troubleshoot_title">Troubleshoot</string>
|
||||
<string name="settings_notification_advanced_summary">Set notification importance by event</string>
|
||||
|
||||
|
|
|
@ -64,4 +64,4 @@
|
|||
|
||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
||||
</androidx.preference.PreferenceScreen>
|
|
@ -0,0 +1,28 @@
|
|||
<?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_DEFAULT"
|
||||
android:title="@string/settings_notification_notify_me_for">
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_direct_messages" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_ONE_ONE_CHAT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_encrypted_direct_messages" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_group_messages" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_GROUP_CHAT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_encrypted_group_messages" />
|
||||
|
||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||
</androidx.preference.PreferenceScreen>
|
|
@ -0,0 +1,23 @@
|
|||
<?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_KEYWORDS_AND_MENTIONS"
|
||||
android:title="@string/settings_notification_notify_me_for">
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_containing_display_name" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_CONTAINING_MY_USER_NAME_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_containing_username" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_CONTAINING_AT_ROOM_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_at_room" />
|
||||
|
||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||
</androidx.preference.PreferenceScreen>
|
|
@ -0,0 +1,27 @@
|
|||
<?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:title="@string/settings_notification_notify_me_for">
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_INVITED_TO_ROOM_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_room_invitations" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_CALL_INVITATIONS_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_call_invitations" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_by_bot" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_ROOMS_UPGRADED_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_room_upgrades" />
|
||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||
</androidx.preference.PreferenceScreen>
|
|
@ -26,7 +26,32 @@
|
|||
android:persistent="false"
|
||||
android:summary="@string/settings_notification_advanced_summary"
|
||||
android:title="@string/settings_notification_advanced"
|
||||
app:fragment="im.vector.app.features.settings.notifications.VectorSettingsAdvancedNotificationPreferenceFragment" />
|
||||
app:fragment="im.vector.app.features.settings.notifications.VectorSettingsAdvancedNotificationPreferenceFragment"
|
||||
app:isPreferenceVisible="@bool/useNotificationSettingsV1" />
|
||||
|
||||
<im.vector.app.core.preference.VectorPreference
|
||||
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
||||
android:key="SETTINGS_NOTIFICATION_DEFAULT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
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
|
||||
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
||||
android:key="SETTINGS_NOTIFICATION_KEYWORD_AND_MENTIONS_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_notification_mentions_and_keywords"
|
||||
app:fragment="im.vector.app.features.settings.notifications.VectorSettingsKeywordAndMentionsNotificationPreferenceFragment"
|
||||
app:isPreferenceVisible="@bool/useNotificationSettingsV2"/>
|
||||
|
||||
<im.vector.app.core.preference.VectorPreference
|
||||
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
||||
android:key="SETTINGS_NOTIFICATION_OTHER_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_notification_other"
|
||||
app:fragment="im.vector.app.features.settings.notifications.VectorSettingsOtherNotificationPreferenceFragment"
|
||||
app:isPreferenceVisible="@bool/useNotificationSettingsV2"/>
|
||||
|
||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||
|
||||
|
|
Loading…
Reference in a new issue