Fixed assistant createButton not enabled & country name not displayed if prefix auto filled

This commit is contained in:
Sylvain Berfini 2023-02-27 11:06:35 +01:00
parent 9726ed04ea
commit 9a086ef205

View file

@ -49,7 +49,7 @@ abstract class AbstractPhoneViewModel(val accountCreator: AccountCreator) :
} }
fun isPhoneNumberOk(): Boolean { fun isPhoneNumberOk(): Boolean {
return countryName.value.orEmpty().isNotEmpty() && phoneNumber.value.orEmpty().isNotEmpty() && phoneNumberError.value.orEmpty().isEmpty() return prefix.value.orEmpty().isNotEmpty() && phoneNumber.value.orEmpty().isNotEmpty() && phoneNumberError.value.orEmpty().isEmpty()
} }
fun updateFromPhoneNumberAndOrDialPlan(number: String?, dialPlan: DialPlan?) { fun updateFromPhoneNumberAndOrDialPlan(number: String?, dialPlan: DialPlan?) {
@ -57,6 +57,7 @@ abstract class AbstractPhoneViewModel(val accountCreator: AccountCreator) :
if (dialPlan != null) { if (dialPlan != null) {
Log.i("[Assistant] Found prefix from dial plan: ${dialPlan.countryCallingCode}") Log.i("[Assistant] Found prefix from dial plan: ${dialPlan.countryCallingCode}")
prefix.value = internationalPrefix prefix.value = internationalPrefix
getCountryNameFromPrefix(internationalPrefix)
} }
if (number != null) { if (number != null) {
@ -69,16 +70,12 @@ abstract class AbstractPhoneViewModel(val accountCreator: AccountCreator) :
} }
} }
private fun getCountryNameFromPrefix(prefix: String?): MutableLiveData<String> { private fun getCountryNameFromPrefix(prefix: String?) {
val country = MutableLiveData<String>()
country.value = ""
if (prefix != null && prefix.isNotEmpty()) { if (prefix != null && prefix.isNotEmpty()) {
val countryCode = if (prefix.first() == '+') prefix.substring(1) else prefix val countryCode = if (prefix.first() == '+') prefix.substring(1) else prefix
val dialPlan = PhoneNumberUtils.getDialPlanFromCountryCallingPrefix(countryCode) val dialPlan = PhoneNumberUtils.getDialPlanFromCountryCallingPrefix(countryCode)
Log.i("[Assistant] Found dial plan $dialPlan from country code: $countryCode") Log.i("[Assistant] Found dial plan $dialPlan from country code: $countryCode")
country.value = dialPlan?.country countryName.value = dialPlan?.country
} }
return country
} }
} }