From 9d663413a9ba306c0517fed5845baca68ceb9abc Mon Sep 17 00:00:00 2001 From: David Langley Date: Fri, 27 Aug 2021 13:16:19 +0100 Subject: [PATCH] Don't auto focus and only scroll to preference when focused. --- .../vector/app/core/preference/KeywordPreference.kt | 4 ++++ ...ywordAndMentionsNotificationPreferenceFragment.kt | 12 +++++++++++- .../main/res/layout/vector_preference_chip_group.xml | 4 +++- 3 files changed, 18 insertions(+), 2 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 c70b403550..a3cab1fb9e 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 @@ -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() 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 ca3d5c8348..1f697d7f5f 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 @@ -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,7 +136,9 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment fun updateWithKeywords(keywords: Set) { val editKeywordPreference = findPreference("SETTINGS_KEYWORD_EDIT") ?: return editKeywordPreference.keywords = keywords - scrollToPreference(editKeywordPreference) + if (keywordsHasFocus) { + scrollToPreference(editKeywordPreference) + } } fun addKeyword(keyword: String) { 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 5cc90d8002..42891f7277 100644 --- a/vector/src/main/res/layout/vector_preference_chip_group.xml +++ b/vector/src/main/res/layout/vector_preference_chip_group.xml @@ -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">