From 863b4b810f83da099cb450ab37e6b3c6ca4e199b Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 6 Apr 2022 09:59:25 +0100 Subject: [PATCH] duplicating the captcha fragment to style separately for the combined register flow --- .../im/vector/app/core/di/FragmentModule.kt | 6 ++ .../ftueauth/FtueAuthCaptchaFragment.kt | 22 +++---- .../FtueAuthCombinedRegisterFragment.kt | 8 +-- .../FtueAuthLegacyStyleCaptchaFragment.kt | 61 +++++++++++++++++++ .../onboarding/ftueauth/FtueAuthVariant.kt | 2 +- ...ml => fragment_ftue_combined_register.xml} | 0 .../layout/fragment_ftue_login_captcha.xml | 50 +++++++++++++++ 7 files changed, 129 insertions(+), 20 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthLegacyStyleCaptchaFragment.kt rename vector/src/main/res/layout/{fragment_ftue_sign_up_combined.xml => fragment_ftue_combined_register.xml} (100%) create mode 100644 vector/src/main/res/layout/fragment_ftue_login_captcha.xml 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 4dcfbe16f8..7a04a4c8b8 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 @@ -102,6 +102,7 @@ import im.vector.app.features.onboarding.ftueauth.FtueAuthCaptchaFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthChooseDisplayNameFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthChooseProfilePictureFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthGenericTextInputFormFragment +import im.vector.app.features.onboarding.ftueauth.FtueAuthLegacyStyleCaptchaFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthLoginFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthPersonalizationCompleteFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthResetPasswordFragment @@ -407,6 +408,11 @@ interface FragmentModule { @FragmentKey(LoginWaitForEmailFragment2::class) fun bindLoginWaitForEmailFragment2(fragment: LoginWaitForEmailFragment2): Fragment + @Binds + @IntoMap + @FragmentKey(FtueAuthLegacyStyleCaptchaFragment::class) + fun bindFtueAuthLegacyStyleCaptchaFragment(fragment: FtueAuthLegacyStyleCaptchaFragment): Fragment + @Binds @IntoMap @FragmentKey(FtueAuthCaptchaFragment::class) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCaptchaFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCaptchaFragment.kt index 4c8dd8e932..e658c4948e 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCaptchaFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCaptchaFragment.kt @@ -1,5 +1,5 @@ /* - * Copyright 2022 New Vector Ltd + * 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. @@ -16,37 +16,29 @@ package im.vector.app.features.onboarding.ftueauth -import android.os.Parcelable import android.view.LayoutInflater import android.view.ViewGroup import com.airbnb.mvrx.args -import im.vector.app.databinding.FragmentLoginCaptchaBinding +import im.vector.app.databinding.FragmentFtueLoginCaptchaBinding 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 javax.inject.Inject -@Parcelize -data class FtueAuthCaptchaFragmentArgument( - val siteKey: String -) : Parcelable - /** * In this screen, the user is asked to confirm they are not a robot */ class FtueAuthCaptchaFragment @Inject constructor( private val captchaWebview: CaptchaWebview -) : AbstractFtueAuthFragment() { - - override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentLoginCaptchaBinding { - return FragmentLoginCaptchaBinding.inflate(inflater, container, false) - } +) : AbstractFtueAuthFragment() { private val params: FtueAuthCaptchaFragmentArgument by args() - private var isWebViewLoaded = false + override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueLoginCaptchaBinding { + return FragmentFtueLoginCaptchaBinding.inflate(inflater, container, false) + } + override fun resetViewModel() { viewModel.handle(OnboardingAction.ResetAuthenticationAttempt) } diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedRegisterFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedRegisterFragment.kt index 441fd64b0b..0755f18c8c 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedRegisterFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedRegisterFragment.kt @@ -37,7 +37,7 @@ import im.vector.app.core.extensions.hideKeyboard import im.vector.app.core.extensions.hidePassword import im.vector.app.core.extensions.realignPercentagesToParent import im.vector.app.core.extensions.toReducedUrl -import im.vector.app.databinding.FragmentFtueSignUpCombinedBinding +import im.vector.app.databinding.FragmentFtueCombinedRegisterBinding import im.vector.app.features.login.LoginMode import im.vector.app.features.login.SSORedirectRouterActivity import im.vector.app.features.login.SocialLoginButtonsView @@ -56,10 +56,10 @@ import org.matrix.android.sdk.api.failure.isUsernameInUse import org.matrix.android.sdk.api.failure.isWeakPassword import javax.inject.Inject -class FtueAuthCombinedRegisterFragment @Inject constructor() : AbstractSSOFtueAuthFragment() { +class FtueAuthCombinedRegisterFragment @Inject constructor() : AbstractSSOFtueAuthFragment() { - override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueSignUpCombinedBinding { - return FragmentFtueSignUpCombinedBinding.inflate(inflater, container, false) + override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueCombinedRegisterBinding { + return FragmentFtueCombinedRegisterBinding.inflate(inflater, container, false) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthLegacyStyleCaptchaFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthLegacyStyleCaptchaFragment.kt new file mode 100644 index 0000000000..dc17ab1cb8 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthLegacyStyleCaptchaFragment.kt @@ -0,0 +1,61 @@ +/* + * Copyright 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.Parcelable +import android.view.LayoutInflater +import android.view.ViewGroup +import com.airbnb.mvrx.args +import im.vector.app.databinding.FragmentLoginCaptchaBinding +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 javax.inject.Inject + +@Parcelize +data class FtueAuthCaptchaFragmentArgument( + val siteKey: String +) : Parcelable + +/** + * In this screen, the user is asked to confirm they are not a robot + */ +class FtueAuthLegacyStyleCaptchaFragment @Inject constructor( + private val captchaWebview: CaptchaWebview +) : AbstractFtueAuthFragment() { + + private val params: FtueAuthCaptchaFragmentArgument by args() + private var isWebViewLoaded = false + + override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentLoginCaptchaBinding { + return FragmentLoginCaptchaBinding.inflate(inflater, container, false) + } + + override fun resetViewModel() { + viewModel.handle(OnboardingAction.ResetAuthenticationAttempt) + } + + override fun updateWithState(state: OnboardingViewState) { + if (!isWebViewLoaded) { + captchaWebview.setupWebView(this, views.loginCaptchaWevView, views.loginCaptchaProgress, params.siteKey, state) { + viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.CaptchaDone(it))) + } + isWebViewLoaded = true + } + } +} 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 a35014ca64..461975ed07 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 @@ -384,7 +384,7 @@ class FtueAuthVariant( when (stage) { is Stage.ReCaptcha -> activity.addFragmentToBackstack( views.loginFragmentContainer, - FtueAuthCaptchaFragment::class.java, + FtueAuthLegacyStyleCaptchaFragment::class.java, FtueAuthCaptchaFragmentArgument(stage.publicKey), tag = FRAGMENT_REGISTRATION_STAGE_TAG, option = commonOption diff --git a/vector/src/main/res/layout/fragment_ftue_sign_up_combined.xml b/vector/src/main/res/layout/fragment_ftue_combined_register.xml similarity index 100% rename from vector/src/main/res/layout/fragment_ftue_sign_up_combined.xml rename to vector/src/main/res/layout/fragment_ftue_combined_register.xml diff --git a/vector/src/main/res/layout/fragment_ftue_login_captcha.xml b/vector/src/main/res/layout/fragment_ftue_login_captcha.xml new file mode 100644 index 0000000000..655bd98097 --- /dev/null +++ b/vector/src/main/res/layout/fragment_ftue_login_captcha.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + +