adding phone number confirmation resending

This commit is contained in:
Adam Brown 2022-05-25 09:47:00 +01:00
parent e6e079a071
commit be3d419290
3 changed files with 75 additions and 54 deletions

View File

@ -22,9 +22,9 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.airbnb.mvrx.args
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.extensions.associateContentStateWith 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.content
import im.vector.app.core.extensions.editText import im.vector.app.core.extensions.editText
import im.vector.app.core.extensions.setOnImeDoneListener import im.vector.app.core.extensions.setOnImeDoneListener
@ -34,7 +34,7 @@ import im.vector.app.features.onboarding.RegisterAction
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import org.matrix.android.sdk.api.auth.registration.RegisterThreePid import org.matrix.android.sdk.api.failure.Failure
import reactivecircus.flowbinding.android.widget.textChanges import reactivecircus.flowbinding.android.widget.textChanges
import javax.inject.Inject import javax.inject.Inject
@ -43,9 +43,9 @@ data class FtueAuthPhoneConfirmationFragmentArgument(
val msisdn: String val msisdn: String
) : Parcelable ) : Parcelable
class FtueAuthPhoneConfirmationFragment @Inject constructor( class FtueAuthPhoneConfirmationFragment @Inject constructor() : AbstractFtueAuthFragment<FragmentFtuePhoneConfirmationBinding>() {
private val phoneNumberParser: PhoneNumberParser
) : AbstractFtueAuthFragment<FragmentFtuePhoneConfirmationBinding>() { private val params: FtueAuthPhoneConfirmationFragmentArgument by args()
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtuePhoneConfirmationBinding { override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtuePhoneConfirmationBinding {
return FragmentFtuePhoneConfirmationBinding.inflate(inflater, container, false) return FragmentFtuePhoneConfirmationBinding.inflate(inflater, container, false)
@ -57,35 +57,32 @@ class FtueAuthPhoneConfirmationFragment @Inject constructor(
} }
private fun setupViews() { private fun setupViews() {
views.phoneEntryInput.associateContentStateWith(button = views.phoneEntrySubmit) views.phoneConfirmationHeaderSubtitle.text = getString(R.string.ftue_auth_phone_confirmation_subtitle, params.msisdn)
views.phoneEntryInput.setOnImeDoneListener { updatePhoneNumber() } views.phoneConfirmationInput.associateContentStateWith(button = views.phoneConfirmationSubmit)
views.phoneEntrySubmit.debouncedClicks { updatePhoneNumber() } views.phoneConfirmationInput.setOnImeDoneListener { submitConfirmationCode() }
views.phoneConfirmationSubmit.debouncedClicks { submitConfirmationCode() }
views.phoneEntryInput.editText().textChanges() views.phoneConfirmationInput.editText().textChanges()
.onEach { .onEach {
views.phoneEntryInput.error = null views.phoneConfirmationInput.error = null
views.phoneEntrySubmit.isEnabled = it.isNotBlank() views.phoneConfirmationSubmit.isEnabled = it.isNotBlank()
} }
.launchIn(viewLifecycleOwner.lifecycleScope) .launchIn(viewLifecycleOwner.lifecycleScope)
views.phoneEntryInput.autofillPhoneNumber() views.phoneConfirmationResend.debouncedClicks { viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.SendAgainThreePid)) }
} }
private fun updatePhoneNumber() { private fun submitConfirmationCode() {
val number = views.phoneEntryInput.content() val code = views.phoneConfirmationInput.content()
viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.ValidateThreePid(code)))
when (val result = phoneNumberParser.parseInternationalNumber(number)) {
PhoneNumberParser.Result.ErrorInvalidNumber -> views.phoneEntryInput.error = getString(R.string.login_msisdn_error_other)
PhoneNumberParser.Result.ErrorMissingInternationalCode -> views.phoneEntryInput.error = getString(R.string.login_msisdn_error_not_international)
is PhoneNumberParser.Result.Success -> {
val (countryCode, phoneNumber) = result
viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.AddThreePid(RegisterThreePid.Msisdn(phoneNumber, countryCode))))
}
}
} }
override fun onError(throwable: Throwable) { override fun onError(throwable: Throwable) {
views.phoneEntryInput.error = errorFormatter.toHumanReadable(throwable) when (throwable) {
// The entered code is not correct
is Failure.SuccessError -> views.phoneConfirmationInput.error = getString(R.string.login_validation_code_is_not_correct)
else -> views.phoneConfirmationInput.error = errorFormatter.toHumanReadable(throwable)
}
} }
override fun resetViewModel() { override fun resetViewModel() {

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="@style/LoginFormScrollView" style="@style/LoginFormScrollView"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?android:colorBackground" android:background="?android:colorBackground"
@ -13,14 +14,14 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<androidx.constraintlayout.widget.Guideline <androidx.constraintlayout.widget.Guideline
android:id="@+id/phoneEntryGutterStart" android:id="@+id/phoneConfirmationGutterStart"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintGuide_percent="@dimen/ftue_auth_gutter_start_percent" /> app:layout_constraintGuide_percent="@dimen/ftue_auth_gutter_start_percent" />
<androidx.constraintlayout.widget.Guideline <androidx.constraintlayout.widget.Guideline
android:id="@+id/phoneEntryGutterEnd" android:id="@+id/phoneConfirmationGutterEnd"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
@ -30,11 +31,13 @@
android:id="@+id/headerSpacing" android:id="@+id/headerSpacing"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="52dp" android:layout_height="52dp"
app:layout_constraintBottom_toTopOf="@id/phoneEntryHeaderIcon" app:layout_constraintBottom_toTopOf="@id/phoneConfirmationHeaderIcon"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0"
app:layout_constraintVertical_chainStyle="packed" />
<ImageView <ImageView
android:id="@+id/phoneEntryHeaderIcon" android:id="@+id/phoneConfirmationHeaderIcon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="0dp" android:layout_height="0dp"
android:adjustViewBounds="true" android:adjustViewBounds="true"
@ -42,57 +45,58 @@
android:backgroundTint="?colorSecondary" android:backgroundTint="?colorSecondary"
android:contentDescription="@null" android:contentDescription="@null"
android:src="@drawable/ic_ftue_phone" android:src="@drawable/ic_ftue_phone"
app:layout_constraintBottom_toTopOf="@id/phoneEntryHeaderTitle" app:layout_constraintBottom_toTopOf="@id/phoneConfirmationHeaderTitle"
app:layout_constraintEnd_toEndOf="@id/phoneEntryGutterEnd" app:layout_constraintEnd_toEndOf="@id/phoneConfirmationGutterEnd"
app:layout_constraintHeight_percent="0.12" app:layout_constraintHeight_percent="0.12"
app:layout_constraintStart_toStartOf="@id/phoneEntryGutterStart" app:layout_constraintStart_toStartOf="@id/phoneConfirmationGutterStart"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toBottomOf="@id/headerSpacing"
app:tint="@color/palette_white" /> app:tint="@color/palette_white" />
<TextView <TextView
android:id="@+id/phoneEntryHeaderTitle" android:id="@+id/phoneConfirmationHeaderTitle"
style="@style/Widget.Vector.TextView.Title.Medium" style="@style/Widget.Vector.TextView.Title.Medium"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:gravity="center" android:gravity="center"
android:text="@string/ftue_auth_phone_title" android:text="@string/ftue_auth_phone_confirmation_title"
android:textColor="?vctr_content_primary" android:textColor="?vctr_content_primary"
app:layout_constraintBottom_toTopOf="@id/phoneEntryHeaderSubtitle" app:layout_constraintBottom_toTopOf="@id/phoneConfirmationHeaderSubtitle"
app:layout_constraintEnd_toEndOf="@id/phoneEntryGutterEnd" app:layout_constraintEnd_toEndOf="@id/phoneConfirmationGutterEnd"
app:layout_constraintStart_toStartOf="@id/phoneEntryGutterStart" app:layout_constraintStart_toStartOf="@id/phoneConfirmationGutterStart"
app:layout_constraintTop_toBottomOf="@id/phoneEntryHeaderIcon" /> app:layout_constraintTop_toBottomOf="@id/phoneConfirmationHeaderIcon" />
<TextView <TextView
android:id="@+id/phoneEntryHeaderSubtitle" android:id="@+id/phoneConfirmationHeaderSubtitle"
style="@style/Widget.Vector.TextView.Subtitle" style="@style/Widget.Vector.TextView.Subtitle"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:gravity="center" android:gravity="center"
android:text="@string/ftue_auth_phone_subtitle"
android:textColor="?vctr_content_secondary" android:textColor="?vctr_content_secondary"
app:layout_constraintBottom_toTopOf="@id/titleContentSpacing" app:layout_constraintBottom_toTopOf="@id/titleContentSpacing"
app:layout_constraintEnd_toEndOf="@id/phoneEntryGutterEnd" app:layout_constraintEnd_toEndOf="@id/phoneConfirmationGutterEnd"
app:layout_constraintStart_toStartOf="@id/phoneEntryGutterStart" app:layout_constraintStart_toStartOf="@id/phoneConfirmationGutterStart"
app:layout_constraintTop_toBottomOf="@id/phoneEntryHeaderTitle" /> app:layout_constraintTop_toBottomOf="@id/phoneConfirmationHeaderTitle"
tools:text="@string/ftue_auth_phone_confirmation_subtitle" />
<Space <Space
android:id="@+id/titleContentSpacing" android:id="@+id/titleContentSpacing"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/phoneEntryInput" app:layout_constraintBottom_toTopOf="@id/phoneConfirmationInput"
app:layout_constraintHeight_percent="0.03" app:layout_constraintHeight_percent="0.03"
app:layout_constraintTop_toBottomOf="@id/phoneEntryHeaderSubtitle" /> app:layout_constraintTop_toBottomOf="@id/phoneConfirmationHeaderSubtitle" />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/phoneEntryInput" android:id="@+id/phoneConfirmationInput"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/ftue_auth_phone_entry_title" android:hint="@string/ftue_auth_phone_entry_title"
app:endIconMode="clear_text" app:endIconMode="clear_text"
app:layout_constraintEnd_toEndOf="@id/phoneEntryGutterEnd" app:layout_constraintBottom_toTopOf="@id/phoneConfirmationResend"
app:layout_constraintStart_toStartOf="@id/phoneEntryGutterStart" app:layout_constraintEnd_toEndOf="@id/phoneConfirmationGutterEnd"
app:layout_constraintStart_toStartOf="@id/phoneConfirmationGutterStart"
app:layout_constraintTop_toBottomOf="@id/titleContentSpacing"> app:layout_constraintTop_toBottomOf="@id/titleContentSpacing">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
@ -104,26 +108,41 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/phoneConfirmationResend"
style="@style/Widget.Vector.Button.Text.Login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/element_background_light"
android:text="@string/ftue_auth_phone_confirmation_resend_code"
android:textAllCaps="true"
android:textColor="?colorSecondary"
app:layout_constraintBottom_toTopOf="@id/entrySpacing"
app:layout_constraintEnd_toEndOf="@id/phoneConfirmationGutterEnd"
app:layout_constraintHorizontal_bias="1"
app:layout_constraintStart_toStartOf="@id/phoneConfirmationGutterStart"
app:layout_constraintTop_toBottomOf="@id/phoneConfirmationInput" />
<Space <Space
android:id="@+id/entrySpacing" android:id="@+id/entrySpacing"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/phoneEntrySubmit" app:layout_constraintBottom_toTopOf="@id/phoneConfirmationSubmit"
app:layout_constraintHeight_percent="0.03" app:layout_constraintHeight_percent="0.03"
app:layout_constraintTop_toBottomOf="@id/phoneEntryInput" app:layout_constraintTop_toBottomOf="@id/phoneConfirmationResend"
app:layout_constraintVertical_bias="0" app:layout_constraintVertical_bias="0"
app:layout_constraintVertical_chainStyle="packed" /> app:layout_constraintVertical_chainStyle="packed" />
<Button <Button
android:id="@+id/phoneEntrySubmit" android:id="@+id/phoneConfirmationSubmit"
style="@style/Widget.Vector.Button.Login" style="@style/Widget.Vector.Button.Login"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/login_set_email_submit" android:text="@string/login_set_email_submit"
android:textAllCaps="true" android:textAllCaps="true"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/phoneEntryGutterEnd" app:layout_constraintEnd_toEndOf="@id/phoneConfirmationGutterEnd"
app:layout_constraintStart_toStartOf="@id/phoneEntryGutterStart" app:layout_constraintStart_toStartOf="@id/phoneConfirmationGutterStart"
app:layout_constraintTop_toBottomOf="@id/entrySpacing" /> app:layout_constraintTop_toBottomOf="@id/entrySpacing" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -48,6 +48,11 @@
<string name="ftue_auth_reset_password">Reset password</string> <string name="ftue_auth_reset_password">Reset password</string>
<string name="ftue_auth_sign_out_all_devices">Sign out all devices</string> <string name="ftue_auth_sign_out_all_devices">Sign out all devices</string>
<string name="ftue_auth_phone_confirmation_title">Confirm your phone number</string>
<!-- Note for translators, %s is the users international phone number -->
<string name="ftue_auth_phone_confirmation_subtitle">We just sent a code to %s. Enter it below to verify it\'s you.</string>
<string name="ftue_auth_phone_confirmation_resend_code">Resend code</string>
<string name="ftue_auth_email_verification_title">Check your email to verify.</string> <string name="ftue_auth_email_verification_title">Check your email to verify.</string>
<!-- Note for translators, %s is the users email address --> <!-- Note for translators, %s is the users email address -->
<string name="ftue_auth_email_verification_subtitle">To confirm your email address, tap the button in the email we just sent to %s</string> <string name="ftue_auth_email_verification_subtitle">To confirm your email address, tap the button in the email we just sent to %s</string>