mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-23 01:45:52 +03:00
Enable keywords by default if none exist. Add "Add" Button.
This commit is contained in:
parent
ce9acd440e
commit
1127a05a3e
3 changed files with 29 additions and 9 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<KeywordPreference>("SETTINGS_KEYWORD_EDIT")!!
|
||||
editKeywordPreference.isEnabled = anyEnabledKeywords
|
||||
editKeywordPreference.isEnabled = enableKeywords
|
||||
|
||||
val keywordPreference = findPreference<VectorCheckboxPreference>("SETTINGS_PUSH_RULE_MESSAGES_CONTAINING_KEYWORDS_PREFERENCE_KEY")!!
|
||||
keywordPreference.isIconSpaceReserved = false
|
||||
keywordPreference.isChecked = anyEnabledKeywords
|
||||
keywordPreference.isChecked = enableKeywords
|
||||
|
||||
val footerPreference = findPreference<VectorPreference>("SETTINGS_KEYWORDS_FOOTER")!!
|
||||
footerPreference.isIconSpaceReserved = false
|
||||
|
|
|
@ -31,6 +31,16 @@
|
|||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/addKeywordButton"
|
||||
style="@style/Widget.Vector.Button.Positive"
|
||||
android:layout_gravity="end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/layout_horizontal_margin"
|
||||
android:textAllCaps="false"
|
||||
android:text="@string/action_add" />
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/chipGroup"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in a new issue