mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Don't auto focus and only scroll to preference when focused.
This commit is contained in:
parent
9b3fe7449b
commit
9d663413a9
@ -30,6 +30,7 @@ import im.vector.app.R
|
||||
class KeywordPreference : VectorPreference {
|
||||
|
||||
interface Listener {
|
||||
fun onFocusDidChange(hasFocus: Boolean)
|
||||
fun didAddKeyword(keyword: String)
|
||||
fun didRemoveKeyword(keyword: String)
|
||||
}
|
||||
@ -107,6 +108,9 @@ class KeywordPreference : VectorPreference {
|
||||
}
|
||||
return@setOnEditorActionListener addKeyword()
|
||||
}
|
||||
chipEditText.setOnFocusChangeListener { _, hasFocus ->
|
||||
listener?.onFocusDidChange(hasFocus)
|
||||
}
|
||||
|
||||
addKeywordButton.setOnClickListener {
|
||||
addKeyword()
|
||||
|
@ -41,6 +41,8 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
|
||||
|
||||
override val preferenceXmlRes = R.xml.vector_settings_notification_mentions_and_keywords
|
||||
|
||||
private var keywordsHasFocus = false
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
session.getKeywords().observe(viewLifecycleOwner, this::updateWithKeywords)
|
||||
@ -88,7 +90,13 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
|
||||
false
|
||||
}
|
||||
|
||||
val host = this
|
||||
editKeywordPreference.listener = object: KeywordPreference.Listener {
|
||||
|
||||
override fun onFocusDidChange(hasFocus: Boolean) {
|
||||
host.keywordsHasFocus = true
|
||||
}
|
||||
|
||||
override fun didAddKeyword(keyword: String) {
|
||||
addKeyword(keyword)
|
||||
}
|
||||
@ -128,8 +136,10 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
|
||||
fun updateWithKeywords(keywords: Set<String>) {
|
||||
val editKeywordPreference = findPreference<KeywordPreference>("SETTINGS_KEYWORD_EDIT") ?: return
|
||||
editKeywordPreference.keywords = keywords
|
||||
if (keywordsHasFocus) {
|
||||
scrollToPreference(editKeywordPreference)
|
||||
}
|
||||
}
|
||||
|
||||
fun addKeyword(keyword: String) {
|
||||
val standardAction = getStandardAction(RuleIds.RULE_ID_KEYWORDS, NotificationIndex.NOISY) ?: return
|
||||
|
@ -5,7 +5,9 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="16dp">
|
||||
android:paddingTop="16dp"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/chipTextInputLayout"
|
||||
|
Loading…
Reference in New Issue
Block a user