Show alert when default account is disabled

This commit is contained in:
Sylvain Berfini 2025-04-03 14:52:16 +02:00
parent 43bb680410
commit 32e4a2dbd6
4 changed files with 56 additions and 43 deletions

View file

@ -227,21 +227,6 @@ class MainActivity : GenericActivity() {
} }
} }
viewModel.defaultAccountRegistrationErrorEvent.observe(this) {
it.consume { error ->
val tag = "DEFAULT_ACCOUNT_REGISTRATION_ERROR"
if (error) {
// First remove any already existing connection error toast
removePersistentRedToast(tag)
val message = getString(R.string.default_account_connection_state_error_toast)
showPersistentRedToast(message, R.drawable.warning_circle, tag)
} else {
removePersistentRedToast(tag)
}
}
}
viewModel.showNewAccountToastEvent.observe(this) { viewModel.showNewAccountToastEvent.observe(this) {
it.consume { it.consume {
val message = getString(R.string.new_account_configured_toast) val message = getString(R.string.new_account_configured_toast)

View file

@ -58,8 +58,9 @@ class MainViewModel
const val MWI_MESSAGES_WAITING = 4 const val MWI_MESSAGES_WAITING = 4
const val NON_DEFAULT_ACCOUNT_NOTIFICATIONS = 5 const val NON_DEFAULT_ACCOUNT_NOTIFICATIONS = 5
const val NON_DEFAULT_ACCOUNT_NOT_CONNECTED = 10 const val NON_DEFAULT_ACCOUNT_NOT_CONNECTED = 10
const val FULL_SCREEN_INTENTS_PERMISSION_NOT_GRANTED = 16 const val FULL_SCREEN_INTENTS_PERMISSION_NOT_GRANTED = 14
const val SEND_NOTIFICATIONS_PERMISSION_NOT_GRANTED = 17 const val SEND_NOTIFICATIONS_PERMISSION_NOT_GRANTED = 15
const val DEFAULT_ACCOUNT_DISABLED = 18
const val NETWORK_NOT_REACHABLE = 19 const val NETWORK_NOT_REACHABLE = 19
const val SINGLE_CALL = 20 const val SINGLE_CALL = 20
const val MULTIPLE_CALLS = 21 const val MULTIPLE_CALLS = 21
@ -77,10 +78,6 @@ class MainViewModel
val callsStatus = MutableLiveData<String>() val callsStatus = MutableLiveData<String>()
val defaultAccountRegistrationErrorEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
val goBackToCallEvent: MutableLiveData<Event<Boolean>> by lazy { val goBackToCallEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>() MutableLiveData<Event<Boolean>>()
} }
@ -113,8 +110,6 @@ class MainViewModel
var mainIntentHandled = false var mainIntentHandled = false
private var defaultAccountRegistrationFailed = false
private val alertsList = arrayListOf<Pair<Int, String>>() private val alertsList = arrayListOf<Pair<Int, String>>()
private var firstAccountRegistered: Boolean = false private var firstAccountRegistered: Boolean = false
@ -212,8 +207,10 @@ class MainViewModel
RegistrationState.Failed -> { RegistrationState.Failed -> {
if (account == core.defaultAccount) { if (account == core.defaultAccount) {
Log.e("$TAG Default account registration failed!") Log.e("$TAG Default account registration failed!")
defaultAccountRegistrationFailed = true val label = AppUtils.getString(
defaultAccountRegistrationErrorEvent.postValue(Event(true)) R.string.connection_error_for_non_default_account
)
addAlert(DEFAULT_ACCOUNT_DISABLED, label)
} else if (core.isNetworkReachable) { } else if (core.isNetworkReachable) {
Log.e("$TAG Non-default account registration failed!") Log.e("$TAG Non-default account registration failed!")
val label = AppUtils.getString( val label = AppUtils.getString(
@ -230,11 +227,8 @@ class MainViewModel
} }
if (account == core.defaultAccount) { if (account == core.defaultAccount) {
if (defaultAccountRegistrationFailed) {
Log.i("$TAG Default account is now registered") Log.i("$TAG Default account is now registered")
defaultAccountRegistrationFailed = false removeAlert(DEFAULT_ACCOUNT_DISABLED)
defaultAccountRegistrationErrorEvent.postValue(Event(false))
}
} else { } else {
// If no call and no account is in Failed state, hide top bar // If no call and no account is in Failed state, hide top bar
val found = core.accountList.find { val found = core.accountList.find {
@ -246,12 +240,20 @@ class MainViewModel
} }
} }
RegistrationState.Progress, RegistrationState.Refreshing -> { RegistrationState.Progress, RegistrationState.Refreshing -> {
if (defaultAccountRegistrationFailed) { if (account == core.defaultAccount) {
Log.i( Log.i(
"$TAG Default account is registering, removing registration failed toast for now" "$TAG Default account is registering, removing registration failed alert for now"
) )
defaultAccountRegistrationFailed = false removeAlert(DEFAULT_ACCOUNT_DISABLED)
defaultAccountRegistrationErrorEvent.postValue(Event(false)) }
}
RegistrationState.Cleared -> {
if (account == core.defaultAccount) {
Log.w("$TAG Default account is now disabled")
val label = AppUtils.getString(
R.string.default_account_disabled
)
addAlert(DEFAULT_ACCOUNT_DISABLED, label)
} }
} }
else -> {} else -> {}
@ -271,9 +273,17 @@ class MainViewModel
) )
coreContext.updateFriendListsSubscriptionDependingOnDefaultAccount() coreContext.updateFriendListsSubscriptionDependingOnDefaultAccount()
removeAlert(DEFAULT_ACCOUNT_DISABLED)
removeAlert(NON_DEFAULT_ACCOUNT_NOT_CONNECTED) removeAlert(NON_DEFAULT_ACCOUNT_NOT_CONNECTED)
// Refresh REGISTER to re-compute alerts regarding accounts registration state // Refresh REGISTER to re-compute alerts regarding accounts registration state
core.refreshRegisters() core.refreshRegisters()
if (!account.params.isRegisterEnabled) {
val label = AppUtils.getString(
R.string.default_account_disabled
)
addAlert(DEFAULT_ACCOUNT_DISABLED, label)
}
} }
computeNonDefaultAccountNotificationsCount() computeNonDefaultAccountNotificationsCount()
@ -287,8 +297,11 @@ class MainViewModel
Log.w( Log.w(
"$TAG Account [${account.params.identityAddress?.asStringUriOnly()}] has been removed!" "$TAG Account [${account.params.identityAddress?.asStringUriOnly()}] has been removed!"
) )
removeAlert(DEFAULT_ACCOUNT_DISABLED)
removeAlert(NON_DEFAULT_ACCOUNT_NOT_CONNECTED) removeAlert(NON_DEFAULT_ACCOUNT_NOT_CONNECTED)
// Refresh REGISTER to re-compute alerts regarding accounts registration state
core.refreshRegisters() core.refreshRegisters()
computeNonDefaultAccountNotificationsCount() computeNonDefaultAccountNotificationsCount()
if (core.accountList.isEmpty()) { if (core.accountList.isEmpty()) {
@ -325,7 +338,6 @@ class MainViewModel
} }
init { init {
defaultAccountRegistrationFailed = false
showAlert.value = false showAlert.value = false
atLeastOneCall.value = false atLeastOneCall.value = false
maxAlertLevel.value = NONE maxAlertLevel.value = NONE
@ -348,10 +360,20 @@ class MainViewModel
atLeastOneCall.postValue(true) atLeastOneCall.postValue(true)
} }
if (core.defaultAccount?.state == RegistrationState.Ok && !firstAccountRegistered) { val defaultAccount = core.defaultAccount
if (defaultAccount != null) {
if (!defaultAccount.params.isRegisterEnabled) {
val label = AppUtils.getString(
R.string.default_account_disabled
)
addAlert(DEFAULT_ACCOUNT_DISABLED, label)
}
if (defaultAccount.state == RegistrationState.Ok && !firstAccountRegistered) {
triggerNativeAddressBookImport() triggerNativeAddressBookImport()
} }
} }
}
updateMissingPermissionAlert() updateMissingPermissionAlert()
@ -557,20 +579,24 @@ class MainViewModel
val label = maxedPriorityAlert.second val label = maxedPriorityAlert.second
Log.i("$TAG Max priority alert right now is [$type]") Log.i("$TAG Max priority alert right now is [$type]")
maxAlertLevel.postValue(type) maxAlertLevel.postValue(type)
when (type) { val icon = when (type) {
NON_DEFAULT_ACCOUNT_NOTIFICATIONS, NON_DEFAULT_ACCOUNT_NOT_CONNECTED -> { DEFAULT_ACCOUNT_DISABLED -> {
alertIcon.postValue(R.drawable.bell_simple) R.drawable.warning_circle
} }
NETWORK_NOT_REACHABLE -> { NETWORK_NOT_REACHABLE -> {
alertIcon.postValue(R.drawable.wifi_slash) R.drawable.wifi_slash
} }
SEND_NOTIFICATIONS_PERMISSION_NOT_GRANTED, FULL_SCREEN_INTENTS_PERMISSION_NOT_GRANTED -> { SEND_NOTIFICATIONS_PERMISSION_NOT_GRANTED, FULL_SCREEN_INTENTS_PERMISSION_NOT_GRANTED -> {
alertIcon.postValue(R.drawable.bell_simple_slash) R.drawable.bell_simple_slash
} }
SINGLE_CALL, MULTIPLE_CALLS -> { SINGLE_CALL, MULTIPLE_CALLS -> {
alertIcon.postValue(R.drawable.phone) R.drawable.phone
}
else -> {
R.drawable.bell_simple
} }
} }
alertIcon.postValue(icon)
alertLabel.postValue(label) alertLabel.postValue(label)
if (type < SINGLE_CALL) { if (type < SINGLE_CALL) {

View file

@ -783,6 +783,7 @@
<item quantity="one">%s notification en attente</item> <item quantity="one">%s notification en attente</item>
<item quantity="other">%s notifications en attente</item> <item quantity="other">%s notifications en attente</item>
</plurals> </plurals>
<string name="default_account_disabled">Le compte selectionné est désactivé</string>
<string name="network_not_reachable">Vous n\'êtes pas connecté à internet</string> <string name="network_not_reachable">Vous n\'êtes pas connecté à internet</string>
<string name="network_is_not_wifi">Mode Wi-Fi uniquement activé</string> <string name="network_is_not_wifi">Mode Wi-Fi uniquement activé</string>
<string name="operation_in_progress_overlay">Opération en cours, merci de patienter…</string> <string name="operation_in_progress_overlay">Opération en cours, merci de patienter…</string>

View file

@ -824,6 +824,7 @@
<item quantity="one">%s notification for other account(s)</item> <item quantity="one">%s notification for other account(s)</item>
<item quantity="other">%s notifications for other account(s)</item> <item quantity="other">%s notifications for other account(s)</item>
</plurals> </plurals>
<string name="default_account_disabled">Selected account is currently disabled</string>
<string name="network_not_reachable">You aren\'t connected to internet</string> <string name="network_not_reachable">You aren\'t connected to internet</string>
<string name="network_is_not_wifi">Wi-Fi only mode enabled</string> <string name="network_is_not_wifi">Wi-Fi only mode enabled</string>
<string name="operation_in_progress_overlay">Operation in progress, please wait</string> <string name="operation_in_progress_overlay">Operation in progress, please wait</string>