From 1127a05a3e5592a0f819f8d5c1e1bdeb97734539 Mon Sep 17 00:00:00 2001 From: David Langley Date: Fri, 27 Aug 2021 11:40:15 +0100 Subject: [PATCH] Enable keywords by default if none exist. Add "Add" Button. --- .../app/core/preference/KeywordPreference.kt | 22 ++++++++++++++----- ...dMentionsNotificationPreferenceFragment.kt | 6 ++--- .../layout/vector_preference_chip_group.xml | 10 +++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) 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 c3377f63f9..37d9a598e7 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 @@ -19,6 +19,7 @@ package im.vector.app.core.preference import android.content.Context import android.util.AttributeSet import android.view.inputmethod.EditorInfo +import android.widget.Button import android.widget.EditText import androidx.core.view.children import androidx.preference.PreferenceViewHolder @@ -75,6 +76,7 @@ class KeywordPreference : VectorPreference { val chipEditText = holder.findViewById(R.id.chipEditText) as? EditText ?: return val chipGroup = holder.findViewById(R.id.chipGroup) as? ChipGroup ?: return + val addKeywordButton = holder.findViewById(R.id.addKeywordButton) as? Button ?: return chipEditText.text = null chipGroup.removeAllViews() @@ -87,20 +89,28 @@ class KeywordPreference : VectorPreference { chipGroup.isEnabled = keywordsEnabled chipGroup.children.forEach { it.isEnabled = keywordsEnabled } - chipEditText.setOnEditorActionListener { _, actionId, _ -> - if (actionId != EditorInfo.IME_ACTION_DONE) { - return@setOnEditorActionListener false - } + fun addKeyword(): Boolean { val keyword = chipEditText.text.toString().trim() if (keyword.isEmpty()) { - return@setOnEditorActionListener false + return false } _keywords.add(keyword) listener?.didAddKeyword(keyword) onPreferenceChangeListener?.onPreferenceChange(this, _keywords) notifyChanged() chipEditText.text = null - return@setOnEditorActionListener true + return true + } + + chipEditText.setOnEditorActionListener { _, actionId, _ -> + if (actionId != EditorInfo.IME_ACTION_DONE) { + return@setOnEditorActionListener false + } + return@setOnEditorActionListener addKeyword() + } + + addKeywordButton.setOnClickListener { + addKeyword() } } 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 71daaadc15..82663ae910 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 @@ -55,14 +55,14 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment yourKeywordsCategory.isIconSpaceReserved = false val keywordRules = session.getPushRules().content?.filter { !it.ruleId.startsWith(".") }.orEmpty() - val anyEnabledKeywords = keywordRules.any(PushRule::enabled) + val enableKeywords = keywordRules.isEmpty() || keywordRules.any(PushRule::enabled) val editKeywordPreference = findPreference("SETTINGS_KEYWORD_EDIT")!! - editKeywordPreference.isEnabled = anyEnabledKeywords + editKeywordPreference.isEnabled = enableKeywords val keywordPreference = findPreference("SETTINGS_PUSH_RULE_MESSAGES_CONTAINING_KEYWORDS_PREFERENCE_KEY")!! keywordPreference.isIconSpaceReserved = false - keywordPreference.isChecked = anyEnabledKeywords + keywordPreference.isChecked = enableKeywords val footerPreference = findPreference("SETTINGS_KEYWORDS_FOOTER")!! footerPreference.isIconSpaceReserved = false diff --git a/vector/src/main/res/layout/vector_preference_chip_group.xml b/vector/src/main/res/layout/vector_preference_chip_group.xml index 33cf6dcf37..5cc90d8002 100644 --- a/vector/src/main/res/layout/vector_preference_chip_group.xml +++ b/vector/src/main/res/layout/vector_preference_chip_group.xml @@ -31,6 +31,16 @@ +