Fixed some scenario where account(s) reload isn't done

This commit is contained in:
Sylvain Berfini 2025-02-13 14:17:28 +01:00
parent 8c1889b181
commit e292b0d7e8
3 changed files with 29 additions and 17 deletions

View file

@ -28,9 +28,9 @@ import org.linphone.core.Account
import org.linphone.core.Call
import org.linphone.core.ChatMessage
import org.linphone.core.ChatRoom
import org.linphone.core.ConfiguringState
import org.linphone.core.Core
import org.linphone.core.CoreListenerStub
import org.linphone.core.GlobalState
import org.linphone.core.tools.Log
import org.linphone.ui.GenericViewModel
import org.linphone.ui.main.model.AccountModel
@ -139,18 +139,10 @@ open class AbstractMainViewModel
}
@WorkerThread
override fun onConfiguringStatus(core: Core, status: ConfiguringState?, message: String?) {
if (status != ConfiguringState.Skipped) {
account.value?.destroy()
val defaultAccount = core.defaultAccount
if (defaultAccount != null) {
Log.i("$TAG Configuring status is [$status], reload default account")
account.postValue(AccountModel(defaultAccount))
defaultAccountChangedEvent.postValue(Event(true))
} else {
Log.w("$TAG Configuring status is [$status] but no default account was found!")
}
override fun onGlobalStateChanged(core: Core, state: GlobalState?, message: String) {
if (core.globalState == GlobalState.On) {
Log.i("$TAG Global state is [${core.globalState}], reload account info")
configure()
}
}

View file

@ -25,10 +25,16 @@ import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.core.Account
import org.linphone.core.Core
import org.linphone.core.CoreListenerStub
import org.linphone.core.GlobalState
import org.linphone.core.tools.Log
import org.linphone.ui.GenericViewModel
import org.linphone.utils.Event
open class DefaultAccountChangedViewModel : GenericViewModel() {
companion object {
private const val TAG = "[Default Account Changed ViewModel]"
}
val defaultAccountChangedEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
@ -38,6 +44,14 @@ open class DefaultAccountChangedViewModel : GenericViewModel() {
override fun onDefaultAccountChanged(core: Core, account: Account?) {
defaultAccountChangedEvent.postValue(Event(true))
}
@WorkerThread
override fun onGlobalStateChanged(core: Core, state: GlobalState?, message: String) {
if (core.globalState == GlobalState.On) {
Log.i("$TAG Global state is [${core.globalState}], reload default account")
defaultAccountChangedEvent.postValue(Event(true))
}
}
}
init {

View file

@ -26,9 +26,9 @@ import androidx.lifecycle.MutableLiveData
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.core.Account
import org.linphone.core.ConfiguringState
import org.linphone.core.Core
import org.linphone.core.CoreListenerStub
import org.linphone.core.GlobalState
import org.linphone.core.tools.Log
import org.linphone.ui.GenericViewModel
import org.linphone.ui.main.model.AccountModel
@ -109,11 +109,11 @@ class DrawerMenuViewModel
}
@WorkerThread
override fun onConfiguringStatus(core: Core, status: ConfiguringState?, message: String?) {
if (status != ConfiguringState.Skipped) {
override fun onGlobalStateChanged(core: Core, state: GlobalState?, message: String) {
if (core.globalState == GlobalState.On) {
accounts.value.orEmpty().forEach(AccountModel::destroy)
Log.i("$TAG Configuring status is [$status], reload accounts & shortcuts")
Log.i("$TAG Global state is [${core.globalState}], reload accounts & shortcuts")
computeAccountsList()
computeShortcuts()
}
@ -180,6 +180,12 @@ class DrawerMenuViewModel
showAccountPopupMenuEvent.postValue(Event(Pair(view, account)))
}
list.add(model)
if (account == coreContext.core.defaultAccount) {
defaultAccountChangedEvent.postValue(
Event(account.params.identityAddress?.asStringUriOnly() ?: "")
)
}
}
accounts.postValue(list)