Fixed chat room information not refreshing
This commit is contained in:
parent
a2a98f90d5
commit
6fa0b96cc0
13 changed files with 86 additions and 105 deletions
|
@ -27,12 +27,9 @@ import org.linphone.core.*
|
||||||
import org.linphone.utils.LinphoneUtils
|
import org.linphone.utils.LinphoneUtils
|
||||||
|
|
||||||
class ChatRoomCreationContactData(private val searchResult: SearchResult) : ContactDataInterface {
|
class ChatRoomCreationContactData(private val searchResult: SearchResult) : ContactDataInterface {
|
||||||
override val contact = MutableLiveData<Contact>()
|
override val contact: MutableLiveData<Contact> = MutableLiveData<Contact>()
|
||||||
|
override val displayName: MutableLiveData<String> = MutableLiveData<String>()
|
||||||
override val displayName: String by lazy {
|
override val securityLevel: MutableLiveData<ChatRoomSecurityLevel> = MutableLiveData<ChatRoomSecurityLevel>()
|
||||||
val address = searchResult.address
|
|
||||||
searchResult.friend?.name ?: if (address != null) LinphoneUtils.getDisplayName(address) else searchResult.phoneNumber.orEmpty()
|
|
||||||
}
|
|
||||||
|
|
||||||
val isDisabled: MutableLiveData<Boolean> by lazy {
|
val isDisabled: MutableLiveData<Boolean> by lazy {
|
||||||
MutableLiveData<Boolean>()
|
MutableLiveData<Boolean>()
|
||||||
|
@ -67,8 +64,10 @@ class ChatRoomCreationContactData(private val searchResult: SearchResult) : Cont
|
||||||
val address = searchResult.address
|
val address = searchResult.address
|
||||||
if (address != null) {
|
if (address != null) {
|
||||||
contact.value = coreContext.contactsManager.findContactByAddress(address)
|
contact.value = coreContext.contactsManager.findContactByAddress(address)
|
||||||
|
displayName.value = searchResult.friend?.name ?: LinphoneUtils.getDisplayName(address)
|
||||||
} else if (searchResult.phoneNumber != null) {
|
} else if (searchResult.phoneNumber != null) {
|
||||||
contact.value = coreContext.contactsManager.findContactByPhoneNumber(searchResult.phoneNumber.orEmpty())
|
contact.value = coreContext.contactsManager.findContactByPhoneNumber(searchResult.phoneNumber.orEmpty())
|
||||||
|
displayName.value = searchResult.friend?.name ?: searchResult.phoneNumber.orEmpty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,6 @@ import org.linphone.core.Participant
|
||||||
import org.linphone.utils.LinphoneUtils
|
import org.linphone.utils.LinphoneUtils
|
||||||
|
|
||||||
class DevicesListGroupData(private val participant: Participant) : GenericContactData(participant.address) {
|
class DevicesListGroupData(private val participant: Participant) : GenericContactData(participant.address) {
|
||||||
override val securityLevel: ChatRoomSecurityLevel
|
|
||||||
get() = participant.securityLevel
|
|
||||||
|
|
||||||
private val device = if (participant.devices.isEmpty()) null else participant.devices.first()
|
private val device = if (participant.devices.isEmpty()) null else participant.devices.first()
|
||||||
|
|
||||||
val securityLevelIcon: Int by lazy {
|
val securityLevelIcon: Int by lazy {
|
||||||
|
@ -56,6 +53,7 @@ class DevicesListGroupData(private val participant: Participant) : GenericContac
|
||||||
val devices = MutableLiveData<ArrayList<DevicesListChildData>>()
|
val devices = MutableLiveData<ArrayList<DevicesListChildData>>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
securityLevel.value = participant.securityLevel
|
||||||
isExpanded.value = false
|
isExpanded.value = false
|
||||||
|
|
||||||
val list = arrayListOf<DevicesListChildData>()
|
val list = arrayListOf<DevicesListChildData>()
|
||||||
|
|
|
@ -50,7 +50,7 @@ class EventData(private val eventLog: EventLog) : GenericContactData(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getName(): String {
|
private fun getName(): String {
|
||||||
return contact.value?.fullName ?: displayName
|
return contact.value?.fullName ?: displayName.value ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateEventText() {
|
private fun updateEventText() {
|
||||||
|
|
|
@ -22,13 +22,9 @@ package org.linphone.activities.main.chat.data
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import org.linphone.activities.main.chat.GroupChatRoomMember
|
import org.linphone.activities.main.chat.GroupChatRoomMember
|
||||||
import org.linphone.contact.GenericContactData
|
import org.linphone.contact.GenericContactData
|
||||||
import org.linphone.core.ChatRoomSecurityLevel
|
|
||||||
import org.linphone.utils.LinphoneUtils
|
import org.linphone.utils.LinphoneUtils
|
||||||
|
|
||||||
class GroupInfoParticipantData(val participant: GroupChatRoomMember) : GenericContactData(participant.address) {
|
class GroupInfoParticipantData(val participant: GroupChatRoomMember) : GenericContactData(participant.address) {
|
||||||
override val securityLevel: ChatRoomSecurityLevel
|
|
||||||
get() = participant.securityLevel
|
|
||||||
|
|
||||||
val sipUri: String get() = LinphoneUtils.getDisplayableAddress(participant.address)
|
val sipUri: String get() = LinphoneUtils.getDisplayableAddress(participant.address)
|
||||||
|
|
||||||
val isAdmin = MutableLiveData<Boolean>()
|
val isAdmin = MutableLiveData<Boolean>()
|
||||||
|
@ -39,6 +35,7 @@ class GroupInfoParticipantData(val participant: GroupChatRoomMember) : GenericCo
|
||||||
val canBeSetAdmin = MutableLiveData<Boolean>()
|
val canBeSetAdmin = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
securityLevel.value = participant.securityLevel
|
||||||
isAdmin.value = participant.isAdmin
|
isAdmin.value = participant.isAdmin
|
||||||
showAdminControls.value = false
|
showAdminControls.value = false
|
||||||
canBeSetAdmin.value = participant.canBeSetAdmin
|
canBeSetAdmin.value = participant.canBeSetAdmin
|
||||||
|
|
|
@ -43,21 +43,9 @@ class ChatRoomViewModelFactory(private val chatRoom: ChatRoom) :
|
||||||
}
|
}
|
||||||
|
|
||||||
class ChatRoomViewModel(val chatRoom: ChatRoom) : ViewModel(), ContactDataInterface {
|
class ChatRoomViewModel(val chatRoom: ChatRoom) : ViewModel(), ContactDataInterface {
|
||||||
override val contact = MutableLiveData<Contact>()
|
override val contact: MutableLiveData<Contact> = MutableLiveData<Contact>()
|
||||||
|
override val displayName: MutableLiveData<String> = MutableLiveData<String>()
|
||||||
override val displayName: String = when {
|
override val securityLevel: MutableLiveData<ChatRoomSecurityLevel> = MutableLiveData<ChatRoomSecurityLevel>()
|
||||||
chatRoom.hasCapability(ChatRoomCapabilities.Basic.toInt()) -> LinphoneUtils.getDisplayName(
|
|
||||||
chatRoom.peerAddress
|
|
||||||
)
|
|
||||||
chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()) -> LinphoneUtils.getDisplayName(
|
|
||||||
chatRoom.participants.firstOrNull()?.address ?: chatRoom.peerAddress
|
|
||||||
)
|
|
||||||
chatRoom.hasCapability(ChatRoomCapabilities.Conference.toInt()) -> chatRoom.subject.orEmpty()
|
|
||||||
else -> chatRoom.peerAddress.asStringUriOnly()
|
|
||||||
}
|
|
||||||
|
|
||||||
override val securityLevel: ChatRoomSecurityLevel = chatRoom.securityLevel
|
|
||||||
|
|
||||||
override val showGroupChatAvatar: Boolean = chatRoom.hasCapability(ChatRoomCapabilities.Conference.toInt()) &&
|
override val showGroupChatAvatar: Boolean = chatRoom.hasCapability(ChatRoomCapabilities.Conference.toInt()) &&
|
||||||
!chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())
|
!chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())
|
||||||
|
|
||||||
|
@ -219,6 +207,17 @@ class ChatRoomViewModel(val chatRoom: ChatRoom) : ViewModel(), ContactDataInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
fun contactLookup() {
|
fun contactLookup() {
|
||||||
|
displayName.value = when {
|
||||||
|
chatRoom.hasCapability(ChatRoomCapabilities.Basic.toInt()) -> LinphoneUtils.getDisplayName(
|
||||||
|
chatRoom.peerAddress
|
||||||
|
)
|
||||||
|
chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()) -> LinphoneUtils.getDisplayName(
|
||||||
|
chatRoom.participants.firstOrNull()?.address ?: chatRoom.peerAddress
|
||||||
|
)
|
||||||
|
chatRoom.hasCapability(ChatRoomCapabilities.Conference.toInt()) -> chatRoom.subject.orEmpty()
|
||||||
|
else -> chatRoom.peerAddress.asStringUriOnly()
|
||||||
|
}
|
||||||
|
|
||||||
if (chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
|
if (chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
|
||||||
searchMatchingContact()
|
searchMatchingContact()
|
||||||
} else {
|
} else {
|
||||||
|
@ -280,6 +279,8 @@ class ChatRoomViewModel(val chatRoom: ChatRoom) : ViewModel(), ContactDataInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSecurityIcon() {
|
private fun updateSecurityIcon() {
|
||||||
|
securityLevel.value = chatRoom.securityLevel
|
||||||
|
|
||||||
securityLevelIcon.value = when (chatRoom.securityLevel) {
|
securityLevelIcon.value = when (chatRoom.securityLevel) {
|
||||||
ChatRoomSecurityLevel.Safe -> R.drawable.security_2_indicator
|
ChatRoomSecurityLevel.Safe -> R.drawable.security_2_indicator
|
||||||
ChatRoomSecurityLevel.Encrypted -> R.drawable.security_1_indicator
|
ChatRoomSecurityLevel.Encrypted -> R.drawable.security_1_indicator
|
||||||
|
|
|
@ -99,17 +99,17 @@ class ContactsListAdapter(
|
||||||
override fun displayHeaderForPosition(position: Int): Boolean {
|
override fun displayHeaderForPosition(position: Int): Boolean {
|
||||||
if (position >= itemCount) return false
|
if (position >= itemCount) return false
|
||||||
val contact = getItem(position)
|
val contact = getItem(position)
|
||||||
val firstLetter = contact.displayName.first().toString()
|
val firstLetter = contact.name.first().toString()
|
||||||
val previousPosition = position - 1
|
val previousPosition = position - 1
|
||||||
return if (previousPosition >= 0) {
|
return if (previousPosition >= 0) {
|
||||||
val previousItemFirstLetter = getItem(previousPosition).displayName.first().toString()
|
val previousItemFirstLetter = getItem(previousPosition).name.first().toString()
|
||||||
previousItemFirstLetter != firstLetter
|
previousItemFirstLetter != firstLetter
|
||||||
} else true
|
} else true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getHeaderViewForPosition(context: Context, position: Int): View {
|
override fun getHeaderViewForPosition(context: Context, position: Int): View {
|
||||||
val contact = getItem(position)
|
val contact = getItem(position)
|
||||||
val firstLetter = AppUtils.getInitials(contact.displayName, 1)
|
val firstLetter = AppUtils.getInitials(contact.name, 1)
|
||||||
val binding: GenericListHeaderBinding = DataBindingUtil.inflate(
|
val binding: GenericListHeaderBinding = DataBindingUtil.inflate(
|
||||||
LayoutInflater.from(context),
|
LayoutInflater.from(context),
|
||||||
R.layout.generic_list_header, null, false
|
R.layout.generic_list_header, null, false
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||||
import org.linphone.activities.main.contact.data.NumberOrAddressEditorData
|
import org.linphone.activities.main.contact.data.NumberOrAddressEditorData
|
||||||
import org.linphone.contact.*
|
import org.linphone.contact.*
|
||||||
|
import org.linphone.core.ChatRoomSecurityLevel
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.utils.ImageUtils
|
import org.linphone.utils.ImageUtils
|
||||||
import org.linphone.utils.PermissionHelper
|
import org.linphone.utils.PermissionHelper
|
||||||
|
@ -45,10 +46,9 @@ class ContactEditorViewModelFactory(private val contact: Contact?) :
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContactEditorViewModel(val c: Contact?) : ViewModel(), ContactDataInterface {
|
class ContactEditorViewModel(val c: Contact?) : ViewModel(), ContactDataInterface {
|
||||||
override val contact = MutableLiveData<Contact>()
|
override val contact: MutableLiveData<Contact> = MutableLiveData<Contact>()
|
||||||
|
override val displayName: MutableLiveData<String> = MutableLiveData<String>()
|
||||||
override val displayName: String
|
override val securityLevel: MutableLiveData<ChatRoomSecurityLevel> = MutableLiveData<ChatRoomSecurityLevel>()
|
||||||
get() = if (c == null) "" else c.fullName ?: c.firstName + " " + c.lastName
|
|
||||||
|
|
||||||
val firstName = MutableLiveData<String>()
|
val firstName = MutableLiveData<String>()
|
||||||
|
|
||||||
|
@ -69,7 +69,12 @@ class ContactEditorViewModel(val c: Contact?) : ViewModel(), ContactDataInterfac
|
||||||
var syncAccountType: String? = null
|
var syncAccountType: String? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (c != null) contact.value = c!!
|
if (c != null) {
|
||||||
|
contact.value = c!!
|
||||||
|
displayName.value = c.fullName ?: c.firstName + " " + c.lastName
|
||||||
|
} else {
|
||||||
|
displayName.value = ""
|
||||||
|
}
|
||||||
firstName.value = c?.firstName ?: ""
|
firstName.value = c?.firstName ?: ""
|
||||||
lastName.value = c?.lastName ?: ""
|
lastName.value = c?.lastName ?: ""
|
||||||
organization.value = c?.organization ?: ""
|
organization.value = c?.organization ?: ""
|
||||||
|
|
|
@ -49,11 +49,12 @@ class ContactViewModelFactory(private val contact: Contact) :
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContactViewModel(val contactInternal: Contact) : ErrorReportingViewModel(), ContactDataInterface {
|
class ContactViewModel(val contactInternal: Contact) : ErrorReportingViewModel(), ContactDataInterface {
|
||||||
override val contact = MutableLiveData<Contact>()
|
override val contact: MutableLiveData<Contact> = MutableLiveData<Contact>()
|
||||||
|
override val displayName: MutableLiveData<String> = MutableLiveData<String>()
|
||||||
|
override val securityLevel: MutableLiveData<ChatRoomSecurityLevel> = MutableLiveData<ChatRoomSecurityLevel>()
|
||||||
|
|
||||||
override val displayName: String by lazy {
|
val name: String
|
||||||
contactInternal.fullName ?: contactInternal.firstName + " " + contactInternal.lastName
|
get() = displayName.value ?: ""
|
||||||
}
|
|
||||||
|
|
||||||
val displayOrganization = corePreferences.displayOrganization
|
val displayOrganization = corePreferences.displayOrganization
|
||||||
|
|
||||||
|
@ -125,6 +126,8 @@ class ContactViewModel(val contactInternal: Contact) : ErrorReportingViewModel()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
contact.value = contactInternal
|
contact.value = contactInternal
|
||||||
|
displayName.value = contactInternal.fullName ?: contactInternal.firstName + " " + contactInternal.lastName
|
||||||
|
|
||||||
updateNumbersAndAddresses(contactInternal)
|
updateNumbersAndAddresses(contactInternal)
|
||||||
coreContext.contactsManager.addListener(contactsUpdatedListener)
|
coreContext.contactsManager.addListener(contactsUpdatedListener)
|
||||||
waitForChatRoomCreation.value = false
|
waitForChatRoomCreation.value = false
|
||||||
|
|
|
@ -74,7 +74,7 @@ class ContactsListViewModel : ViewModel() {
|
||||||
val filterValue = filter.value.orEmpty()
|
val filterValue = filter.value.orEmpty()
|
||||||
list = if (filterValue.isNotEmpty()) {
|
list = if (filterValue.isNotEmpty()) {
|
||||||
getSelectedContactsList().filter { contact ->
|
getSelectedContactsList().filter { contact ->
|
||||||
contact.displayName.contains(filterValue, true) ?: false
|
contact.name.contains(filterValue, true)
|
||||||
} as ArrayList<ContactViewModel>
|
} as ArrayList<ContactViewModel>
|
||||||
} else {
|
} else {
|
||||||
getSelectedContactsList()
|
getSelectedContactsList()
|
||||||
|
|
|
@ -62,7 +62,7 @@ class BigContactAvatarView : LinearLayout {
|
||||||
val initials = if (contact != null) {
|
val initials = if (contact != null) {
|
||||||
AppUtils.getInitials(contact.fullName ?: contact.firstName + " " + contact.lastName)
|
AppUtils.getInitials(contact.fullName ?: contact.firstName + " " + contact.lastName)
|
||||||
} else {
|
} else {
|
||||||
AppUtils.getInitials(viewModel.displayName)
|
AppUtils.getInitials(viewModel.displayName.value ?: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.initials = initials
|
binding.initials = initials
|
||||||
|
|
|
@ -56,7 +56,7 @@ class ContactAvatarView : LinearLayout {
|
||||||
val initials = if (contact != null) {
|
val initials = if (contact != null) {
|
||||||
AppUtils.getInitials(contact.fullName ?: contact.firstName + " " + contact.lastName)
|
AppUtils.getInitials(contact.fullName ?: contact.firstName + " " + contact.lastName)
|
||||||
} else {
|
} else {
|
||||||
AppUtils.getInitials(data.displayName)
|
AppUtils.getInitials(data.displayName.value ?: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.initials = initials
|
binding.initials = initials
|
||||||
|
@ -66,12 +66,12 @@ class ContactAvatarView : LinearLayout {
|
||||||
binding.imagePath = contact?.getContactThumbnailPictureUri()
|
binding.imagePath = contact?.getContactThumbnailPictureUri()
|
||||||
binding.borderVisibility = corePreferences.showBorderOnContactAvatar
|
binding.borderVisibility = corePreferences.showBorderOnContactAvatar
|
||||||
|
|
||||||
binding.securityIcon = when (data.securityLevel) {
|
binding.securityIcon = when (data.securityLevel.value) {
|
||||||
ChatRoomSecurityLevel.Safe -> R.drawable.security_2_indicator
|
ChatRoomSecurityLevel.Safe -> R.drawable.security_2_indicator
|
||||||
ChatRoomSecurityLevel.Encrypted -> R.drawable.security_1_indicator
|
ChatRoomSecurityLevel.Encrypted -> R.drawable.security_1_indicator
|
||||||
else -> R.drawable.security_alert_indicator
|
else -> R.drawable.security_alert_indicator
|
||||||
}
|
}
|
||||||
binding.securityContentDescription = when (data.securityLevel) {
|
binding.securityContentDescription = when (data.securityLevel.value) {
|
||||||
ChatRoomSecurityLevel.Safe -> R.string.content_description_security_level_safe
|
ChatRoomSecurityLevel.Safe -> R.string.content_description_security_level_safe
|
||||||
ChatRoomSecurityLevel.Encrypted -> R.string.content_description_security_level_encrypted
|
ChatRoomSecurityLevel.Encrypted -> R.string.content_description_security_level_encrypted
|
||||||
else -> R.string.content_description_security_level_unsafe
|
else -> R.string.content_description_security_level_unsafe
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.linphone.contact
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import org.linphone.LinphoneApplication
|
import org.linphone.LinphoneApplication
|
||||||
|
import org.linphone.activities.main.viewmodels.ErrorReportingViewModel
|
||||||
import org.linphone.core.Address
|
import org.linphone.core.Address
|
||||||
import org.linphone.core.ChatRoomSecurityLevel
|
import org.linphone.core.ChatRoomSecurityLevel
|
||||||
import org.linphone.utils.LinphoneUtils
|
import org.linphone.utils.LinphoneUtils
|
||||||
|
@ -28,19 +29,18 @@ import org.linphone.utils.LinphoneUtils
|
||||||
interface ContactDataInterface {
|
interface ContactDataInterface {
|
||||||
val contact: MutableLiveData<Contact>
|
val contact: MutableLiveData<Contact>
|
||||||
|
|
||||||
val displayName: String
|
val displayName: MutableLiveData<String>
|
||||||
|
|
||||||
val securityLevel: ChatRoomSecurityLevel
|
val securityLevel: MutableLiveData<ChatRoomSecurityLevel>
|
||||||
get() = ChatRoomSecurityLevel.ClearText
|
|
||||||
|
|
||||||
val showGroupChatAvatar: Boolean
|
val showGroupChatAvatar: Boolean
|
||||||
get() = false
|
get() = false
|
||||||
}
|
}
|
||||||
|
|
||||||
open class GenericContactData(private val sipAddress: Address) : ContactDataInterface {
|
open class GenericContactData(private val sipAddress: Address) : ContactDataInterface {
|
||||||
override val displayName: String = LinphoneUtils.getDisplayName(sipAddress)
|
final override val contact: MutableLiveData<Contact> = MutableLiveData<Contact>()
|
||||||
|
final override val displayName: MutableLiveData<String> = MutableLiveData<String>()
|
||||||
override val contact = MutableLiveData<Contact>()
|
final override val securityLevel: MutableLiveData<ChatRoomSecurityLevel> = MutableLiveData<ChatRoomSecurityLevel>()
|
||||||
|
|
||||||
private val contactsUpdatedListener = object : ContactsUpdatedListenerStub() {
|
private val contactsUpdatedListener = object : ContactsUpdatedListenerStub() {
|
||||||
override fun onContactUpdated(contact: Contact) {
|
override fun onContactUpdated(contact: Contact) {
|
||||||
|
@ -49,6 +49,7 @@ open class GenericContactData(private val sipAddress: Address) : ContactDataInte
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
securityLevel.value = ChatRoomSecurityLevel.ClearText
|
||||||
LinphoneApplication.coreContext.contactsManager.addListener(contactsUpdatedListener)
|
LinphoneApplication.coreContext.contactsManager.addListener(contactsUpdatedListener)
|
||||||
contactLookup()
|
contactLookup()
|
||||||
}
|
}
|
||||||
|
@ -58,6 +59,36 @@ open class GenericContactData(private val sipAddress: Address) : ContactDataInte
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun contactLookup() {
|
private fun contactLookup() {
|
||||||
|
displayName.value = LinphoneUtils.getDisplayName(sipAddress)
|
||||||
|
contact.value = LinphoneApplication.coreContext.contactsManager.findContactByAddress(sipAddress)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class GenericContactViewModel(private val sipAddress: Address) : ErrorReportingViewModel(), ContactDataInterface {
|
||||||
|
final override val contact: MutableLiveData<Contact> = MutableLiveData<Contact>()
|
||||||
|
final override val displayName: MutableLiveData<String> = MutableLiveData<String>()
|
||||||
|
final override val securityLevel: MutableLiveData<ChatRoomSecurityLevel> = MutableLiveData<ChatRoomSecurityLevel>()
|
||||||
|
|
||||||
|
private val contactsUpdatedListener = object : ContactsUpdatedListenerStub() {
|
||||||
|
override fun onContactUpdated(contact: Contact) {
|
||||||
|
contactLookup()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
securityLevel.value = ChatRoomSecurityLevel.ClearText
|
||||||
|
LinphoneApplication.coreContext.contactsManager.addListener(contactsUpdatedListener)
|
||||||
|
contactLookup()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
LinphoneApplication.coreContext.contactsManager.removeListener(contactsUpdatedListener)
|
||||||
|
|
||||||
|
super.onCleared()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun contactLookup() {
|
||||||
|
displayName.value = LinphoneUtils.getDisplayName(sipAddress)
|
||||||
contact.value = LinphoneApplication.coreContext.contactsManager.findContactByAddress(sipAddress)
|
contact.value = LinphoneApplication.coreContext.contactsManager.findContactByAddress(sipAddress)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,53 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2010-2020 Belledonne Communications SARL.
|
|
||||||
*
|
|
||||||
* This file is part of linphone-android
|
|
||||||
* (see https://www.linphone.org).
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package org.linphone.contact
|
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
|
||||||
import org.linphone.activities.main.viewmodels.ErrorReportingViewModel
|
|
||||||
import org.linphone.core.Address
|
|
||||||
import org.linphone.utils.LinphoneUtils
|
|
||||||
|
|
||||||
abstract class GenericContactViewModel(private val sipAddress: Address) : ErrorReportingViewModel(), ContactDataInterface {
|
|
||||||
override val displayName: String = LinphoneUtils.getDisplayName(sipAddress)
|
|
||||||
|
|
||||||
override val contact = MutableLiveData<Contact>()
|
|
||||||
|
|
||||||
private val contactsUpdatedListener = object : ContactsUpdatedListenerStub() {
|
|
||||||
override fun onContactUpdated(contact: Contact) {
|
|
||||||
contactLookup()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
coreContext.contactsManager.addListener(contactsUpdatedListener)
|
|
||||||
contactLookup()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCleared() {
|
|
||||||
coreContext.contactsManager.removeListener(contactsUpdatedListener)
|
|
||||||
|
|
||||||
super.onCleared()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun contactLookup() {
|
|
||||||
contact.value = coreContext.contactsManager.findContactByAddress(sipAddress)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue