Login screens: setup autofill

This commit is contained in:
Benoit Marty 2019-11-21 11:02:12 +01:00
parent 4e41156db3
commit eb4355890e
3 changed files with 35 additions and 1 deletions

View File

@ -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'

View File

@ -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()

View File

@ -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() {