mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
More error info in assistant
This commit is contained in:
parent
8f51de45d0
commit
3832299463
8 changed files with 205 additions and 22 deletions
|
|
@ -57,4 +57,9 @@ lime_update_threshold=86400
|
|||
[alerts]
|
||||
alerts_enabled=1
|
||||
|
||||
[assistant]
|
||||
algorithm=SHA-256
|
||||
password_min_length=6
|
||||
username_regex=^[a-z0-9+_.\-]*$
|
||||
|
||||
## End of factory rc
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import org.linphone.LinphoneApplication.Companion.coreContext
|
|||
import org.linphone.R
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.AssistantRegisterFragmentBinding
|
||||
import org.linphone.ui.assistant.AssistantActivity
|
||||
import org.linphone.ui.assistant.model.ConfirmPhoneNumberDialogModel
|
||||
import org.linphone.ui.assistant.viewmodel.AccountCreationViewModel
|
||||
import org.linphone.utils.DialogUtils
|
||||
|
|
@ -137,6 +138,15 @@ class RegisterFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
viewModel.errorHappenedEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { error ->
|
||||
(requireActivity() as AssistantActivity).showRedToast(
|
||||
error,
|
||||
R.drawable.warning_circle
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
coreContext.postOnCoreThread {
|
||||
val prefix = PhoneNumberUtils.getDeviceInternationalPrefix(requireContext())
|
||||
if (!prefix.isNullOrEmpty()) {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ import org.linphone.LinphoneApplication.Companion.coreContext
|
|||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.R
|
||||
import org.linphone.core.AccountCreator
|
||||
import org.linphone.core.AccountCreator.PhoneNumberStatus
|
||||
import org.linphone.core.AccountCreator.UsernameStatus
|
||||
import org.linphone.core.AccountCreatorListenerStub
|
||||
import org.linphone.core.Core
|
||||
import org.linphone.core.CoreListenerStub
|
||||
|
|
@ -56,6 +58,8 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
|
||||
val password = MutableLiveData<String>()
|
||||
|
||||
val passwordError = MutableLiveData<String>()
|
||||
|
||||
val phoneNumber = MutableLiveData<String>()
|
||||
|
||||
val phoneNumberError = MutableLiveData<String>()
|
||||
|
|
@ -81,6 +85,10 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
|
||||
val goToLoginPageEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
val errorHappenedEvent: MutableLiveData<Event<String>> by lazy {
|
||||
MutableLiveData<Event<String>>()
|
||||
}
|
||||
|
||||
private var waitingForFlexiApiPushToken = false
|
||||
private var waitForPushJob: Job? = null
|
||||
|
||||
|
|
@ -113,8 +121,12 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
Log.e("$TAG An unexpected error occurred!")
|
||||
operationInProgress.postValue(false)
|
||||
createEnabled.postValue(false)
|
||||
// TODO FIXME: use translated string
|
||||
phoneNumberError.postValue(status.name)
|
||||
|
||||
phoneNumberError.postValue(
|
||||
AppUtils.getString(
|
||||
R.string.assistant_account_register_invalid_phone_number_error
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -144,8 +156,12 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
Log.e("$TAG An unexpected error occurred!")
|
||||
operationInProgress.postValue(false)
|
||||
createEnabled.postValue(false)
|
||||
// TODO FIXME: use translated string
|
||||
phoneNumberError.postValue(status.name)
|
||||
|
||||
phoneNumberError.postValue(
|
||||
AppUtils.getString(
|
||||
R.string.assistant_account_register_invalid_phone_number_error
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -166,7 +182,14 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
}
|
||||
else -> {
|
||||
Log.e("$TAG Account couldn't be created, an unexpected error occurred!")
|
||||
// TODO: show error message to user
|
||||
errorHappenedEvent.postValue(
|
||||
Event(
|
||||
AppUtils.getFormattedString(
|
||||
R.string.assistant_account_register_server_error,
|
||||
status.toInt()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -185,7 +208,14 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
goToLoginPageEvent.postValue(Event(true))
|
||||
} else {
|
||||
Log.e("$TAG Account couldn't be activated, an unexpected error occurred!")
|
||||
// TODO: show error message to user
|
||||
errorHappenedEvent.postValue(
|
||||
Event(
|
||||
AppUtils.getFormattedString(
|
||||
R.string.assistant_account_register_server_error,
|
||||
status.toInt()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -282,6 +312,7 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
|
||||
@UiThread
|
||||
fun confirmPhoneNumber() {
|
||||
operationInProgress.value = true
|
||||
coreContext.postOnCoreThread {
|
||||
if (::accountCreator.isInitialized) {
|
||||
val prefix = internationalPrefix.value.orEmpty().trim()
|
||||
|
|
@ -293,7 +324,8 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
val number = phoneNumber.value.orEmpty().trim()
|
||||
|
||||
val status = accountCreator.setPhoneNumber(number, digitsPrefix)
|
||||
if (status == AccountCreator.PhoneNumberStatus.Ok.toInt()) {
|
||||
Log.i("$TAG setPhoneNumber returned $status")
|
||||
if (status == PhoneNumberStatus.Ok.toInt()) {
|
||||
val normalizedPhoneNumber = accountCreator.phoneNumber
|
||||
|
||||
val message = coreContext.context.getString(
|
||||
|
|
@ -322,14 +354,41 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
Log.e(
|
||||
"$TAG Failed to set phone number [$number] and prefix [$digitsPrefix] into account creator!"
|
||||
)
|
||||
val error = AppUtils.getString(
|
||||
R.string.assistant_account_register_invalid_phone_number_error
|
||||
)
|
||||
val error = when (status) {
|
||||
PhoneNumberStatus.Invalid.toInt() -> {
|
||||
AppUtils.getString(
|
||||
R.string.assistant_account_register_invalid_phone_number_error
|
||||
)
|
||||
}
|
||||
PhoneNumberStatus.InvalidCountryCode.toInt() -> {
|
||||
AppUtils.getString(
|
||||
R.string.assistant_account_register_invalid_phone_number_international_prefix_error
|
||||
)
|
||||
}
|
||||
PhoneNumberStatus.TooLong.toInt() -> {
|
||||
AppUtils.getString(
|
||||
R.string.assistant_account_register_invalid_phone_number_too_long_error
|
||||
)
|
||||
}
|
||||
PhoneNumberStatus.TooShort.toInt() -> {
|
||||
AppUtils.getString(
|
||||
R.string.assistant_account_register_invalid_phone_number_too_short_error
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
AppUtils.getString(
|
||||
R.string.assistant_account_register_invalid_phone_number_error
|
||||
)
|
||||
}
|
||||
}
|
||||
phoneNumberError.postValue(error)
|
||||
operationInProgress.postValue(false)
|
||||
}
|
||||
} else {
|
||||
Log.e("$TAG Account creator hasn't been initialized!")
|
||||
// TODO: show error message to user
|
||||
errorHappenedEvent.postValue(
|
||||
Event(AppUtils.getString(R.string.assistant_account_register_unexpected_error))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -373,7 +432,14 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
if (status != AccountCreator.Status.RequestOk) {
|
||||
Log.e("$TAG Can't activate account [$status]")
|
||||
operationInProgress.postValue(false)
|
||||
// TODO: show error message to user
|
||||
errorHappenedEvent.postValue(
|
||||
Event(
|
||||
AppUtils.getFormattedString(
|
||||
R.string.assistant_account_register_server_error,
|
||||
status.toInt()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -383,7 +449,30 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
operationInProgress.postValue(true)
|
||||
|
||||
usernameError.postValue("")
|
||||
accountCreator.username = username.value.orEmpty().trim()
|
||||
val usernameStatus = accountCreator.setUsername(username.value.orEmpty().trim())
|
||||
Log.i("$TAG setUsername returned $usernameStatus")
|
||||
if (usernameStatus != UsernameStatus.Ok) {
|
||||
val error = when (usernameStatus) {
|
||||
UsernameStatus.InvalidCharacters, UsernameStatus.Invalid -> {
|
||||
AppUtils.getString(
|
||||
R.string.assistant_account_register_username_invalid_characters_error
|
||||
)
|
||||
}
|
||||
UsernameStatus.TooShort -> {
|
||||
AppUtils.getString(R.string.assistant_account_register_username_too_short_error)
|
||||
}
|
||||
UsernameStatus.TooLong -> {
|
||||
AppUtils.getString(R.string.assistant_account_register_username_too_long_error)
|
||||
}
|
||||
else -> {
|
||||
AppUtils.getString(R.string.assistant_account_register_username_error)
|
||||
}
|
||||
}
|
||||
usernameError.postValue(error)
|
||||
operationInProgress.postValue(false)
|
||||
return
|
||||
}
|
||||
|
||||
accountCreator.domain = corePreferences.defaultDomain
|
||||
|
||||
val status = accountCreator.isAccountExist
|
||||
|
|
@ -391,7 +480,14 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
if (status != AccountCreator.Status.RequestOk) {
|
||||
Log.e("$TAG Can't check if account already exists [$status]")
|
||||
operationInProgress.postValue(false)
|
||||
// TODO: show error message to user
|
||||
errorHappenedEvent.postValue(
|
||||
Event(
|
||||
AppUtils.getFormattedString(
|
||||
R.string.assistant_account_register_server_error,
|
||||
status.toInt()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -404,7 +500,14 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
if (status != AccountCreator.Status.RequestOk) {
|
||||
Log.e("$TAG Can't check if phone number is already used [$status]")
|
||||
operationInProgress.postValue(false)
|
||||
// TODO: show error message to user
|
||||
errorHappenedEvent.postValue(
|
||||
Event(
|
||||
AppUtils.getFormattedString(
|
||||
R.string.assistant_account_register_server_error,
|
||||
status.toInt()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -412,14 +515,42 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
private fun createAccount() {
|
||||
operationInProgress.postValue(true)
|
||||
|
||||
accountCreator.password = password.value.orEmpty().trim()
|
||||
val status = accountCreator.createAccount()
|
||||
val passwordStatus = accountCreator.setPassword(password.value.orEmpty().trim())
|
||||
Log.i("$TAG setPassword returned $passwordStatus")
|
||||
if (passwordStatus != AccountCreator.PasswordStatus.Ok) {
|
||||
val error = when (passwordStatus) {
|
||||
AccountCreator.PasswordStatus.InvalidCharacters -> {
|
||||
AppUtils.getString(
|
||||
R.string.assistant_account_register_password_invalid_characters_error
|
||||
)
|
||||
}
|
||||
AccountCreator.PasswordStatus.TooShort -> {
|
||||
AppUtils.getString(R.string.assistant_account_register_password_too_short)
|
||||
}
|
||||
AccountCreator.PasswordStatus.TooLong -> {
|
||||
AppUtils.getString(R.string.assistant_account_register_password_too_long_error)
|
||||
}
|
||||
else -> {
|
||||
AppUtils.getString(R.string.assistant_account_register_invalid_password_error)
|
||||
}
|
||||
}
|
||||
passwordError.postValue(error)
|
||||
operationInProgress.postValue(false)
|
||||
}
|
||||
|
||||
val status = accountCreator.createAccount()
|
||||
Log.i("$TAG createAccount returned $status")
|
||||
if (status != AccountCreator.Status.RequestOk) {
|
||||
Log.e("$TAG Can't create account [$status]")
|
||||
operationInProgress.postValue(false)
|
||||
// TODO: show error message to user
|
||||
errorHappenedEvent.postValue(
|
||||
Event(
|
||||
AppUtils.getFormattedString(
|
||||
R.string.assistant_account_register_server_error,
|
||||
status.toInt()
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
Log.i("$TAG createAccount consumed our token, setting it to null")
|
||||
accountCreator.token = null
|
||||
|
|
@ -481,6 +612,12 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
private fun onFlexiApiTokenRequestError() {
|
||||
Log.e("$TAG Flexi API token request by push error!")
|
||||
operationInProgress.postValue(false)
|
||||
// TODO: show error message to user
|
||||
errorHappenedEvent.postValue(
|
||||
Event(
|
||||
AppUtils.getString(
|
||||
R.string.assistant_account_register_push_notification_not_received_error
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,10 +118,12 @@ class ThirdPartySipAccountLoginViewModel @UiThread constructor() : ViewModel() {
|
|||
loginEnabled.value = isLoginButtonEnabled()
|
||||
}
|
||||
|
||||
// TODO: handle formatting errors
|
||||
|
||||
availableTransports.add(UDP)
|
||||
availableTransports.add(TCP)
|
||||
availableTransports.add(TLS)
|
||||
transport.value = UDP
|
||||
transport.value = TLS
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
|
|
|||
|
|
@ -213,6 +213,19 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style_600"
|
||||
android:visibility="@{viewModel.passwordError.length() == 0 ? View.GONE : View.VISIBLE, default=gone}"
|
||||
android:id="@+id/password_error"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@{viewModel.passwordError, default=`Error`}"
|
||||
android:textSize="13sp"
|
||||
android:textColor="@color/red_danger"
|
||||
app:layout_constraintTop_toBottomOf="@id/password"
|
||||
app:layout_constraintStart_toStartOf="@id/password"
|
||||
app:layout_constraintEnd_toEndOf="@id/password"/>
|
||||
|
||||
<ImageView
|
||||
android:onClick="@{() -> viewModel.toggleShowPassword()}"
|
||||
android:id="@+id/eye"
|
||||
|
|
|
|||
|
|
@ -58,9 +58,10 @@
|
|||
android:layout_marginStart="8dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:text="@{message, default=`This call can be trusted`}"
|
||||
android:text="@{message, default=@string/assistant_account_register_push_notification_not_received_error}"
|
||||
android:textSize="14sp"
|
||||
textColor="@{text_color, default=@color/blue_trusted}"
|
||||
app:layout_constraintWidth_max="@dimen/toast_text_max_width"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/toast_icon"
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
<dimen name="in_call_round_corners_texture_view_radius">20dp</dimen>
|
||||
|
||||
<dimen name="toast_max_width">400dp</dimen>
|
||||
<dimen name="toast_text_max_width">300dp</dimen>
|
||||
<dimen name="button_max_width">400dp</dimen>
|
||||
<dimen name="dialog_max_width">400dp</dimen>
|
||||
<dimen name="text_input_max_width">400dp</dimen>
|
||||
|
|
|
|||
|
|
@ -113,8 +113,22 @@
|
|||
<string name="assistant_secure_mode_interoperable_title">Interoperable</string>
|
||||
<string name="assistant_secure_mode_finish_account_login">Continue</string>
|
||||
<string name="assistant_account_register_username_already_in_use_error">This account already exists</string>
|
||||
<string name="assistant_account_register_username_invalid_characters_error">Invalid characters: capital letters and special characters are not allowed</string>
|
||||
<string name="assistant_account_register_username_too_short_error">Username is too short</string>
|
||||
<string name="assistant_account_register_username_too_long_error">Username is too long</string>
|
||||
<string name="assistant_account_register_username_error">Unexpected username error</string>
|
||||
<string name="assistant_account_register_phone_number_already_in_use_error">Phone number already used</string>
|
||||
<string name="assistant_account_register_invalid_phone_number_error">Invalid phone number and/or prefix</string>
|
||||
<string name="assistant_account_register_invalid_phone_number_international_prefix_error">Invalid phone number</string>
|
||||
<string name="assistant_account_register_invalid_phone_number_too_long_error">Phone number is too long</string>
|
||||
<string name="assistant_account_register_invalid_phone_number_too_short_error">Phone number is too short</string>
|
||||
<string name="assistant_account_register_invalid_phone_number_error">Unexpected phone number error</string>
|
||||
<string name="assistant_account_register_password_invalid_characters_error">Invalid characters</string>
|
||||
<string name="assistant_account_register_password_too_short">Password is too short</string>
|
||||
<string name="assistant_account_register_password_too_long_error">Password is too long</string>
|
||||
<string name="assistant_account_register_invalid_password_error">Unexpected password error</string>
|
||||
<string name="assistant_account_register_server_error">Failed to create account, error %i</string>
|
||||
<string name="assistant_account_register_push_notification_not_received_error">Push notification with auth token not received in 5 seconds, please try again later</string>
|
||||
<string name="assistant_account_register_unexpected_error">Unexpected error occurred, please try again later</string>
|
||||
|
||||
<string name="drawer_menu_manage_account">Manage the profile</string>
|
||||
<string name="drawer_menu_account_connection_status_connected">Connected</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue