Merge pull request #6981 from vector-im/feature/adm/allow-optional-emails

Allowing optional email registration
This commit is contained in:
Adam Brown 2022-09-01 16:30:20 +01:00 committed by GitHub
commit bddb37ef7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 7 deletions

1
changelog.d/6969.bugfix Normal file
View File

@ -0,0 +1 @@
FTUE - Fixes optional email registration step always being mandatory

View File

@ -17,9 +17,11 @@
package im.vector.app.features.onboarding.ftueauth
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.airbnb.mvrx.args
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.extensions.associateContentStateWith
@ -35,11 +37,18 @@ import im.vector.app.databinding.FragmentFtueEmailInputBinding
import im.vector.app.features.onboarding.OnboardingAction
import im.vector.app.features.onboarding.OnboardingViewState
import im.vector.app.features.onboarding.RegisterAction
import kotlinx.parcelize.Parcelize
import org.matrix.android.sdk.api.auth.registration.RegisterThreePid
@Parcelize
data class FtueAuthEmailEntryFragmentArgument(
val mandatory: Boolean,
) : Parcelable
@AndroidEntryPoint
class FtueAuthEmailEntryFragment :
AbstractFtueAuthFragment<FragmentFtueEmailInputBinding>() {
class FtueAuthEmailEntryFragment : AbstractFtueAuthFragment<FragmentFtueEmailInputBinding>() {
private val params: FtueAuthEmailEntryFragmentArgument by args()
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueEmailInputBinding {
return FragmentFtueEmailInputBinding.inflate(inflater, container, false)
@ -51,7 +60,11 @@ class FtueAuthEmailEntryFragment :
}
private fun setupViews() {
views.emailEntryInput.associateContentStateWith(button = views.emailEntrySubmit, enabledPredicate = { it.isEmail() })
views.emailEntryInput.hint = getString(if (params.mandatory) R.string.ftue_auth_email_entry_title else R.string.login_set_email_optional_hint)
views.emailEntryInput.associateContentStateWith(
button = views.emailEntrySubmit,
enabledPredicate = { it.isEmail() || it.isEmptyAndOptional() },
)
views.emailEntryInput.setOnImeDoneListener { updateEmail() }
views.emailEntryInput.clearErrorOnChange(viewLifecycleOwner)
views.emailEntrySubmit.debouncedClicks { updateEmail() }
@ -60,9 +73,14 @@ class FtueAuthEmailEntryFragment :
private fun updateEmail() {
val email = views.emailEntryInput.content()
viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.AddThreePid(RegisterThreePid.Email(email))))
when {
email.isEmptyAndOptional() -> viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.RegisterDummy))
else -> viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.AddThreePid(RegisterThreePid.Email(email))))
}
}
private fun String.isEmptyAndOptional() = isEmpty() && !params.mandatory
override fun updateWithState(state: OnboardingViewState) {
views.emailEntryHeaderSubtitle.text = getString(R.string.ftue_auth_email_subtitle, state.selectedHomeserver.userFacingUrl.toReducedUrl())

View File

@ -411,7 +411,8 @@ class FtueAuthVariant(
private fun onEmail(stage: Stage) {
when {
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> addRegistrationStageFragmentToBackstack(
FtueAuthEmailEntryFragment::class.java
FtueAuthEmailEntryFragment::class.java,
FtueAuthEmailEntryFragmentArgument(mandatory = stage.mandatory)
)
else -> addRegistrationStageFragmentToBackstack(
FtueAuthGenericTextInputFormFragment::class.java,

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="@style/LoginFormScrollView"
android:layout_height="match_parent"
android:background="?android:colorBackground"
@ -88,11 +89,11 @@
android:id="@+id/emailEntryInput"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/ftue_auth_email_entry_title"
app:endIconMode="clear_text"
app:layout_constraintEnd_toEndOf="@id/emailEntryGutterEnd"
app:layout_constraintStart_toStartOf="@id/emailEntryGutterStart"
app:layout_constraintTop_toBottomOf="@id/titleContentSpacing">
app:layout_constraintTop_toBottomOf="@id/titleContentSpacing"
tools:hint="@string/ftue_auth_email_entry_title">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"