diff --git a/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt b/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt index 40019c5d64..d3ee765780 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt @@ -16,9 +16,11 @@ package im.vector.app.core.extensions +import android.os.Build import android.text.Editable import android.view.View import android.view.inputmethod.EditorInfo +import androidx.autofill.HintConstants import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope import com.google.android.material.textfield.TextInputLayout @@ -79,3 +81,12 @@ fun TextInputLayout.setOnFocusLostListener(action: () -> Unit) { } } } + +fun TextInputLayout.autofillPhoneNumber() = setAutofillHint(HintConstants.AUTOFILL_HINT_PHONE_NUMBER) +fun TextInputLayout.autofillEmail() = setAutofillHint(HintConstants.AUTOFILL_HINT_EMAIL_ADDRESS) + +private fun TextInputLayout.setAutofillHint(hintType: String) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + setAutofillHints(hintType) + } +} diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthEmailEntryFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthEmailEntryFragment.kt index e3bf2becd8..7d8dab73ec 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthEmailEntryFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthEmailEntryFragment.kt @@ -16,13 +16,12 @@ package im.vector.app.features.onboarding.ftueauth -import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.autofill.HintConstants import im.vector.app.core.extensions.associateContentStateWith +import im.vector.app.core.extensions.autofillEmail import im.vector.app.core.extensions.clearErrorOnChange import im.vector.app.core.extensions.content import im.vector.app.core.extensions.isEmail @@ -49,13 +48,7 @@ class FtueAuthEmailEntryFragment @Inject constructor() : AbstractFtueAuthFragmen views.emailEntryInput.setOnImeDoneListener { updateEmail() } views.emailEntryInput.clearErrorOnChange(viewLifecycleOwner) views.emailEntrySubmit.debouncedClicks { updateEmail() } - setupAutoFill() - } - - private fun setupAutoFill() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - views.emailEntryInput.setAutofillHints(HintConstants.AUTOFILL_HINT_PHONE_NUMBER) - } + views.emailEntryInput.autofillEmail() } private fun updateEmail() { diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthPhoneEntryFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthPhoneEntryFragment.kt index f978921348..5f9a962aa7 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthPhoneEntryFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthPhoneEntryFragment.kt @@ -22,6 +22,7 @@ import android.view.View import android.view.ViewGroup import androidx.lifecycle.lifecycleScope import im.vector.app.core.extensions.associateContentStateWith +import im.vector.app.core.extensions.autofillPhoneNumber import im.vector.app.core.extensions.content import im.vector.app.core.extensions.editText import im.vector.app.core.extensions.isEmail @@ -57,6 +58,8 @@ class FtueAuthPhoneEntryFragment @Inject constructor() : AbstractFtueAuthFragmen views.emailEntrySubmit.isEnabled = it.isEmail() } .launchIn(viewLifecycleOwner.lifecycleScope) + + views.emailEntryInput.autofillPhoneNumber() } private fun updateEmail() {