Don't auto focus and only scroll to preference when focused.

This commit is contained in:
David Langley 2021-08-27 13:16:19 +01:00
parent 9b3fe7449b
commit 9d663413a9
3 changed files with 18 additions and 2 deletions

View File

@ -30,6 +30,7 @@ import im.vector.app.R
class KeywordPreference : VectorPreference { class KeywordPreference : VectorPreference {
interface Listener { interface Listener {
fun onFocusDidChange(hasFocus: Boolean)
fun didAddKeyword(keyword: String) fun didAddKeyword(keyword: String)
fun didRemoveKeyword(keyword: String) fun didRemoveKeyword(keyword: String)
} }
@ -107,6 +108,9 @@ class KeywordPreference : VectorPreference {
} }
return@setOnEditorActionListener addKeyword() return@setOnEditorActionListener addKeyword()
} }
chipEditText.setOnFocusChangeListener { _, hasFocus ->
listener?.onFocusDidChange(hasFocus)
}
addKeywordButton.setOnClickListener { addKeywordButton.setOnClickListener {
addKeyword() addKeyword()

View File

@ -41,6 +41,8 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
override val preferenceXmlRes = R.xml.vector_settings_notification_mentions_and_keywords override val preferenceXmlRes = R.xml.vector_settings_notification_mentions_and_keywords
private var keywordsHasFocus = false
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
session.getKeywords().observe(viewLifecycleOwner, this::updateWithKeywords) session.getKeywords().observe(viewLifecycleOwner, this::updateWithKeywords)
@ -88,7 +90,13 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
false false
} }
val host = this
editKeywordPreference.listener = object: KeywordPreference.Listener { editKeywordPreference.listener = object: KeywordPreference.Listener {
override fun onFocusDidChange(hasFocus: Boolean) {
host.keywordsHasFocus = true
}
override fun didAddKeyword(keyword: String) { override fun didAddKeyword(keyword: String) {
addKeyword(keyword) addKeyword(keyword)
} }
@ -128,7 +136,9 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
fun updateWithKeywords(keywords: Set<String>) { fun updateWithKeywords(keywords: Set<String>) {
val editKeywordPreference = findPreference<KeywordPreference>("SETTINGS_KEYWORD_EDIT") ?: return val editKeywordPreference = findPreference<KeywordPreference>("SETTINGS_KEYWORD_EDIT") ?: return
editKeywordPreference.keywords = keywords editKeywordPreference.keywords = keywords
scrollToPreference(editKeywordPreference) if (keywordsHasFocus) {
scrollToPreference(editKeywordPreference)
}
} }
fun addKeyword(keyword: String) { fun addKeyword(keyword: String) {

View File

@ -5,7 +5,9 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:paddingTop="16dp"> android:paddingTop="16dp"
android:focusable="true"
android:focusableInTouchMode="true">
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/chipTextInputLayout" android:id="@+id/chipTextInputLayout"