-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FTUE - Msisdn (phone number) entry #6108
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
df6ebca
adding msisdn fragment and layout, copied from email input
ouchadam a8b73f0
applying autofill hints for phonenumber and email entry
ouchadam 7617309
hooking up, styling and applying copy to the phone number fragment
ouchadam 27b1bc9
handling msisdn 401 errors as success within the registration wizard …
ouchadam 0bbc74b
injects the phonenumberutil and adds testcases around the parsing
ouchadam f2db4be
fixing formatting/unused imports
ouchadam bfa50f1
formatting
ouchadam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...or/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthPhoneEntryFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* 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.R | ||
import im.vector.app.core.extensions.associateContentStateWith | ||
import im.vector.app.core.extensions.autofillPhoneNumber | ||
import im.vector.app.core.extensions.content | ||
import im.vector.app.core.extensions.editText | ||
import im.vector.app.core.extensions.setOnImeDoneListener | ||
import im.vector.app.databinding.FragmentFtuePhoneInputBinding | ||
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( | ||
private val phoneNumberParser: PhoneNumberParser | ||
) : AbstractFtueAuthFragment<FragmentFtuePhoneInputBinding>() { | ||
|
||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtuePhoneInputBinding { | ||
return FragmentFtuePhoneInputBinding.inflate(inflater, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setupViews() | ||
} | ||
|
||
private fun setupViews() { | ||
views.phoneEntryInput.associateContentStateWith(button = views.phoneEntrySubmit) | ||
views.phoneEntryInput.setOnImeDoneListener { updatePhoneNumber() } | ||
views.phoneEntrySubmit.debouncedClicks { updatePhoneNumber() } | ||
|
||
views.phoneEntryInput.editText().textChanges() | ||
.onEach { | ||
views.phoneEntryInput.error = null | ||
views.phoneEntrySubmit.isEnabled = it.isNotBlank() | ||
} | ||
.launchIn(viewLifecycleOwner.lifecycleScope) | ||
|
||
views.phoneEntryInput.autofillPhoneNumber() | ||
} | ||
|
||
private fun updatePhoneNumber() { | ||
val number = views.phoneEntryInput.content() | ||
|
||
when (val result = phoneNumberParser.parseInternationalNumber(number)) { | ||
PhoneNumberParser.Result.ErrorInvalidNumber -> views.phoneEntryInput.error = getString(R.string.login_msisdn_error_other) | ||
PhoneNumberParser.Result.ErrorMissingInternationalCode -> views.phoneEntryInput.error = getString(R.string.login_msisdn_error_not_international) | ||
is PhoneNumberParser.Result.Success -> { | ||
val (countryCode, phoneNumber) = result | ||
viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.AddThreePid(RegisterThreePid.Msisdn(phoneNumber, countryCode)))) | ||
} | ||
} | ||
} | ||
|
||
override fun onError(throwable: Throwable) { | ||
views.phoneEntryInput.error = errorFormatter.toHumanReadable(throwable) | ||
} | ||
|
||
override fun resetViewModel() { | ||
viewModel.handle(OnboardingAction.ResetAuthenticationAttempt) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
vector/src/main/java/im/vector/app/features/onboarding/ftueauth/PhoneNumberParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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 com.google.i18n.phonenumbers.NumberParseException | ||
import com.google.i18n.phonenumbers.PhoneNumberUtil | ||
import javax.inject.Inject | ||
|
||
class PhoneNumberParser @Inject constructor( | ||
private val phoneNumberUtil: PhoneNumberUtil | ||
) { | ||
|
||
fun parseInternationalNumber(rawPhoneNumber: String): Result { | ||
return when { | ||
rawPhoneNumber.doesNotStartWith("+") -> Result.ErrorMissingInternationalCode | ||
else -> parseNumber(rawPhoneNumber) | ||
} | ||
} | ||
|
||
private fun parseNumber(rawPhoneNumber: String) = try { | ||
val phoneNumber = phoneNumberUtil.parse(rawPhoneNumber, null) | ||
Result.Success(phoneNumberUtil.getRegionCodeForCountryCode(phoneNumber.countryCode), rawPhoneNumber) | ||
} catch (e: NumberParseException) { | ||
Result.ErrorInvalidNumber | ||
} | ||
|
||
sealed interface Result { | ||
object ErrorMissingInternationalCode : Result | ||
object ErrorInvalidNumber : Result | ||
data class Success(val countryCode: String, val phoneNumber: String) : Result | ||
} | ||
|
||
private fun String.doesNotStartWith(input: String) = !startsWith(input) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:width="71dp" | ||
android:height="70dp" | ||
android:viewportWidth="71" | ||
android:viewportHeight="70"> | ||
<path | ||
android:fillColor="#ff0000" | ||
android:pathData="M29.378,41.602C31.28,43.655 35.858,47.21 37.106,47.94C37.18,47.983 37.264,48.033 37.359,48.09C39.263,49.221 45.229,52.768 49.576,49.449C52.944,46.877 51.848,43.985 50.715,43.125C49.939,42.521 47.652,40.857 45.501,39.359C43.389,37.887 42.211,39.066 41.415,39.863C41.401,39.878 41.386,39.892 41.372,39.907L39.77,41.508C39.362,41.916 38.742,41.767 38.148,41.301C36.015,39.677 34.447,38.11 33.662,37.325L33.655,37.318C32.871,36.534 31.323,34.984 29.699,32.852C29.233,32.258 29.084,31.638 29.492,31.23L31.093,29.628C31.108,29.614 31.122,29.599 31.137,29.584C31.934,28.788 33.113,27.611 31.641,25.499C30.143,23.347 28.479,21.061 27.875,20.285C27.015,19.151 24.122,18.056 21.551,21.424C18.232,25.771 21.778,31.737 22.91,33.641C22.966,33.736 23.017,33.82 23.06,33.894C23.789,35.142 27.325,39.7 29.378,41.602Z" | ||
tools:ignore="VectorPath" /> | ||
</vector> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
International phone numbers can also start with "00" instead of "+". Perhaps we should check that too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
https://en.wikipedia.org/wiki/International_call_prefix
tl;dr mobile networks automatically covert from + to the correct IDD prefix
we would have to support multiple variants of
00
,011
etc which wouldn't scale too well and for the most part should be safe to replace with a+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah...... let's stick with the + 😂