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,7 +136,9 @@ class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment
|
|||
fun updateWithKeywords(keywords: Set<String>) {
|
||||
val editKeywordPreference = findPreference<KeywordPreference>("SETTINGS_KEYWORD_EDIT") ?: return
|
||||
editKeywordPreference.keywords = keywords
|
||||
scrollToPreference(editKeywordPreference)
|
||||
if (keywordsHasFocus) {
|
||||
scrollToPreference(editKeywordPreference)
|
||||
}
|
||||
}
|
||||
|
||||
fun addKeyword(keyword: String) {
|
||||
|
|
|
@ -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