Fix crash in registration v2 country code drop down.

This commit is contained in:
Nicholas Tinsley 2024-06-06 15:30:22 -04:00 committed by Cody Henthorne
parent c8a9759eba
commit 4151d123cd
2 changed files with 10 additions and 2 deletions

View file

@ -186,8 +186,11 @@ class EnterPhoneNumberV2Fragment : LoggingFragment(R.layout.fragment_registratio
private fun initializeInputFields() {
binding.countryCode.editText?.addTextChangedListener { s ->
val countryCode: Int = s.toString().toInt()
fragmentViewModel.setCountry(countryCode)
val sanitized = s.toString().filter { c -> c.isDigit() }
if (sanitized.isNotNullOrBlank()) {
val countryCode: Int = sanitized.toInt()
fragmentViewModel.setCountry(countryCode)
}
}
phoneNumberInputLayout.addTextChangedListener {

View file

@ -63,6 +63,11 @@ class EnterPhoneNumberV2ViewModel : ViewModel() {
fun setCountry(digits: Int) {
val matchingIndex = countryCodeToAdapterIndex(digits)
if (matchingIndex == -1) {
Log.d(TAG, "Invalid country code specified $digits")
return
}
store.update {
it.copy(countryPrefixIndex = matchingIndex)
}