From 62e8beadf8c0ece8e56e21b86d9e96c0ec68d3b2 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 31 Aug 2022 17:35:38 +0100 Subject: [PATCH 1/2] allowing optional emails - when the email stage is non mandatory, email emails are treated as a dummy step, as per the legacy flow --- changelog.d/6969.bugfix | 1 + .../ftueauth/FtueAuthEmailEntryFragment.kt | 25 ++++++++++++++++--- .../onboarding/ftueauth/FtueAuthVariant.kt | 3 ++- .../res/layout/fragment_ftue_email_input.xml | 5 ++-- 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 changelog.d/6969.bugfix diff --git a/changelog.d/6969.bugfix b/changelog.d/6969.bugfix new file mode 100644 index 0000000000..4f3a161b41 --- /dev/null +++ b/changelog.d/6969.bugfix @@ -0,0 +1 @@ +FTUE - Fixes optional email registration step always being mandatory 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 4cd35c8a66..70a711e2f9 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 @@ -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() { +class FtueAuthEmailEntryFragment : AbstractFtueAuthFragment() { + + private val params: FtueAuthEmailEntryFragmentArgument by args() override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueEmailInputBinding { return FragmentFtueEmailInputBinding.inflate(inflater, container, false) @@ -51,7 +60,10 @@ 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 +72,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()) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt index f3767aa546..6fe1b5b7bb 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt @@ -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, diff --git a/vector/src/main/res/layout/fragment_ftue_email_input.xml b/vector/src/main/res/layout/fragment_ftue_email_input.xml index 046d9de552..c58fd3fc6e 100644 --- a/vector/src/main/res/layout/fragment_ftue_email_input.xml +++ b/vector/src/main/res/layout/fragment_ftue_email_input.xml @@ -1,6 +1,7 @@ + app:layout_constraintTop_toBottomOf="@id/titleContentSpacing" + tools:hint="@string/ftue_auth_email_entry_title"> Date: Thu, 1 Sep 2022 12:46:49 +0100 Subject: [PATCH 2/2] formatting function arguments to be on separate lines --- .../onboarding/ftueauth/FtueAuthEmailEntryFragment.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 70a711e2f9..e315f191c1 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 @@ -61,9 +61,10 @@ class FtueAuthEmailEntryFragment : AbstractFtueAuthFragment