Changes for how we handle presence in background + updated presence setting & moved it from Accounts to Contacts
This commit is contained in:
parent
8397debb00
commit
76334e03e6
8 changed files with 59 additions and 36 deletions
|
@ -98,14 +98,6 @@ class AccountSettingsFragment : GenericSettingFragment<SettingsAccountFragmentBi
|
|||
}
|
||||
}
|
||||
|
||||
viewModel.publishPresenceToggledEvent.observe(
|
||||
viewLifecycleOwner
|
||||
) {
|
||||
it.consume {
|
||||
sharedViewModel.publishPresenceToggled.value = true
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.deleteAccountRequiredEvent.observe(
|
||||
viewLifecycleOwner
|
||||
) {
|
||||
|
|
|
@ -74,6 +74,14 @@ class ContactsSettingsFragment : GenericSettingFragment<SettingsContactsFragment
|
|||
}
|
||||
}
|
||||
|
||||
viewModel.publishPresenceToggledEvent.observe(
|
||||
viewLifecycleOwner
|
||||
) {
|
||||
it.consume {
|
||||
sharedViewModel.publishPresenceToggled.value = true
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.ldapNewSettingsListener = object : SettingListenerStub() {
|
||||
override fun onClicked() {
|
||||
Log.i("[Contacts Settings] Clicked on new LDAP config")
|
||||
|
|
|
@ -75,10 +75,6 @@ class AccountSettingsViewModel(val account: Account) : GenericSettingsViewModel(
|
|||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
val publishPresenceToggledEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
val displayUsernameInsteadOfIdentity = corePreferences.replaceSipUriByUsername
|
||||
|
||||
private var accountToDelete: Account? = null
|
||||
|
@ -439,16 +435,6 @@ class AccountSettingsViewModel(val account: Account) : GenericSettingsViewModel(
|
|||
}
|
||||
val limeServerUrl = MutableLiveData<String>()
|
||||
|
||||
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<Boolean>()
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Boolean>()
|
||||
val rlsAddressAvailable = MutableLiveData<Boolean>()
|
||||
|
||||
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<Boolean>()
|
||||
val publishPresenceToggledEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -127,12 +127,6 @@
|
|||
linphone:checked="@={viewModel.isDefault}"
|
||||
linphone:enabled="@{!viewModel.isDefault}"/>
|
||||
|
||||
<include
|
||||
layout="@layout/settings_widget_switch"
|
||||
linphone:title="@{@string/account_setting_publish_presence_title}"
|
||||
linphone:listener="@{viewModel.publishPresenceListener}"
|
||||
linphone:checked="@={viewModel.publishPresence}"/>
|
||||
|
||||
<include
|
||||
layout="@layout/settings_widget_basic"
|
||||
linphone:title="@{@string/account_settings_link_phone_number_title}"
|
||||
|
|
|
@ -71,6 +71,12 @@
|
|||
linphone:checked="@={viewModel.friendListSubscribe}"
|
||||
linphone:enabled="@{viewModel.readContactsPermissionGranted && viewModel.rlsAddressAvailable}"/>
|
||||
|
||||
<include
|
||||
layout="@layout/settings_widget_switch"
|
||||
linphone:title="@{@string/account_setting_publish_presence_title}"
|
||||
linphone:listener="@{viewModel.publishPresenceListener}"
|
||||
linphone:checked="@={viewModel.publishPresence}"/>
|
||||
|
||||
<include
|
||||
layout="@layout/settings_widget_switch"
|
||||
linphone:title="@{@string/contacts_settings_show_new_contact_account_dialog_title}"
|
||||
|
|
Loading…
Reference in a new issue