diff --git a/app/src/main/java/org/linphone/activities/main/settings/fragments/AccountSettingsFragment.kt b/app/src/main/java/org/linphone/activities/main/settings/fragments/AccountSettingsFragment.kt index 049bdd531..b06648585 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/fragments/AccountSettingsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/fragments/AccountSettingsFragment.kt @@ -98,14 +98,6 @@ class AccountSettingsFragment : GenericSettingFragment>() } - val publishPresenceToggledEvent: MutableLiveData> by lazy { - MutableLiveData>() - } - val displayUsernameInsteadOfIdentity = corePreferences.replaceSipUriByUsername private var accountToDelete: Account? = null @@ -439,16 +435,6 @@ class AccountSettingsViewModel(val account: Account) : GenericSettingsViewModel( } val limeServerUrl = MutableLiveData() - val publishPresenceListener = object : SettingListenerStub() { - override fun onBoolValueChanged(newValue: Boolean) { - val params = account.params.clone() - params.isPublishEnabled = newValue - account.params = params - publishPresenceToggledEvent.value = Event(true) - } - } - val publishPresence = MutableLiveData() - val disableBundleModeListener = object : SettingListenerStub() { override fun onBoolValueChanged(newValue: Boolean) { val params = account.params.clone() @@ -518,7 +504,6 @@ class AccountSettingsViewModel(val account: Account) : GenericSettingsViewModel( limeServerUrl.value = params.limeServerUrl hideLinkPhoneNumber.value = corePreferences.hideLinkPhoneNumber || params.identityAddress?.domain != corePreferences.defaultDomain - publishPresence.value = params.isPublishEnabled disableBundleMode.value = !params.isRtpBundleEnabled } diff --git a/app/src/main/java/org/linphone/activities/main/settings/viewmodels/ContactsSettingsViewModel.kt b/app/src/main/java/org/linphone/activities/main/settings/viewmodels/ContactsSettingsViewModel.kt index 619e15849..0806ab461 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/viewmodels/ContactsSettingsViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/viewmodels/ContactsSettingsViewModel.kt @@ -22,6 +22,8 @@ package org.linphone.activities.main.settings.viewmodels import androidx.lifecycle.MutableLiveData import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.activities.main.settings.SettingListenerStub +import org.linphone.core.ConsolidatedPresence +import org.linphone.core.tools.Log import org.linphone.utils.Event import org.linphone.utils.PermissionHelper @@ -40,6 +42,30 @@ class ContactsSettingsViewModel : GenericSettingsViewModel() { val friendListSubscribe = MutableLiveData() val rlsAddressAvailable = MutableLiveData() + val publishPresenceListener = object : SettingListenerStub() { + override fun onBoolValueChanged(newValue: Boolean) { + prefs.publishPresence = newValue + + if (newValue) { + // Publish online presence when enabling setting + Log.i( + "[Contacts Settings] Presence has been enabled, PUBLISHING presence as Online" + ) + core.consolidatedPresence = ConsolidatedPresence.Online + } else { + // Unpublish presence when disabling setting + Log.i("[Contacts Settings] Presence has been disabled, un-PUBLISHING presence info") + core.consolidatedPresence = ConsolidatedPresence.Offline + } + + publishPresenceToggledEvent.value = Event(true) + } + } + val publishPresence = MutableLiveData() + val publishPresenceToggledEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + val showNewContactAccountDialogListener = object : SettingListenerStub() { override fun onBoolValueChanged(newValue: Boolean) { prefs.showNewContactAccountDialog = newValue @@ -97,6 +123,8 @@ class ContactsSettingsViewModel : GenericSettingsViewModel() { friendListSubscribe.value = core.isFriendListSubscriptionEnabled rlsAddressAvailable.value = !core.config.getString("sip", "rls_uri", "").isNullOrEmpty() + publishPresence.value = prefs.publishPresence + showNewContactAccountDialog.value = prefs.showNewContactAccountDialog nativePresence.value = prefs.storePresenceInNativeContact showOrganization.value = prefs.displayOrganization diff --git a/app/src/main/java/org/linphone/core/CoreContext.kt b/app/src/main/java/org/linphone/core/CoreContext.kt index 202e0c181..4b38f1269 100644 --- a/app/src/main/java/org/linphone/core/CoreContext.kt +++ b/app/src/main/java/org/linphone/core/CoreContext.kt @@ -436,18 +436,22 @@ class CoreContext( } fun onForeground() { - // If presence publish is disabled and we call core.setConsolidatedPresence, it will enabled it! - if (core.defaultAccount?.params?.isPublishEnabled == true) { - Log.i("[Context] App is in foreground, setting consolidated presence to Online") + // We can't rely on defaultAccount?.params?.isPublishEnabled + // as it will be modified by the SDK when changing the presence status + if (corePreferences.publishPresence) { + Log.i("[Context] App is in foreground, PUBLISHING presence as Online") core.consolidatedPresence = ConsolidatedPresence.Online } } fun onBackground() { - // If presence publish is disabled and we call core.setConsolidatedPresence, it will enabled it! - if (core.defaultAccount?.params?.isPublishEnabled == true) { - Log.i("[Context] App is in background, setting consolidated presence to Busy") - core.consolidatedPresence = ConsolidatedPresence.Busy + // We can't rely on defaultAccount?.params?.isPublishEnabled + // as it will be modified by the SDK when changing the presence status + if (corePreferences.publishPresence) { + Log.i("[Context] App is in background, un-PUBLISHING presence info") + // We don't use ConsolidatedPresence.Busy but Offline to do an unsubscribe, + // Flexisip will handle the Busy status depending on other devices + core.consolidatedPresence = ConsolidatedPresence.Offline } } diff --git a/app/src/main/java/org/linphone/core/CorePreferences.kt b/app/src/main/java/org/linphone/core/CorePreferences.kt index 9d88e0a32..51c8e7f6d 100644 --- a/app/src/main/java/org/linphone/core/CorePreferences.kt +++ b/app/src/main/java/org/linphone/core/CorePreferences.kt @@ -280,6 +280,12 @@ class CorePreferences constructor(private val context: Context) { config.setBool("app", "contact_shortcuts", value) } + var publishPresence: Boolean + get() = config.getBool("app", "publish_presence", true) + set(value) { + config.setBool("app", "publish_presence", value) + } + /* Call */ var sendEarlyMedia: Boolean diff --git a/app/src/main/res/layout/settings_account_fragment.xml b/app/src/main/res/layout/settings_account_fragment.xml index af9d48967..44a9c6173 100644 --- a/app/src/main/res/layout/settings_account_fragment.xml +++ b/app/src/main/res/layout/settings_account_fragment.xml @@ -127,12 +127,6 @@ linphone:checked="@={viewModel.isDefault}" linphone:enabled="@{!viewModel.isDefault}"/> - - + +