diff --git a/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt b/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt index 143818f3e5..bb11ec0dc5 100644 --- a/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt +++ b/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt @@ -110,6 +110,7 @@ import im.vector.app.features.onboarding.ftueauth.FtueAuthLegacyStyleCaptchaFrag import im.vector.app.features.onboarding.ftueauth.FtueAuthLegacyWaitForEmailFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthLoginFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthPersonalizationCompleteFragment +import im.vector.app.features.onboarding.ftueauth.FtueAuthPhoneConfirmationFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthPhoneEntryFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthResetPasswordFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthResetPasswordMailConfirmationFragment @@ -515,6 +516,11 @@ interface FragmentModule { @FragmentKey(FtueAuthPhoneEntryFragment::class) fun bindFtueAuthPhoneEntryFragment(fragment: FtueAuthPhoneEntryFragment): Fragment + @Binds + @IntoMap + @FragmentKey(FtueAuthPhoneConfirmationFragment::class) + fun bindFtueAuthPhoneConfirmationFragment(fragment: FtueAuthPhoneConfirmationFragment): Fragment + @Binds @IntoMap @FragmentKey(FtueAuthChooseDisplayNameFragment::class) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthPhoneConfirmationFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthPhoneConfirmationFragment.kt new file mode 100644 index 0000000000..39577efa19 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthPhoneConfirmationFragment.kt @@ -0,0 +1,80 @@ +/* + * 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.os.Parcelable +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.airbnb.mvrx.args +import im.vector.app.R +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.setOnImeDoneListener +import im.vector.app.databinding.FragmentFtuePhoneConfirmationBinding +import im.vector.app.features.onboarding.OnboardingAction +import im.vector.app.features.onboarding.RegisterAction +import kotlinx.parcelize.Parcelize +import org.matrix.android.sdk.api.failure.Failure +import javax.inject.Inject + +@Parcelize +data class FtueAuthPhoneConfirmationFragmentArgument( + val msisdn: String +) : Parcelable + +class FtueAuthPhoneConfirmationFragment @Inject constructor() : AbstractFtueAuthFragment() { + + private val params: FtueAuthPhoneConfirmationFragmentArgument by args() + + override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtuePhoneConfirmationBinding { + return FragmentFtuePhoneConfirmationBinding.inflate(inflater, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setupViews() + } + + private fun setupViews() { + views.phoneConfirmationHeaderSubtitle.text = getString(R.string.ftue_auth_phone_confirmation_subtitle, params.msisdn) + views.phoneConfirmationInput.associateContentStateWith(button = views.phoneConfirmationSubmit) + views.phoneConfirmationInput.setOnImeDoneListener { submitConfirmationCode() } + views.phoneConfirmationInput.clearErrorOnChange(viewLifecycleOwner) + views.phoneConfirmationSubmit.debouncedClicks { submitConfirmationCode() } + views.phoneConfirmationResend.debouncedClicks { viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.SendAgainThreePid)) } + } + + private fun submitConfirmationCode() { + val code = views.phoneConfirmationInput.content() + viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.ValidateThreePid(code))) + } + + override fun onError(throwable: Throwable) { + views.phoneConfirmationInput.error = when (throwable) { + // The entered code is not correct + is Failure.SuccessError -> getString(R.string.login_validation_code_is_not_correct) + else -> 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 df5c6e79ef..bb8c523b5f 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 @@ -199,12 +199,7 @@ class FtueAuthVariant( openWaitForEmailVerification(viewEvents.email) } is OnboardingViewEvents.OnSendMsisdnSuccess -> { - // Pop the enter Msisdn Fragment - supportFragmentManager.popBackStack(FRAGMENT_REGISTRATION_STAGE_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE) - addRegistrationStageFragmentToBackstack( - FtueAuthGenericTextInputFormFragment::class.java, - FtueAuthGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.ConfirmMsisdn, true, viewEvents.msisdn), - ) + openMsisdnConfirmation(viewEvents.msisdn) } is OnboardingViewEvents.Failure, is OnboardingViewEvents.Loading -> @@ -432,6 +427,20 @@ class FtueAuthVariant( } } + private fun openMsisdnConfirmation(msisdn: String) { + supportFragmentManager.popBackStack(FRAGMENT_REGISTRATION_STAGE_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE) + when { + vectorFeatures.isOnboardingCombinedRegisterEnabled() -> addRegistrationStageFragmentToBackstack( + FtueAuthPhoneConfirmationFragment::class.java, + FtueAuthPhoneConfirmationFragmentArgument(msisdn), + ) + else -> addRegistrationStageFragmentToBackstack( + FtueAuthGenericTextInputFormFragment::class.java, + FtueAuthGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.ConfirmMsisdn, true, msisdn), + ) + } + } + private fun onTerms(stage: Stage.Terms) { when { vectorFeatures.isOnboardingCombinedRegisterEnabled() -> addRegistrationStageFragmentToBackstack( diff --git a/vector/src/main/res/layout/fragment_ftue_phone_confirmation.xml b/vector/src/main/res/layout/fragment_ftue_phone_confirmation.xml new file mode 100644 index 0000000000..fe913d3d7d --- /dev/null +++ b/vector/src/main/res/layout/fragment_ftue_phone_confirmation.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +