This commit is contained in:
David Langley 2021-08-24 19:08:27 +01:00
parent 3481fc70c7
commit fb8c7f6be0
9 changed files with 20 additions and 13 deletions

View File

@ -16,7 +16,6 @@
package org.matrix.android.sdk.internal.session.pushers
import org.matrix.android.sdk.api.pushrules.RuleKind
import org.matrix.android.sdk.api.pushrules.rest.PushRule
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task

View File

@ -92,7 +92,7 @@ class KeywordPreference : VectorPreference {
return@setOnEditorActionListener false
}
val keyword = chipEditText.text.toString().trim()
if (keyword.isEmpty()){
if (keyword.isEmpty()) {
return@setOnEditorActionListener false
}
_keywords.add(keyword)
@ -102,7 +102,6 @@ class KeywordPreference : VectorPreference {
chipEditText.text = null
return@setOnEditorActionListener true
}
}
private fun addChipToGroup(keyword: String, chipGroup: ChipGroup) {
@ -114,8 +113,9 @@ class KeywordPreference : VectorPreference {
chipGroup.addView(chip)
chip.setOnCloseIconClickListener {
if (!keywordsEnabled)
if (!keywordsEnabled) {
return@setOnCloseIconClickListener
}
_keywords.remove(keyword)
listener?.didRemoveKeyword(keyword)
onPreferenceChangeListener?.onPreferenceChange(this, _keywords)

View File

@ -87,7 +87,7 @@ fun getStandardAction(ruleId: String, index: NotificationIndex): StandardActions
NotificationIndex.NOISY -> StandardActions.Highlight
}
RuleIds.RULE_ID_KEYWORDS ->
when(index) {
when (index) {
NotificationIndex.OFF -> StandardActions.Disabled
NotificationIndex.SILENT -> StandardActions.Notify
NotificationIndex.NOISY -> StandardActions.HighlightDefaultSound

View File

@ -16,9 +16,7 @@
package im.vector.app.features.settings.notifications
import androidx.preference.PreferenceCategory
import im.vector.app.R
import im.vector.app.core.preference.VectorCheckboxPreference
import im.vector.app.core.preference.VectorPreferenceCategory
import org.matrix.android.sdk.api.pushrules.RuleIds

View File

@ -23,6 +23,7 @@ import androidx.preference.Preference
import im.vector.app.R
import im.vector.app.core.preference.KeywordPreference
import im.vector.app.core.preference.VectorCheckboxPreference
import im.vector.app.core.preference.VectorPreference
import im.vector.app.core.preference.VectorPreferenceCategory
import im.vector.app.core.utils.toast
import kotlinx.coroutines.Dispatchers
@ -63,11 +64,14 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
keywordPreference.isIconSpaceReserved = false
keywordPreference.isChecked = anyEnabledKeywords
val footerPreference = findPreference<VectorPreference>("SETTINGS_KEYWORDS_FOOTER")!!
footerPreference.isIconSpaceReserved = false
keywordPreference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
val keywords = editKeywordPreference.keywords
val newChecked = newValue as Boolean
displayLoadingView()
updateKeywordPushRules(keywords, newChecked){ result ->
updateKeywordPushRules(keywords, newChecked) { result ->
hideLoadingView()
if (!isAdded) {
return@updateKeywordPushRules
@ -95,7 +99,6 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
scrollToPreference(editKeywordPreference)
}
}
}
fun updateKeywordPushRules(keywords: Set<String>, checked: Boolean, completion: (Result<Unit>) -> Unit) {
@ -116,7 +119,7 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
}
}
val firstError = results.firstNotNullOfOrNull(Result<Unit>::exceptionOrNull)
if (firstError == null){
if (firstError == null) {
completion(Result.success(Unit))
} else {
completion(Result.failure(firstError))
@ -124,7 +127,7 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
}
}
fun updateWithKeywords (keywords: Set<String>) {
fun updateWithKeywords(keywords: Set<String>) {
val editKeywordPreference = findPreference<KeywordPreference>("SETTINGS_KEYWORD_EDIT") ?: return
editKeywordPreference.keywords = keywords
}

View File

@ -43,7 +43,7 @@ abstract class VectorSettingsPushRuleNotificationPreferenceFragment
val initialIndex = ruleAndKind.pushRule.notificationIndex
preference.isChecked = initialIndex != NotificationIndex.OFF
preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
updatePushRule(ruleAndKind.pushRule.ruleId, ruleAndKind.kind,newValue as Boolean, preference)
updatePushRule(ruleAndKind.pushRule.ruleId, ruleAndKind.kind, newValue as Boolean, preference)
false
}
}

View File

@ -38,7 +38,8 @@
android:layout_marginStart="@dimen/layout_horizontal_margin"
android:layout_marginEnd="@dimen/layout_horizontal_margin"
app:chipSpacing="12dp"
app:lineSpacing="2dp"/>
android:paddingTop="16dp"
/>
</LinearLayout>

View File

@ -1227,6 +1227,7 @@
<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_mentions_and_keywords_encryption_notice">You wont get notifications for mentions &amp; keywords in encrypted rooms on mobile.</string>
<string name="settings_background_sync">Background synchronization</string>
<string name="settings_background_fdroid_sync_mode">Background Sync Mode</string>

View File

@ -28,5 +28,10 @@
android:key="SETTINGS_KEYWORD_EDIT"
/>
<im.vector.app.core.preference.VectorPreference
android:key="SETTINGS_KEYWORDS_FOOTER"
android:focusable="false"
android:summary="@string/settings_mentions_and_keywords_encryption_notice" />
</im.vector.app.core.preference.VectorPreferenceCategory>
</androidx.preference.PreferenceScreen>