diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/AbstractPhoneViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/AbstractPhoneViewModel.kt index aabbc44c9..605b0c5ce 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/AbstractPhoneViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/AbstractPhoneViewModel.kt @@ -32,6 +32,7 @@ abstract class AbstractPhoneViewModel(accountCreator: AccountCreator) : CountryPickerFragment.CountryPickedListener { val prefix = MutableLiveData() + val prefixError = MutableLiveData() val phoneNumber = MutableLiveData() val phoneNumberError = MutableLiveData() @@ -48,7 +49,10 @@ abstract class AbstractPhoneViewModel(accountCreator: AccountCreator) : } fun isPhoneNumberOk(): Boolean { - return prefix.value.orEmpty().isNotEmpty() && phoneNumber.value.orEmpty().isNotEmpty() && phoneNumberError.value.orEmpty().isEmpty() + return prefix.value.orEmpty().length > 1 && // Not just '+' character + prefixError.value.orEmpty().isEmpty() && + phoneNumber.value.orEmpty().isNotEmpty() && + phoneNumberError.value.orEmpty().isEmpty() } fun updateFromPhoneNumberAndOrDialPlan(number: String?, dialPlan: DialPlan?) { diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/AccountLoginViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/AccountLoginViewModel.kt index 8bca89dbb..579a76eb7 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/AccountLoginViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/AccountLoginViewModel.kt @@ -46,7 +46,7 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM val password = MutableLiveData() val passwordError = MutableLiveData() - val loginEnabled: MediatorLiveData = MediatorLiveData() + val loginEnabled = MediatorLiveData() val waitForServerAnswer = MutableLiveData() @@ -140,6 +140,9 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM loginEnabled.addSource(phoneNumberError) { loginEnabled.value = isLoginButtonEnabled() } + loginEnabled.addSource(prefixError) { + loginEnabled.value = isLoginButtonEnabled() + } } override fun onCleared() { @@ -149,6 +152,7 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM override fun onFlexiApiTokenReceived() { Log.i("[Assistant] [Account Login] Using FlexiAPI auth token [${accountCreator.token}]") + waitForServerAnswer.value = false loginWithPhoneNumber() } diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/EchoCancellerCalibrationViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/EchoCancellerCalibrationViewModel.kt index 9b5c54df8..09d01c069 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/EchoCancellerCalibrationViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/EchoCancellerCalibrationViewModel.kt @@ -51,16 +51,16 @@ class EchoCancellerCalibrationViewModel : ViewModel() { coreContext.core.removeListener(listener) when (status) { EcCalibratorStatus.DoneNoEcho -> { - Log.i("[Echo Canceller Calibration] Done, no echo") + Log.i("[Assistant] [Echo Canceller Calibration] Done, no echo") } EcCalibratorStatus.Done -> { - Log.i("[Echo Canceller Calibration] Done, delay is ${delay}ms") + Log.i("[Assistant] [Echo Canceller Calibration] Done, delay is ${delay}ms") } EcCalibratorStatus.Failed -> { - Log.w("[Echo Canceller Calibration] Failed") + Log.w("[Assistant] [Echo Canceller Calibration] Failed") } EcCalibratorStatus.InProgress -> { - Log.i("[Echo Canceller Calibration] In progress") + Log.i("[Assistant] [Echo Canceller Calibration] In progress") } } echoCalibrationTerminated.value = Event(true) diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/EmailAccountCreationViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/EmailAccountCreationViewModel.kt index 08b6f4ab7..dea25074d 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/EmailAccountCreationViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/EmailAccountCreationViewModel.kt @@ -72,7 +72,7 @@ class EmailAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPu status: AccountCreator.Status, response: String? ) { - Log.i("[Account Creation] onIsAccountExist status is $status") + Log.i("[Assistant] [Account Creation] onIsAccountExist status is $status") when (status) { AccountCreator.Status.AccountExist, AccountCreator.Status.AccountExistWithAlias -> { waitForServerAnswer.value = false @@ -99,7 +99,7 @@ class EmailAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPu status: AccountCreator.Status, response: String? ) { - Log.i("[Account Creation] onCreateAccount status is $status") + Log.i("[Assistant] [Account Creation] onCreateAccount status is $status") waitForServerAnswer.value = false when (status) { @@ -149,11 +149,11 @@ class EmailAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPu } override fun onFlexiApiTokenReceived() { - Log.i("[Account Creation] Using FlexiAPI auth token [${accountCreator.token}]") + Log.i("[Assistant] [Account Creation] Using FlexiAPI auth token [${accountCreator.token}]") waitForServerAnswer.value = true val status = accountCreator.isAccountExist - Log.i("[Account Creation] Account exists returned $status") + Log.i("[Assistant] [Account Creation] Account exists returned $status") if (status != AccountCreator.Status.RequestOk) { waitForServerAnswer.value = false onErrorEvent.value = Event("Error: ${status.name}") @@ -161,7 +161,7 @@ class EmailAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPu } override fun onFlexiApiTokenRequestError() { - Log.e("[Account Creation] Failed to get an auth token from FlexiAPI") + Log.e("[Assistant] [Account Creation] Failed to get an auth token from FlexiAPI") waitForServerAnswer.value = false onErrorEvent.value = Event("Error: Failed to get an auth token from account manager server") } @@ -175,11 +175,11 @@ class EmailAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPu val token = accountCreator.token.orEmpty() if (token.isNotEmpty()) { Log.i( - "[Account Creation] We already have an auth token from FlexiAPI [$token], continue" + "[Assistant] [Account Creation] We already have an auth token from FlexiAPI [$token], continue" ) onFlexiApiTokenReceived() } else { - Log.i("[Account Creation] Requesting an auth token from FlexiAPI") + Log.i("[Assistant] [Account Creation] Requesting an auth token from FlexiAPI") waitForServerAnswer.value = true requestFlexiApiToken() } diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/EmailAccountValidationViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/EmailAccountValidationViewModel.kt index 52fffbb26..bc72fbc90 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/EmailAccountValidationViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/EmailAccountValidationViewModel.kt @@ -57,7 +57,7 @@ class EmailAccountValidationViewModel(val accountCreator: AccountCreator) : View status: AccountCreator.Status, response: String? ) { - Log.i("[Account Validation] onIsAccountActivated status is $status") + Log.i("[Assistant] [Account Validation] onIsAccountActivated status is $status") waitForServerAnswer.value = false when (status) { diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/GenericLoginViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/GenericLoginViewModel.kt index 153db0671..5e0e50dfe 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/GenericLoginViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/GenericLoginViewModel.kt @@ -152,6 +152,8 @@ class GenericLoginViewModel(private val accountCreator: AccountCreator) : ViewMo } private fun isLoginButtonEnabled(): Boolean { - return username.value.orEmpty().isNotEmpty() && domain.value.orEmpty().isNotEmpty() && password.value.orEmpty().isNotEmpty() + return username.value.orEmpty().isNotEmpty() && + domain.value.orEmpty().isNotEmpty() && + password.value.orEmpty().isNotEmpty() } } diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/PhoneAccountCreationViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/PhoneAccountCreationViewModel.kt index a857cd1c3..03b6face3 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/PhoneAccountCreationViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/PhoneAccountCreationViewModel.kt @@ -68,7 +68,7 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh status: AccountCreator.Status, response: String? ) { - Log.i("[Phone Account Creation] onIsAccountExist status is $status") + Log.i("[Assistant] [Phone Account Creation] onIsAccountExist status is $status") when (status) { AccountCreator.Status.AccountExist, AccountCreator.Status.AccountExistWithAlias -> { waitForServerAnswer.value = false @@ -92,7 +92,7 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh status: AccountCreator.Status, response: String? ) { - Log.i("[Phone Account Creation] onIsAliasUsed status is $status") + Log.i("[Assistant] [Phone Account Creation] onIsAliasUsed status is $status") when (status) { AccountCreator.Status.AliasExist -> { waitForServerAnswer.value = false @@ -114,7 +114,9 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh } AccountCreator.Status.AliasNotExist -> { val createAccountStatus = creator.createAccount() - Log.i("[Phone Account Creation] createAccount returned $createAccountStatus") + Log.i( + "[Assistant] [Phone Account Creation] createAccount returned $createAccountStatus" + ) if (createAccountStatus != AccountCreator.Status.RequestOk) { waitForServerAnswer.value = false onErrorEvent.value = Event("Error: ${status.name}") @@ -132,7 +134,7 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh status: AccountCreator.Status, response: String? ) { - Log.i("[Phone Account Creation] onCreateAccount status is $status") + Log.i("[Assistant] [Phone Account Creation] onCreateAccount status is $status") waitForServerAnswer.value = false when (status) { AccountCreator.Status.AccountCreated -> { @@ -173,6 +175,9 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh createEnabled.addSource(phoneNumberError) { createEnabled.value = isCreateButtonEnabled() } + createEnabled.addSource(prefixError) { + createEnabled.value = isCreateButtonEnabled() + } } override fun onCleared() { @@ -181,9 +186,22 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh } override fun onFlexiApiTokenReceived() { - Log.i("[Phone Account Creation] Using FlexiAPI auth token [${accountCreator.token}]") + Log.i( + "[Assistant] [Phone Account Creation] Using FlexiAPI auth token [${accountCreator.token}]" + ) accountCreator.displayName = displayName.value - accountCreator.setPhoneNumber(phoneNumber.value, prefix.value) + + val result = AccountCreator.PhoneNumberStatus.fromInt( + accountCreator.setPhoneNumber(phoneNumber.value, prefix.value) + ) + if (result != AccountCreator.PhoneNumberStatus.Ok) { + Log.e( + "[Assistant] [Phone Account Creation] Error [$result] setting the phone number: ${phoneNumber.value} with prefix: ${prefix.value}" + ) + phoneNumberError.value = result.name + return + } + Log.i("[Assistant] [Phone Account Creation] Phone number is ${accountCreator.phoneNumber}") if (useUsername.value == true) { accountCreator.username = username.value @@ -199,14 +217,14 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh } override fun onFlexiApiTokenRequestError() { - Log.e("[Phone Account Creation] Failed to get an auth token from FlexiAPI") + Log.e("[Assistant] [Phone Account Creation] Failed to get an auth token from FlexiAPI") waitForServerAnswer.value = false onErrorEvent.value = Event("Error: Failed to get an auth token from account manager server") } private fun checkUsername() { val status = accountCreator.isAccountExist - Log.i("[Phone Account Creation] isAccountExist returned $status") + Log.i("[Assistant] [Phone Account Creation] isAccountExist returned $status") if (status != AccountCreator.Status.RequestOk) { waitForServerAnswer.value = false onErrorEvent.value = Event("Error: ${status.name}") @@ -215,7 +233,7 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh private fun checkPhoneNumber() { val status = accountCreator.isAliasUsed - Log.i("[Phone Account Creation] isAliasUsed returned $status") + Log.i("[Assistant] [Phone Account Creation] isAliasUsed returned $status") if (status != AccountCreator.Status.RequestOk) { waitForServerAnswer.value = false onErrorEvent.value = Event("Error: ${status.name}") @@ -226,11 +244,11 @@ class PhoneAccountCreationViewModel(accountCreator: AccountCreator) : AbstractPh val token = accountCreator.token.orEmpty() if (token.isNotEmpty()) { Log.i( - "[Phone Account Creation] We already have an auth token from FlexiAPI [$token], continue" + "[Assistant] [Phone Account Creation] We already have an auth token from FlexiAPI [$token], continue" ) onFlexiApiTokenReceived() } else { - Log.i("[Phone Account Creation] Requesting an auth token from FlexiAPI") + Log.i("[Assistant] [Phone Account Creation] Requesting an auth token from FlexiAPI") waitForServerAnswer.value = true requestFlexiApiToken() } diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/PhoneAccountLinkingViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/PhoneAccountLinkingViewModel.kt index b38b8e86d..78c11c04e 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/PhoneAccountLinkingViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/PhoneAccountLinkingViewModel.kt @@ -60,12 +60,12 @@ class PhoneAccountLinkingViewModel(accountCreator: AccountCreator) : AbstractPho status: AccountCreator.Status, response: String? ) { - Log.i("[Phone Account Linking] onIsAliasUsed status is $status") + Log.i("[Assistant] [Phone Account Linking] onIsAliasUsed status is $status") when (status) { AccountCreator.Status.AliasNotExist -> { if (creator.linkAccount() != AccountCreator.Status.RequestOk) { - Log.e("[Phone Account Linking] linkAccount status is $status") + Log.e("[Assistant] [Phone Account Linking] linkAccount status is $status") waitForServerAnswer.value = false onErrorEvent.value = Event("Error: ${status.name}") } @@ -86,7 +86,7 @@ class PhoneAccountLinkingViewModel(accountCreator: AccountCreator) : AbstractPho status: AccountCreator.Status, response: String? ) { - Log.i("[Phone Account Linking] onLinkAccount status is $status") + Log.i("[Assistant] [Phone Account Linking] onLinkAccount status is $status") waitForServerAnswer.value = false when (status) { @@ -113,6 +113,9 @@ class PhoneAccountLinkingViewModel(accountCreator: AccountCreator) : AbstractPho linkEnabled.addSource(phoneNumberError) { linkEnabled.value = isLinkButtonEnabled() } + linkEnabled.addSource(prefixError) { + linkEnabled.value = isLinkButtonEnabled() + } } override fun onCleared() { @@ -123,10 +126,10 @@ class PhoneAccountLinkingViewModel(accountCreator: AccountCreator) : AbstractPho override fun onFlexiApiTokenReceived() { accountCreator.setPhoneNumber(phoneNumber.value, prefix.value) accountCreator.username = username.value - Log.i("[Phone Account Linking] Phone number is ${accountCreator.phoneNumber}") + Log.i("[Assistant] [Phone Account Linking] Phone number is ${accountCreator.phoneNumber}") val status: AccountCreator.Status = accountCreator.isAliasUsed - Log.i("[Phone Account Linking] isAliasUsed returned $status") + Log.i("[Assistant] [Phone Account Linking] isAliasUsed returned $status") if (status != AccountCreator.Status.RequestOk) { waitForServerAnswer.value = false onErrorEvent.value = Event("Error: ${status.name}") @@ -134,12 +137,12 @@ class PhoneAccountLinkingViewModel(accountCreator: AccountCreator) : AbstractPho } override fun onFlexiApiTokenRequestError() { - Log.e("[Phone Account Linking] Failed to get an auth token from FlexiAPI") + Log.e("[Assistant] [Phone Account Linking] Failed to get an auth token from FlexiAPI") waitForServerAnswer.value = false } fun link() { - Log.i("[Phone Account Linking] Requesting an auth token from FlexiAPI") + Log.i("[Assistant] [Phone Account Linking] Requesting an auth token from FlexiAPI") waitForServerAnswer.value = true requestFlexiApiToken() } diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/QrCodeViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/QrCodeViewModel.kt index b5daaec35..c0f988d0f 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/QrCodeViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/QrCodeViewModel.kt @@ -34,7 +34,7 @@ class QrCodeViewModel : ViewModel() { private val listener = object : CoreListenerStub() { override fun onQrcodeFound(core: Core, result: String?) { - Log.i("[QR Code] Found [$result]") + Log.i("[Assistant] [QR Code] Found [$result]") if (result != null) qrCodeFoundEvent.postValue(Event(result)) } } @@ -54,7 +54,7 @@ class QrCodeViewModel : ViewModel() { for (camera in coreContext.core.videoDevicesList) { if (camera.contains("Back")) { - Log.i("[QR Code] Found back facing camera: $camera") + Log.i("[Assistant] [QR Code] Found back facing camera: $camera") coreContext.core.videoDevice = camera return } @@ -62,7 +62,7 @@ class QrCodeViewModel : ViewModel() { val first = coreContext.core.videoDevicesList.firstOrNull() if (first != null) { - Log.i("[QR Code] Using first camera found: $first") + Log.i("[Assistant] [QR Code] Using first camera found: $first") coreContext.core.videoDevice = first } } diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/RemoteProvisioningViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/RemoteProvisioningViewModel.kt index b4ec77e13..e137d975e 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/RemoteProvisioningViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/RemoteProvisioningViewModel.kt @@ -73,7 +73,7 @@ class RemoteProvisioningViewModel : ViewModel() { fun fetchAndApply() { val url = urlToFetch.value.orEmpty() coreContext.core.provisioningUri = url - Log.w("[Remote Provisioning] Url set to [$url], restarting Core") + Log.w("[Assistant] [Remote Provisioning] Url set to [$url], restarting Core") fetchInProgress.value = true coreContext.core.stop() coreContext.core.start() diff --git a/app/src/main/java/org/linphone/utils/DataBindingUtils.kt b/app/src/main/java/org/linphone/utils/DataBindingUtils.kt index 2da1b8759..0b3f8f8b3 100644 --- a/app/src/main/java/org/linphone/utils/DataBindingUtils.kt +++ b/app/src/main/java/org/linphone/utils/DataBindingUtils.kt @@ -593,7 +593,17 @@ fun addPhoneNumberEditTextValidation(editText: EditText, enabled: Boolean) { fun addPrefixEditTextValidation(editText: EditText, enabled: Boolean) { if (!enabled) return editText.addTextChangedListener(object : TextWatcher { - override fun afterTextChanged(s: Editable?) {} + override fun afterTextChanged(s: Editable?) { + val dialPlan = PhoneNumberUtils.getDialPlanFromCountryCallingPrefix( + s.toString().substring(1) + ) + if (dialPlan == null) { + editText.error = + editText.context.getString( + R.string.assistant_error_invalid_international_prefix + ) + } + } override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} diff --git a/app/src/main/res/layout/assistant_account_login_fragment.xml b/app/src/main/res/layout/assistant_account_login_fragment.xml index f1b69fd8f..b6051be74 100644 --- a/app/src/main/res/layout/assistant_account_login_fragment.xml +++ b/app/src/main/res/layout/assistant_account_login_fragment.xml @@ -119,6 +119,7 @@ Change la visibilité du selectionneur d\'emoji Permission requise pour afficher les appels entrant non accordée Afficher + Préfixe international inconnu \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5958d297f..b99e5e090 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -422,6 +422,7 @@ Email address is invalid Username has too many characters Account does not exist or password does not match + Wrong international prefix Use your &appName; account