Skip to content

Commit abf35d7

Browse files
authored
Merge pull request #6157 from vector-im/feature/adm/ftue-msisdn-confirmation
[FTUE] MSISDN / Phone number confirmation
2 parents f3e7d0d + 2a36dc8 commit abf35d7

File tree

5 files changed

+257
-6
lines changed

5 files changed

+257
-6
lines changed

vector/src/main/java/im/vector/app/core/di/FragmentModule.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ import im.vector.app.features.onboarding.ftueauth.FtueAuthLegacyStyleCaptchaFrag
110110
import im.vector.app.features.onboarding.ftueauth.FtueAuthLegacyWaitForEmailFragment
111111
import im.vector.app.features.onboarding.ftueauth.FtueAuthLoginFragment
112112
import im.vector.app.features.onboarding.ftueauth.FtueAuthPersonalizationCompleteFragment
113+
import im.vector.app.features.onboarding.ftueauth.FtueAuthPhoneConfirmationFragment
113114
import im.vector.app.features.onboarding.ftueauth.FtueAuthPhoneEntryFragment
114115
import im.vector.app.features.onboarding.ftueauth.FtueAuthResetPasswordFragment
115116
import im.vector.app.features.onboarding.ftueauth.FtueAuthResetPasswordMailConfirmationFragment
@@ -515,6 +516,11 @@ interface FragmentModule {
515516
@FragmentKey(FtueAuthPhoneEntryFragment::class)
516517
fun bindFtueAuthPhoneEntryFragment(fragment: FtueAuthPhoneEntryFragment): Fragment
517518

519+
@Binds
520+
@IntoMap
521+
@FragmentKey(FtueAuthPhoneConfirmationFragment::class)
522+
fun bindFtueAuthPhoneConfirmationFragment(fragment: FtueAuthPhoneConfirmationFragment): Fragment
523+
518524
@Binds
519525
@IntoMap
520526
@FragmentKey(FtueAuthChooseDisplayNameFragment::class)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2022 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package im.vector.app.features.onboarding.ftueauth
18+
19+
import android.os.Bundle
20+
import android.os.Parcelable
21+
import android.view.LayoutInflater
22+
import android.view.View
23+
import android.view.ViewGroup
24+
import com.airbnb.mvrx.args
25+
import im.vector.app.R
26+
import im.vector.app.core.extensions.associateContentStateWith
27+
import im.vector.app.core.extensions.clearErrorOnChange
28+
import im.vector.app.core.extensions.content
29+
import im.vector.app.core.extensions.setOnImeDoneListener
30+
import im.vector.app.databinding.FragmentFtuePhoneConfirmationBinding
31+
import im.vector.app.features.onboarding.OnboardingAction
32+
import im.vector.app.features.onboarding.RegisterAction
33+
import kotlinx.parcelize.Parcelize
34+
import org.matrix.android.sdk.api.failure.Failure
35+
import javax.inject.Inject
36+
37+
@Parcelize
38+
data class FtueAuthPhoneConfirmationFragmentArgument(
39+
val msisdn: String
40+
) : Parcelable
41+
42+
class FtueAuthPhoneConfirmationFragment @Inject constructor() : AbstractFtueAuthFragment<FragmentFtuePhoneConfirmationBinding>() {
43+
44+
private val params: FtueAuthPhoneConfirmationFragmentArgument by args()
45+
46+
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtuePhoneConfirmationBinding {
47+
return FragmentFtuePhoneConfirmationBinding.inflate(inflater, container, false)
48+
}
49+
50+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
51+
super.onViewCreated(view, savedInstanceState)
52+
setupViews()
53+
}
54+
55+
private fun setupViews() {
56+
views.phoneConfirmationHeaderSubtitle.text = getString(R.string.ftue_auth_phone_confirmation_subtitle, params.msisdn)
57+
views.phoneConfirmationInput.associateContentStateWith(button = views.phoneConfirmationSubmit)
58+
views.phoneConfirmationInput.setOnImeDoneListener { submitConfirmationCode() }
59+
views.phoneConfirmationInput.clearErrorOnChange(viewLifecycleOwner)
60+
views.phoneConfirmationSubmit.debouncedClicks { submitConfirmationCode() }
61+
views.phoneConfirmationResend.debouncedClicks { viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.SendAgainThreePid)) }
62+
}
63+
64+
private fun submitConfirmationCode() {
65+
val code = views.phoneConfirmationInput.content()
66+
viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.ValidateThreePid(code)))
67+
}
68+
69+
override fun onError(throwable: Throwable) {
70+
views.phoneConfirmationInput.error = when (throwable) {
71+
// The entered code is not correct
72+
is Failure.SuccessError -> getString(R.string.login_validation_code_is_not_correct)
73+
else -> errorFormatter.toHumanReadable(throwable)
74+
}
75+
}
76+
77+
override fun resetViewModel() {
78+
viewModel.handle(OnboardingAction.ResetAuthenticationAttempt)
79+
}
80+
}

vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,7 @@ class FtueAuthVariant(
199199
openWaitForEmailVerification(viewEvents.email)
200200
}
201201
is OnboardingViewEvents.OnSendMsisdnSuccess -> {
202-
// Pop the enter Msisdn Fragment
203-
supportFragmentManager.popBackStack(FRAGMENT_REGISTRATION_STAGE_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE)
204-
addRegistrationStageFragmentToBackstack(
205-
FtueAuthGenericTextInputFormFragment::class.java,
206-
FtueAuthGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.ConfirmMsisdn, true, viewEvents.msisdn),
207-
)
202+
openMsisdnConfirmation(viewEvents.msisdn)
208203
}
209204
is OnboardingViewEvents.Failure,
210205
is OnboardingViewEvents.Loading ->
@@ -432,6 +427,20 @@ class FtueAuthVariant(
432427
}
433428
}
434429

430+
private fun openMsisdnConfirmation(msisdn: String) {
431+
supportFragmentManager.popBackStack(FRAGMENT_REGISTRATION_STAGE_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE)
432+
when {
433+
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> addRegistrationStageFragmentToBackstack(
434+
FtueAuthPhoneConfirmationFragment::class.java,
435+
FtueAuthPhoneConfirmationFragmentArgument(msisdn),
436+
)
437+
else -> addRegistrationStageFragmentToBackstack(
438+
FtueAuthGenericTextInputFormFragment::class.java,
439+
FtueAuthGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.ConfirmMsisdn, true, msisdn),
440+
)
441+
}
442+
}
443+
435444
private fun onTerms(stage: Stage.Terms) {
436445
when {
437446
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> addRegistrationStageFragmentToBackstack(
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
style="@style/LoginFormScrollView"
6+
android:layout_height="match_parent"
7+
android:background="?android:colorBackground"
8+
android:fillViewport="true"
9+
android:paddingTop="0dp"
10+
android:paddingBottom="0dp">
11+
12+
<androidx.constraintlayout.widget.ConstraintLayout
13+
android:layout_width="match_parent"
14+
android:layout_height="wrap_content">
15+
16+
<androidx.constraintlayout.widget.Guideline
17+
android:id="@+id/phoneConfirmationGutterStart"
18+
android:layout_width="wrap_content"
19+
android:layout_height="match_parent"
20+
android:orientation="vertical"
21+
app:layout_constraintGuide_percent="@dimen/ftue_auth_gutter_start_percent" />
22+
23+
<androidx.constraintlayout.widget.Guideline
24+
android:id="@+id/phoneConfirmationGutterEnd"
25+
android:layout_width="wrap_content"
26+
android:layout_height="match_parent"
27+
android:orientation="vertical"
28+
app:layout_constraintGuide_percent="@dimen/ftue_auth_gutter_end_percent" />
29+
30+
<Space
31+
android:id="@+id/headerSpacing"
32+
android:layout_width="match_parent"
33+
android:layout_height="52dp"
34+
app:layout_constraintBottom_toTopOf="@id/phoneConfirmationHeaderIcon"
35+
app:layout_constraintTop_toTopOf="parent"
36+
app:layout_constraintVertical_bias="0"
37+
app:layout_constraintVertical_chainStyle="packed" />
38+
39+
<ImageView
40+
android:id="@+id/phoneConfirmationHeaderIcon"
41+
android:layout_width="wrap_content"
42+
android:layout_height="0dp"
43+
android:adjustViewBounds="true"
44+
android:background="@drawable/circle"
45+
android:backgroundTint="?colorSecondary"
46+
android:contentDescription="@null"
47+
android:src="@drawable/ic_ftue_phone"
48+
app:layout_constraintBottom_toTopOf="@id/phoneConfirmationHeaderTitle"
49+
app:layout_constraintEnd_toEndOf="@id/phoneConfirmationGutterEnd"
50+
app:layout_constraintHeight_percent="0.12"
51+
app:layout_constraintStart_toStartOf="@id/phoneConfirmationGutterStart"
52+
app:layout_constraintTop_toBottomOf="@id/headerSpacing"
53+
app:tint="@color/palette_white" />
54+
55+
<TextView
56+
android:id="@+id/phoneConfirmationHeaderTitle"
57+
style="@style/Widget.Vector.TextView.Title.Medium"
58+
android:layout_width="0dp"
59+
android:layout_height="wrap_content"
60+
android:layout_marginTop="16dp"
61+
android:gravity="center"
62+
android:text="@string/ftue_auth_phone_confirmation_title"
63+
android:textColor="?vctr_content_primary"
64+
app:layout_constraintBottom_toTopOf="@id/phoneConfirmationHeaderSubtitle"
65+
app:layout_constraintEnd_toEndOf="@id/phoneConfirmationGutterEnd"
66+
app:layout_constraintStart_toStartOf="@id/phoneConfirmationGutterStart"
67+
app:layout_constraintTop_toBottomOf="@id/phoneConfirmationHeaderIcon" />
68+
69+
<TextView
70+
android:id="@+id/phoneConfirmationHeaderSubtitle"
71+
style="@style/Widget.Vector.TextView.Subtitle"
72+
android:layout_width="0dp"
73+
android:layout_height="wrap_content"
74+
android:layout_marginTop="8dp"
75+
android:gravity="center"
76+
android:textColor="?vctr_content_secondary"
77+
app:layout_constraintBottom_toTopOf="@id/titleContentSpacing"
78+
app:layout_constraintEnd_toEndOf="@id/phoneConfirmationGutterEnd"
79+
app:layout_constraintStart_toStartOf="@id/phoneConfirmationGutterStart"
80+
app:layout_constraintTop_toBottomOf="@id/phoneConfirmationHeaderTitle"
81+
tools:text="@string/ftue_auth_phone_confirmation_subtitle" />
82+
83+
<Space
84+
android:id="@+id/titleContentSpacing"
85+
android:layout_width="match_parent"
86+
android:layout_height="0dp"
87+
app:layout_constraintBottom_toTopOf="@id/phoneConfirmationInput"
88+
app:layout_constraintHeight_percent="0.03"
89+
app:layout_constraintTop_toBottomOf="@id/phoneConfirmationHeaderSubtitle" />
90+
91+
<com.google.android.material.textfield.TextInputLayout
92+
android:id="@+id/phoneConfirmationInput"
93+
android:layout_width="0dp"
94+
android:layout_height="wrap_content"
95+
android:hint="@string/ftue_auth_phone_confirmation_entry_title"
96+
app:endIconMode="clear_text"
97+
app:layout_constraintBottom_toTopOf="@id/phoneConfirmationResend"
98+
app:layout_constraintEnd_toEndOf="@id/phoneConfirmationGutterEnd"
99+
app:layout_constraintStart_toStartOf="@id/phoneConfirmationGutterStart"
100+
app:layout_constraintTop_toBottomOf="@id/titleContentSpacing">
101+
102+
<com.google.android.material.textfield.TextInputEditText
103+
android:layout_width="match_parent"
104+
android:layout_height="match_parent"
105+
android:imeOptions="actionDone"
106+
android:inputType="phone"
107+
android:maxLines="1" />
108+
109+
</com.google.android.material.textfield.TextInputLayout>
110+
111+
<Button
112+
android:id="@+id/phoneConfirmationResend"
113+
style="@style/Widget.Vector.Button.Text.Login"
114+
android:layout_width="wrap_content"
115+
android:layout_height="wrap_content"
116+
android:backgroundTint="@color/element_background_light"
117+
android:text="@string/ftue_auth_phone_confirmation_resend_code"
118+
android:textAllCaps="true"
119+
android:textColor="?colorSecondary"
120+
app:layout_constraintBottom_toTopOf="@id/entrySpacing"
121+
app:layout_constraintEnd_toEndOf="@id/phoneConfirmationGutterEnd"
122+
app:layout_constraintHorizontal_bias="1"
123+
app:layout_constraintStart_toStartOf="@id/phoneConfirmationGutterStart"
124+
app:layout_constraintTop_toBottomOf="@id/phoneConfirmationInput" />
125+
126+
<Space
127+
android:id="@+id/entrySpacing"
128+
android:layout_width="match_parent"
129+
android:layout_height="0dp"
130+
app:layout_constraintBottom_toTopOf="@id/phoneConfirmationSubmit"
131+
app:layout_constraintHeight_percent="0.03"
132+
app:layout_constraintTop_toBottomOf="@id/phoneConfirmationResend"
133+
app:layout_constraintVertical_bias="0"
134+
app:layout_constraintVertical_chainStyle="packed" />
135+
136+
<Button
137+
android:id="@+id/phoneConfirmationSubmit"
138+
style="@style/Widget.Vector.Button.Login"
139+
android:layout_width="0dp"
140+
android:layout_height="wrap_content"
141+
android:text="@string/login_set_email_submit"
142+
android:textAllCaps="true"
143+
app:layout_constraintBottom_toBottomOf="parent"
144+
app:layout_constraintEnd_toEndOf="@id/phoneConfirmationGutterEnd"
145+
app:layout_constraintStart_toStartOf="@id/phoneConfirmationGutterStart"
146+
app:layout_constraintTop_toBottomOf="@id/entrySpacing" />
147+
148+
</androidx.constraintlayout.widget.ConstraintLayout>
149+
150+
</androidx.core.widget.NestedScrollView>

vector/src/main/res/values/donottranslate.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<string name="ftue_auth_phone_title">Enter your phone number</string>
4040
<string name="ftue_auth_phone_subtitle">This will help verify your account and enables password recovery.</string>
4141
<string name="ftue_auth_phone_entry_title">Phone Number</string>
42+
<string name="ftue_auth_phone_confirmation_entry_title">Confirmation code</string>
4243

4344
<string name="ftue_auth_reset_password_email_subtitle">We will send you a verification link.</string>
4445
<string name="ftue_auth_reset_password_breaker_title">Check your email.</string>
@@ -48,6 +49,11 @@
4849
<string name="ftue_auth_reset_password">Reset password</string>
4950
<string name="ftue_auth_sign_out_all_devices">Sign out all devices</string>
5051

52+
<string name="ftue_auth_phone_confirmation_title">Confirm your phone number</string>
53+
<!-- Note for translators, %s is the users international phone number -->
54+
<string name="ftue_auth_phone_confirmation_subtitle">We just sent a code to %s. Enter it below to verify it\'s you.</string>
55+
<string name="ftue_auth_phone_confirmation_resend_code">Resend code</string>
56+
5157
<string name="ftue_auth_email_verification_title">Check your email to verify.</string>
5258
<!-- Note for translators, %s is the users email address -->
5359
<string name="ftue_auth_email_verification_subtitle">To confirm your email address, tap the button in the email we just sent to %s</string>

0 commit comments

Comments
 (0)