From df6ebcacd12955c1d4ebb3958f32666b702d4081 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 19 May 2022 14:33:37 +0100 Subject: [PATCH 1/7] adding msisdn fragment and layout, copied from email input --- .../ftueauth/FtueAuthEmailEntryFragment.kt | 17 ++- .../ftueauth/FtueAuthPhoneEntryFragment.kt | 74 ++++++++++ .../onboarding/ftueauth/FtueAuthVariant.kt | 18 ++- .../res/layout/fragment_ftue_phone_input.xml | 131 ++++++++++++++++++ 4 files changed, 229 insertions(+), 11 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthPhoneEntryFragment.kt create mode 100644 vector/src/main/res/layout/fragment_ftue_phone_input.xml 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 523d576120..e3bf2becd8 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 @@ -16,25 +16,27 @@ package im.vector.app.features.onboarding.ftueauth +import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.autofill.HintConstants import im.vector.app.core.extensions.associateContentStateWith import im.vector.app.core.extensions.clearErrorOnChange import im.vector.app.core.extensions.content import im.vector.app.core.extensions.isEmail import im.vector.app.core.extensions.setOnImeDoneListener -import im.vector.app.databinding.FragmentFtueEmailInputBinding +import im.vector.app.databinding.FragmentFtuePhoneInputBinding import im.vector.app.features.onboarding.OnboardingAction import im.vector.app.features.onboarding.RegisterAction import org.matrix.android.sdk.api.auth.registration.RegisterThreePid import javax.inject.Inject -class FtueAuthEmailEntryFragment @Inject constructor() : AbstractFtueAuthFragment() { +class FtueAuthEmailEntryFragment @Inject constructor() : AbstractFtueAuthFragment() { - override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueEmailInputBinding { - return FragmentFtueEmailInputBinding.inflate(inflater, container, false) + override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtuePhoneInputBinding { + return FragmentFtuePhoneInputBinding.inflate(inflater, container, false) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -47,6 +49,13 @@ class FtueAuthEmailEntryFragment @Inject constructor() : AbstractFtueAuthFragmen views.emailEntryInput.setOnImeDoneListener { updateEmail() } views.emailEntryInput.clearErrorOnChange(viewLifecycleOwner) views.emailEntrySubmit.debouncedClicks { updateEmail() } + setupAutoFill() + } + + private fun setupAutoFill() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + views.emailEntryInput.setAutofillHints(HintConstants.AUTOFILL_HINT_PHONE_NUMBER) + } } private fun updateEmail() { diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthPhoneEntryFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthPhoneEntryFragment.kt new file mode 100644 index 0000000000..f978921348 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthPhoneEntryFragment.kt @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.onboarding.ftueauth + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.lifecycle.lifecycleScope +import im.vector.app.core.extensions.associateContentStateWith +import im.vector.app.core.extensions.content +import im.vector.app.core.extensions.editText +import im.vector.app.core.extensions.isEmail +import im.vector.app.core.extensions.setOnImeDoneListener +import im.vector.app.databinding.FragmentFtueEmailInputBinding +import im.vector.app.features.onboarding.OnboardingAction +import im.vector.app.features.onboarding.RegisterAction +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import org.matrix.android.sdk.api.auth.registration.RegisterThreePid +import reactivecircus.flowbinding.android.widget.textChanges +import javax.inject.Inject + +class FtueAuthPhoneEntryFragment @Inject constructor() : AbstractFtueAuthFragment() { + + override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueEmailInputBinding { + return FragmentFtueEmailInputBinding.inflate(inflater, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setupViews() + } + + private fun setupViews() { + views.emailEntryInput.associateContentStateWith(button = views.emailEntrySubmit) + views.emailEntryInput.setOnImeDoneListener { updateEmail() } + views.emailEntrySubmit.debouncedClicks { updateEmail() } + + views.emailEntryInput.editText().textChanges() + .onEach { + views.emailEntryInput.error = null + views.emailEntrySubmit.isEnabled = it.isEmail() + } + .launchIn(viewLifecycleOwner.lifecycleScope) + } + + private fun updateEmail() { + val email = views.emailEntryInput.content() + viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.AddThreePid(RegisterThreePid.Email(email)))) + } + + override fun onError(throwable: Throwable) { + views.emailEntryInput.error = errorFormatter.toHumanReadable(throwable) + } + + override fun resetViewModel() { + viewModel.handle(OnboardingAction.ResetAuthenticationAttempt) + } +} 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 2880b16156..6ac922cece 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 @@ -387,16 +387,20 @@ class FtueAuthVariant( when (stage) { is Stage.ReCaptcha -> onCaptcha(stage) - is Stage.Email -> onEmail(stage) - is Stage.Msisdn -> addRegistrationStageFragmentToBackstack( - FtueAuthGenericTextInputFormFragment::class.java, - FtueAuthGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.SetMsisdn, stage.mandatory), - ) - is Stage.Terms -> onTerms(stage) - else -> Unit // Should not happen + is Stage.Email -> onEmail(stage) + is Stage.Msisdn -> onMsisdn(stage) + is Stage.Terms -> onTerms(stage) + else -> Unit // Should not happen } } + private fun onMsisdn(stage: Stage) { + addRegistrationStageFragmentToBackstack( + FtueAuthGenericTextInputFormFragment::class.java, + FtueAuthGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.SetMsisdn, stage.mandatory), + ) + } + private fun onEmail(stage: Stage) { when { vectorFeatures.isOnboardingCombinedRegisterEnabled() -> addRegistrationStageFragmentToBackstack( diff --git a/vector/src/main/res/layout/fragment_ftue_phone_input.xml b/vector/src/main/res/layout/fragment_ftue_phone_input.xml new file mode 100644 index 0000000000..0cfcfea7cc --- /dev/null +++ b/vector/src/main/res/layout/fragment_ftue_phone_input.xml @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +