diff --git a/vector/build.gradle b/vector/build.gradle index ed489f84ac..ee897cfff4 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -225,6 +225,7 @@ dependencies { def glide_version = '4.10.0' def moshi_version = '1.8.0' def daggerVersion = '2.24' + def autofill_version = "1.0.0-rc01" implementation project(":matrix-sdk-android") implementation project(":matrix-sdk-android-rx") @@ -290,6 +291,7 @@ dependencies { implementation "io.noties.markwon:html:$markwon_version" implementation 'me.saket:better-link-movement-method:2.2.0' implementation 'com.google.android:flexbox:1.1.1' + implementation "androidx.autofill:autofill:$autofill_version" // Passphrase strength helper implementation 'com.nulab-inc:zxcvbn:1.2.7' diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt index 1a258b6dbe..425edcc255 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt @@ -16,8 +16,10 @@ package im.vector.riotx.features.login +import android.os.Build import android.os.Bundle import android.view.View +import androidx.autofill.HintConstants import androidx.core.view.isVisible import butterknife.OnClick import com.airbnb.mvrx.Fail @@ -45,7 +47,6 @@ class LoginFragment @Inject constructor( private val errorFormatter: ErrorFormatter ) : AbstractLoginFragment() { - // TODO Move to viewState? private var passwordShown = false override fun getLayoutResId() = R.layout.fragment_login @@ -54,11 +55,28 @@ class LoginFragment @Inject constructor( super.onViewCreated(view, savedInstanceState) setupUi() + setupAutoFill() setupSubmitButton() setupPasswordReveal() setupButtons() } + private fun setupAutoFill() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + when (loginViewModel.signMode) { + SignMode.Unknown -> error("developer error") + SignMode.SignUp -> { + loginField.setAutofillHints(HintConstants.AUTOFILL_HINT_NEW_USERNAME) + passwordField.setAutofillHints(HintConstants.AUTOFILL_HINT_NEW_PASSWORD) + } + SignMode.SignIn -> { + loginField.setAutofillHints(HintConstants.AUTOFILL_HINT_USERNAME) + passwordField.setAutofillHints(HintConstants.AUTOFILL_HINT_PASSWORD) + } + } + } + } + @OnClick(R.id.loginSubmit) fun submit() { val login = loginField.text?.trim().toString() diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginGenericTextInputFormFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginGenericTextInputFormFragment.kt index 3b93e4f971..5b89cc8169 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginGenericTextInputFormFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginGenericTextInputFormFragment.kt @@ -16,10 +16,12 @@ package im.vector.riotx.features.login +import android.os.Build import android.os.Bundle import android.os.Parcelable import android.text.InputType import android.view.View +import androidx.autofill.HintConstants import androidx.core.view.isVisible import butterknife.OnClick import com.airbnb.mvrx.args @@ -62,6 +64,18 @@ class LoginGenericTextInputFormFragment @Inject constructor(private val errorFor setupUi() setupSubmitButton() setupTil() + setupAutoFill() + } + + private fun setupAutoFill() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + when (params.mode) { + TextInputFormFragmentMode.SetEmail -> loginGenericTextInputFormTextInput.setAutofillHints(HintConstants.AUTOFILL_HINT_EMAIL_ADDRESS) + // TODO Phone number without country code? + TextInputFormFragmentMode.SetMsisdn -> loginGenericTextInputFormTextInput.setAutofillHints(HintConstants.AUTOFILL_HINT_PHONE_NUMBER) + TextInputFormFragmentMode.ConfirmMsisdn -> loginGenericTextInputFormTextInput.setAutofillHints(HintConstants.AUTOFILL_HINT_SMS_OTP) + } + } } private fun setupTil() {