diff --git a/app/src/main/java/org/linphone/ui/assistant/fragment/RegisterFragment.kt b/app/src/main/java/org/linphone/ui/assistant/fragment/RegisterFragment.kt index 6790a7719..c2d72588c 100644 --- a/app/src/main/java/org/linphone/ui/assistant/fragment/RegisterFragment.kt +++ b/app/src/main/java/org/linphone/ui/assistant/fragment/RegisterFragment.kt @@ -100,23 +100,7 @@ class RegisterFragment : GenericFragment() { } binding.setOpenSubscribeWebPageClickListener { - val url = getString(R.string.web_platform_register_email_url) - try { - val browserIntent = Intent(Intent.ACTION_VIEW, url.toUri()) - startActivity(browserIntent) - } catch (ise: IllegalStateException) { - Log.e( - "$TAG Can't start ACTION_VIEW intent for URL [$url], IllegalStateException: $ise" - ) - } catch (anfe: ActivityNotFoundException) { - Log.e( - "$TAG Can't start ACTION_VIEW intent for URL [$url], ActivityNotFoundException: $anfe" - ) - } catch (e: Exception) { - Log.e( - "$TAG Can't start ACTION_VIEW intent for URL [$url]: $e" - ) - } + openSubscribeOnlineWebpage() } binding.username.addTextChangedListener(object : TextWatcher { @@ -152,6 +136,12 @@ class RegisterFragment : GenericFragment() { } } + viewModel.accountCantBeCreatedBySmsEvent.observe(viewLifecycleOwner) { + it.consume { + showPhoneNumberValidationNotAvailableDialog() + } + } + viewModel.goToSmsCodeConfirmationViewEvent.observe(viewLifecycleOwner) { it.consume { Log.i("$TAG Going to SMS code confirmation fragment") @@ -224,4 +214,47 @@ class RegisterFragment : GenericFragment() { dialog.show() } + + private fun openSubscribeOnlineWebpage() { + val url = getString(R.string.web_platform_register_email_url) + try { + val browserIntent = Intent(Intent.ACTION_VIEW, url.toUri()) + startActivity(browserIntent) + } catch (ise: IllegalStateException) { + Log.e( + "$TAG Can't start ACTION_VIEW intent for URL [$url], IllegalStateException: $ise" + ) + } catch (anfe: ActivityNotFoundException) { + Log.e( + "$TAG Can't start ACTION_VIEW intent for URL [$url], ActivityNotFoundException: $anfe" + ) + } catch (e: Exception) { + Log.e( + "$TAG Can't start ACTION_VIEW intent for URL [$url]: $e" + ) + } + } + + private fun showPhoneNumberValidationNotAvailableDialog() { + val model = ConfirmationDialogModel() + val dialog = DialogUtils.getAccountCreationPhoneNumberValidationNotAvailableDialog( + requireActivity(), + model + ) + + model.dismissEvent.observe(viewLifecycleOwner) { + it.consume { + dialog.dismiss() + } + } + + model.confirmEvent.observe(viewLifecycleOwner) { + it.consume { + openSubscribeOnlineWebpage() + dialog.dismiss() + } + } + + dialog.show() + } } diff --git a/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountCreationViewModel.kt b/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountCreationViewModel.kt index 139145f21..19ebe9529 100644 --- a/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountCreationViewModel.kt +++ b/app/src/main/java/org/linphone/ui/assistant/viewmodel/AccountCreationViewModel.kt @@ -108,6 +108,10 @@ class AccountCreationViewModel MutableLiveData() } + val accountCantBeCreatedBySmsEvent: MutableLiveData> by lazy { + MutableLiveData() + } + private var waitingForFlexiApiPushToken = false private var waitForPushJob: Job? = null @@ -166,7 +170,11 @@ class AccountCreationViewModel operationInProgress.postValue(false) if (!errorMessage.isNullOrEmpty()) { - showFormattedRedToast(errorMessage, R.drawable.warning_circle) + if (request.type == AccountManagerServicesRequest.Type.SendPhoneNumberLinkingCodeBySms && statusCode == 422) { + // Do not show error message sent by the account management platform for this specific scenario + } else { + showFormattedRedToast(errorMessage, R.drawable.warning_circle) + } } for (parameter in parameterErrors?.keys.orEmpty()) { @@ -186,6 +194,7 @@ class AccountCreationViewModel waitForPushJob?.cancel() } AccountManagerServicesRequest.Type.SendPhoneNumberLinkingCodeBySms -> { + Log.e("$TAG Error sending SMS code, clearing auth info & account") val authInfo = accountCreatedAuthInfo if (authInfo != null) { coreContext.core.removeAuthInfo(authInfo) @@ -194,6 +203,10 @@ class AccountCreationViewModel if (account != null) { coreContext.core.removeAccount(account) } + + if (statusCode == 422) { + accountCantBeCreatedBySmsEvent.postValue(Event(true)) + } } else -> { } diff --git a/app/src/main/java/org/linphone/utils/DialogUtils.kt b/app/src/main/java/org/linphone/utils/DialogUtils.kt index ffa5a40fa..5c4fa287b 100644 --- a/app/src/main/java/org/linphone/utils/DialogUtils.kt +++ b/app/src/main/java/org/linphone/utils/DialogUtils.kt @@ -66,6 +66,7 @@ import org.linphone.ui.main.contacts.model.ContactTrustDialogModel import org.linphone.ui.main.contacts.model.NumberOrAddressPickerDialogModel import org.linphone.ui.main.model.GroupSetOrEditSubjectDialogModel import androidx.core.graphics.drawable.toDrawable +import org.linphone.databinding.DialogAssistantCreateAccountPhoneNumberValidationNotAvailableBinding import org.linphone.databinding.DialogDeleteChatMessageBinding import org.linphone.databinding.DialogManageAccountOutboundProxyHelpBinding import org.linphone.ui.main.chat.model.MessageDeleteDialogModel @@ -105,6 +106,22 @@ class DialogUtils { return getDialog(context, binding) } + @UiThread + fun getAccountCreationPhoneNumberValidationNotAvailableDialog( + context: Context, + viewModel: ConfirmationDialogModel + ): Dialog { + val binding: DialogAssistantCreateAccountPhoneNumberValidationNotAvailableBinding = DataBindingUtil.inflate( + LayoutInflater.from(context), + R.layout.dialog_assistant_create_account_phone_number_validation_not_available, + null, + false + ) + binding.viewModel = viewModel + + return getDialog(context, binding) + } + @UiThread fun getAccountInternationalPrefixHelpDialog(context: Context): Dialog { val binding: DialogManageAccountInternationalPrefixHelpBinding = DataBindingUtil.inflate( diff --git a/app/src/main/res/layout/dialog_assistant_create_account_phone_number_validation_not_available.xml b/app/src/main/res/layout/dialog_assistant_create_account_phone_number_validation_not_available.xml new file mode 100644 index 000000000..059010a2a --- /dev/null +++ b/app/src/main/res/layout/dialog_assistant_create_account_phone_number_validation_not_available.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 1beca0ede..b2d20ec06 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -108,6 +108,9 @@ En continuant, vous acceptez nos %1$s et %2$s. Confirmez votre numéro de téléphone Êtes-vous sûr que le %s est votre numéro de téléphone ? + Inscription par téléphone indisponible + L\'inscription par numéro de téléphone n\'est pas disponible, veuillez utiliser l\'inscription par adresse email. + S\'inscrire avec un email Connexion Scanner un QR code Ce QR code est invalide ! diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 54bef35ef..acb794950 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -150,6 +150,9 @@ By continuing, you accept our %1$s and %2$s. Confirm phone number Are you sure your phone number is %s? + Phone number validation not available + Phone number validation is not available, please use email account creation process. + Register with an email Login Scan QR code Invalid QR code!