mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Generate avatar for conferences based on participants avatar (like for group conversations)
This commit is contained in:
parent
035738f4c5
commit
567ef561c0
8 changed files with 75 additions and 38 deletions
|
|
@ -15,4 +15,6 @@ abstract class AbstractAvatarModel {
|
|||
val forceConferenceIcon = MutableLiveData<Boolean>()
|
||||
|
||||
val defaultToConferenceIcon = MutableLiveData<Boolean>()
|
||||
|
||||
val skipInitials = MutableLiveData<Boolean>()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import androidx.core.graphics.drawable.IconCompat
|
|||
import androidx.loader.app.LoaderManager
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.core.Address
|
||||
import org.linphone.core.ConferenceInfo
|
||||
import org.linphone.core.Core
|
||||
import org.linphone.core.CoreListenerStub
|
||||
import org.linphone.core.Friend
|
||||
|
|
@ -217,6 +218,24 @@ class ContactsManager @UiThread constructor(context: Context) {
|
|||
return avatar
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun getContactAvatarModelForConferenceInfo(conferenceInfo: ConferenceInfo): ContactAvatarModel {
|
||||
// Do not clean parameters!
|
||||
val key = conferenceInfo.uri?.asStringUriOnly()
|
||||
if (key == null) {
|
||||
val fakeFriend = coreContext.core.createFriend()
|
||||
return ContactAvatarModel(fakeFriend)
|
||||
}
|
||||
|
||||
val foundInMap = if (avatarsMap.keys.contains(key)) avatarsMap[key] else null
|
||||
if (foundInMap != null) return foundInMap
|
||||
|
||||
val avatar = LinphoneUtils.getAvatarModelForConferenceInfo(conferenceInfo)
|
||||
avatarsMap[key] = avatar
|
||||
|
||||
return avatar
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun onCoreStarted(core: Core) {
|
||||
core.addListener(coreListener)
|
||||
|
|
|
|||
|
|
@ -57,17 +57,18 @@ class CallModel @WorkerThread constructor(val call: Call) {
|
|||
init {
|
||||
call.addListener(callListener)
|
||||
|
||||
val avatarModel = coreContext.contactsManager.getContactAvatarModelForAddress(
|
||||
call.remoteAddress
|
||||
)
|
||||
val conferenceInfo = coreContext.core.findConferenceInformationFromUri(call.remoteAddress)
|
||||
if (conferenceInfo != null) {
|
||||
displayName.postValue(conferenceInfo.subject)
|
||||
avatarModel.forceConferenceIcon.postValue(true)
|
||||
val avatarModel = if (conferenceInfo != null) {
|
||||
coreContext.contactsManager.getContactAvatarModelForConferenceInfo(conferenceInfo)
|
||||
} else {
|
||||
displayName.postValue(friend?.name ?: LinphoneUtils.getDisplayName(call.remoteAddress))
|
||||
coreContext.contactsManager.getContactAvatarModelForAddress(
|
||||
call.remoteAddress
|
||||
)
|
||||
}
|
||||
contact.postValue(avatarModel)
|
||||
displayName.postValue(
|
||||
avatarModel.friend.name ?: LinphoneUtils.getDisplayName(call.remoteAddress)
|
||||
)
|
||||
|
||||
state.postValue(LinphoneUtils.callStateToString(call.state))
|
||||
isPaused.postValue(LinphoneUtils.isCallPaused(call.state))
|
||||
|
|
|
|||
|
|
@ -781,25 +781,18 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val isDeviceTrusted = updateEncryption()
|
||||
val securityLevel = if (isDeviceTrusted) SecurityLevel.Encrypted else SecurityLevel.Safe
|
||||
val friend = coreContext.contactsManager.findContactByAddress(address)
|
||||
if (friend != null) {
|
||||
displayedName.postValue(friend.name)
|
||||
val model = ContactAvatarModel(friend)
|
||||
model.trust.postValue(securityLevel)
|
||||
contact.postValue(model)
|
||||
|
||||
val conferenceInfo = coreContext.core.findConferenceInformationFromUri(
|
||||
call.remoteAddress
|
||||
)
|
||||
val model = if (conferenceInfo != null) {
|
||||
coreContext.contactsManager.getContactAvatarModelForConferenceInfo(conferenceInfo)
|
||||
} else {
|
||||
val conferenceInfo = coreContext.core.findConferenceInformationFromUri(
|
||||
call.remoteAddress
|
||||
)
|
||||
val fakeFriend = coreContext.core.createFriend()
|
||||
fakeFriend.name = conferenceInfo?.subject ?: LinphoneUtils.getDisplayName(address)
|
||||
fakeFriend.addAddress(address)
|
||||
val model = ContactAvatarModel(fakeFriend)
|
||||
model.forceConferenceIcon.postValue(conferenceInfo != null)
|
||||
model.trust.postValue(securityLevel)
|
||||
contact.postValue(model)
|
||||
displayedName.postValue(fakeFriend.name)
|
||||
coreContext.contactsManager.getContactAvatarModelForAddress(call.remoteAddress)
|
||||
}
|
||||
model.trust.postValue(securityLevel)
|
||||
contact.postValue(model)
|
||||
displayedName.postValue(model.friend.name)
|
||||
|
||||
isRecording.postValue(call.params.isRecording)
|
||||
isRemoteRecordingEvent.postValue(
|
||||
|
|
|
|||
|
|
@ -52,21 +52,23 @@ class CallLogModel @WorkerThread constructor(private val callLog: CallLog) {
|
|||
dateTime.postValue(displayedDate)
|
||||
|
||||
if (callLog.wasConference()) {
|
||||
val fakeFriend = coreContext.core.createFriend()
|
||||
fakeFriend.address = address
|
||||
|
||||
val conferenceInfo = coreContext.core.findConferenceInformationFromUri(address)
|
||||
if (conferenceInfo != null) {
|
||||
fakeFriend.name = conferenceInfo.subject
|
||||
avatarModel = coreContext.contactsManager.getContactAvatarModelForConferenceInfo(
|
||||
conferenceInfo
|
||||
)
|
||||
} else {
|
||||
val fakeFriend = coreContext.core.createFriend()
|
||||
fakeFriend.address = address
|
||||
fakeFriend.name = LinphoneUtils.getDisplayName(address)
|
||||
avatarModel = ContactAvatarModel(fakeFriend)
|
||||
avatarModel.forceConferenceIcon.postValue(true)
|
||||
Log.w(
|
||||
"$TAG Call log was conference but failed to find matching conference info from it's URI!"
|
||||
)
|
||||
}
|
||||
avatarModel = ContactAvatarModel(fakeFriend)
|
||||
|
||||
avatarModel.forceConferenceIcon.postValue(true)
|
||||
friendRefKey = null
|
||||
friendExists = false
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -95,14 +95,6 @@ class ContactHistoryViewModel @UiThread constructor() : ViewModel() {
|
|||
if (callLog != null) {
|
||||
val model = CallLogModel(callLog)
|
||||
address = model.address
|
||||
|
||||
// Check if it is a conference
|
||||
val conferenceInfo = coreContext.core.findConferenceInformationFromUri(address)
|
||||
if (conferenceInfo != null) {
|
||||
model.avatarModel.name.postValue(conferenceInfo.subject)
|
||||
model.avatarModel.forceConferenceIcon.postValue(true)
|
||||
}
|
||||
|
||||
callLogModel.postValue(model)
|
||||
|
||||
val peerAddress = if (callLog.dir == Call.Dir.Outgoing) callLog.toAddress else callLog.fromAddress
|
||||
|
|
@ -119,6 +111,7 @@ class ContactHistoryViewModel @UiThread constructor() : ViewModel() {
|
|||
history.add(historyModel)
|
||||
}
|
||||
historyCallLogs.postValue(history)
|
||||
|
||||
callLogFoundEvent.postValue(Event(true))
|
||||
} else {
|
||||
callLogFoundEvent.postValue(Event(false))
|
||||
|
|
|
|||
|
|
@ -411,7 +411,7 @@ private suspend fun loadContactPictureWithCoil(
|
|||
coroutineScope {
|
||||
withContext(Dispatchers.IO) {
|
||||
val initials = model.initials.value.orEmpty()
|
||||
if (initials.isEmpty() || initials == "+") {
|
||||
if (initials.isEmpty() || initials == "+" || model.skipInitials.value == true) {
|
||||
if (model.defaultToConferenceIcon.value == true) {
|
||||
ResourcesCompat.getDrawable(
|
||||
context.resources,
|
||||
|
|
|
|||
|
|
@ -35,8 +35,11 @@ import org.linphone.core.Call.Dir
|
|||
import org.linphone.core.Call.Status
|
||||
import org.linphone.core.ChatMessage
|
||||
import org.linphone.core.ChatRoom
|
||||
import org.linphone.core.ConferenceInfo
|
||||
import org.linphone.core.Core
|
||||
import org.linphone.core.Friend
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
||||
|
||||
class LinphoneUtils {
|
||||
companion object {
|
||||
|
|
@ -318,5 +321,29 @@ class LinphoneUtils {
|
|||
|
||||
return text
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun getAvatarModelForConferenceInfo(conferenceInfo: ConferenceInfo): ContactAvatarModel {
|
||||
val fakeFriend = coreContext.core.createFriend()
|
||||
fakeFriend.address = conferenceInfo.uri
|
||||
fakeFriend.name = conferenceInfo.subject
|
||||
|
||||
val avatarModel = ContactAvatarModel(fakeFriend)
|
||||
avatarModel.defaultToConferenceIcon.postValue(true)
|
||||
avatarModel.skipInitials.postValue(true)
|
||||
|
||||
val list = arrayListOf<Friend>()
|
||||
for (participant in conferenceInfo.participantInfos) {
|
||||
val friend = coreContext.contactsManager.findContactByAddress(
|
||||
participant.address
|
||||
)
|
||||
if (friend != null) {
|
||||
list.add(friend)
|
||||
}
|
||||
}
|
||||
|
||||
avatarModel.setPicturesFromFriends(list)
|
||||
return avatarModel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue