From 3481fc70c7b8e1d4fa3744f141edcd1a250d7472 Mon Sep 17 00:00:00 2001 From: David Langley Date: Tue, 24 Aug 2021 16:49:18 +0100 Subject: [PATCH] Cleanup and fix resValue --- .../session/notification/DefaultPushRuleService.kt | 1 + vector/build.gradle | 4 ++-- .../vector/app/core/preference/KeywordPreference.kt | 2 -- ...wordAndMentionsNotificationPreferenceFragment.kt | 13 +++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/notification/DefaultPushRuleService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/notification/DefaultPushRuleService.kt index 7a1440a0aa..65974151c8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/notification/DefaultPushRuleService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/notification/DefaultPushRuleService.kt @@ -216,6 +216,7 @@ internal class DefaultPushRuleService @Inject constructor( } override fun getKeywords(): LiveData> { + // Keywords are all content rules that don't start with '.' val liveData = monarchy.findAllMappedWithChanges( { realm -> PushRulesEntity.where(realm, RuleScope.GLOBAL, RuleSetKey.CONTENT) diff --git a/vector/build.gradle b/vector/build.gradle index 85d3eb849f..6494436c13 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -143,8 +143,8 @@ android { resValue "bool", "useLoginV2", "false" // NotificationSettingsV2 is disabled. To be released in conjunction with iOS/Web - resValue "bool", "useNotificationSettingsV1", "false" - resValue "bool", "useNotificationSettingsV2", "true" + 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" diff --git a/vector/src/main/java/im/vector/app/core/preference/KeywordPreference.kt b/vector/src/main/java/im/vector/app/core/preference/KeywordPreference.kt index a1a4fb5738..10b02cc088 100644 --- a/vector/src/main/java/im/vector/app/core/preference/KeywordPreference.kt +++ b/vector/src/main/java/im/vector/app/core/preference/KeywordPreference.kt @@ -25,7 +25,6 @@ import androidx.preference.PreferenceViewHolder import com.google.android.material.chip.Chip import com.google.android.material.chip.ChipGroup import im.vector.app.R -import java.util.SortedSet class KeywordPreference : VectorPreference { @@ -112,7 +111,6 @@ class KeywordPreference : VectorPreference { chip.isClickable = true chip.isCheckable = false chip.isCloseIconVisible = true - chip.clipBounds chipGroup.addView(chip) chip.setOnCloseIconClickListener { 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 580c546293..e444878168 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 @@ -19,7 +19,6 @@ package im.vector.app.features.settings.notifications import android.os.Bundle import android.view.View import androidx.lifecycle.lifecycleScope -import androidx.preference.CheckBoxPreference import androidx.preference.Preference import im.vector.app.R import im.vector.app.core.preference.KeywordPreference @@ -50,20 +49,24 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment super.bindPref() val mentionCategory = findPreference("SETTINGS_KEYWORDS_AND_MENTIONS")!! mentionCategory.isIconSpaceReserved = false + val yourKeywordsCategory = findPreference("SETTINGS_YOUR_KEYWORDS")!! yourKeywordsCategory.isIconSpaceReserved = false + val keywordRules = session.getPushRules().content?.filter { !it.ruleId.startsWith(".") }.orEmpty() + val anyEnabledKeywords = keywordRules.any(PushRule::enabled) + val editKeywordPreference = findPreference("SETTINGS_KEYWORD_EDIT")!! + editKeywordPreference.isEnabled = anyEnabledKeywords + val keywordPreference = findPreference("SETTINGS_PUSH_RULE_MESSAGES_CONTAINING_KEYWORDS_PREFERENCE_KEY")!! keywordPreference.isIconSpaceReserved = false - val anyEnabledKeywords = keywordRules.any(PushRule::enabled) keywordPreference.isChecked = anyEnabledKeywords - editKeywordPreference.isEnabled = anyEnabledKeywords + keywordPreference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> val keywords = editKeywordPreference.keywords val newChecked = newValue as Boolean displayLoadingView() - session.getKeywords() updateKeywordPushRules(keywords, newChecked){ result -> hideLoadingView() if (!isAdded) { @@ -81,8 +84,6 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment false } - - editKeywordPreference.keywords = session.getKeywords().value.orEmpty() editKeywordPreference.listener = object: KeywordPreference.Listener { override fun didAddKeyword(keyword: String) { addKeyword(keyword)