From 3c2640d4bf61534bfd925d3628d192a5efef6922 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 18 May 2022 17:27:11 +0200 Subject: [PATCH] Properly display conference participants in incoming call fragment --- .../linphone/activities/voip/data/CallData.kt | 39 +++++++++++++++++++ .../data/ConferenceInfoParticipantData.kt | 31 +++++++++++++++ .../layout/voip_call_incoming_fragment.xml | 37 ++++-------------- ...p_conference_incoming_participant_cell.xml | 6 +-- app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 6 files changed, 83 insertions(+), 32 deletions(-) create mode 100644 app/src/main/java/org/linphone/activities/voip/data/ConferenceInfoParticipantData.kt diff --git a/app/src/main/java/org/linphone/activities/voip/data/CallData.kt b/app/src/main/java/org/linphone/activities/voip/data/CallData.kt index d446c45df..01bffb826 100644 --- a/app/src/main/java/org/linphone/activities/voip/data/CallData.kt +++ b/app/src/main/java/org/linphone/activities/voip/data/CallData.kt @@ -20,6 +20,7 @@ package org.linphone.activities.voip.data import android.view.View +import androidx.lifecycle.MediatorLiveData import androidx.lifecycle.MutableLiveData import java.util.* import kotlinx.coroutines.* @@ -48,6 +49,9 @@ open class CallData(val call: Call) : GenericContactData(call.remoteAddress) { val isInRemoteConference = MutableLiveData() val remoteConferenceSubject = MutableLiveData() + val isConferenceCall = MediatorLiveData() + val conferenceParticipants = MutableLiveData>() + val conferenceParticipantsCountLabel = MutableLiveData() val isOutgoing = MutableLiveData() val isIncoming = MutableLiveData() @@ -110,6 +114,13 @@ open class CallData(val call: Call) : GenericContactData(call.remoteAddress) { isRemotelyRecorded.value = call.remoteParams?.isRecording displayableAddress.value = LinphoneUtils.getDisplayableAddress(call.remoteAddress) + isConferenceCall.addSource(remoteConferenceSubject) { + isConferenceCall.value = remoteConferenceSubject.value.orEmpty().isNotEmpty() || conferenceParticipants.value.orEmpty().isNotEmpty() + } + isConferenceCall.addSource(conferenceParticipants) { + isConferenceCall.value = remoteConferenceSubject.value.orEmpty().isNotEmpty() || conferenceParticipants.value.orEmpty().isNotEmpty() + } + update() } @@ -231,6 +242,15 @@ open class CallData(val call: Call) : GenericContactData(call.remoteAddress) { conference.subject } Log.d("[Call] Found conference related to this call with subject [${remoteConferenceSubject.value}]") + + val participantsList = arrayListOf() + for (participant in conference.participantList) { + val participantData = ConferenceInfoParticipantData(participant.address) + participantsList.add(participantData) + } + + conferenceParticipants.value = participantsList + conferenceParticipantsCountLabel.value = coreContext.context.getString(R.string.conference_participants_title, participantsList.size) } else { val remoteContact = call.remoteContact Log.d("[Call] Call's remote contact is $remoteContact") @@ -239,6 +259,25 @@ open class CallData(val call: Call) : GenericContactData(call.remoteAddress) { if (conferenceInfo != null) { Log.d("[Call] Found matching conference info with subject: ${conferenceInfo.subject}") remoteConferenceSubject.value = conferenceInfo.subject + + val participantsList = arrayListOf() + for (participant in conferenceInfo.participants) { + val participantData = ConferenceInfoParticipantData(participant) + participantsList.add(participantData) + } + + // Add organizer if not in participants list + val organizer = conferenceInfo.organizer + if (organizer != null) { + val found = participantsList.find { it.participant.weakEqual(organizer) } + if (found == null) { + val participantData = ConferenceInfoParticipantData(organizer) + participantsList.add(0, participantData) + } + } + + conferenceParticipants.value = participantsList + conferenceParticipantsCountLabel.value = coreContext.context.getString(R.string.conference_participants_title, participantsList.size) } } } diff --git a/app/src/main/java/org/linphone/activities/voip/data/ConferenceInfoParticipantData.kt b/app/src/main/java/org/linphone/activities/voip/data/ConferenceInfoParticipantData.kt new file mode 100644 index 000000000..bd7fe2eb6 --- /dev/null +++ b/app/src/main/java/org/linphone/activities/voip/data/ConferenceInfoParticipantData.kt @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010-2022 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 . + */ +package org.linphone.activities.voip.data + +import org.linphone.contact.GenericContactData +import org.linphone.core.* +import org.linphone.utils.LinphoneUtils + +class ConferenceInfoParticipantData( + val participant: Address +) : + GenericContactData(participant) { + val sipUri: String get() = LinphoneUtils.getDisplayableAddress(participant) +} diff --git a/app/src/main/res/layout/voip_call_incoming_fragment.xml b/app/src/main/res/layout/voip_call_incoming_fragment.xml index 43321583a..f45bcaa51 100644 --- a/app/src/main/res/layout/voip_call_incoming_fragment.xml +++ b/app/src/main/res/layout/voip_call_incoming_fragment.xml @@ -42,7 +42,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" - android:text="@{callsViewModel.currentCallData.remoteConferenceSubject.length > 0 ? @string/conference_incoming_title : @string/call_incoming_title, default=@string/call_incoming_title}" + android:text="@{callsViewModel.currentCallData.isConferenceCall ? @string/conference_incoming_title : @string/call_incoming_title, default=@string/call_incoming_title}" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/progress" /> @@ -129,7 +129,7 @@ android:layout_height="wrap_content" android:layout_marginStart="20dp" android:layout_marginEnd="20dp" - android:layout_marginBottom="20dp" + android:layout_marginBottom="10dp" android:background="@drawable/event_decoration_gray" android:gravity="center" android:orientation="horizontal" @@ -145,7 +145,7 @@ android:lineSpacingExtra="0sp" android:paddingLeft="10dp" android:paddingRight="10dp" - android:text="Participants (6)" /> + android:text="@{callsViewModel.currentCallData.conferenceParticipantsCountLabel, default=`Participants (6)`}" /> @@ -167,30 +167,9 @@ - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="vertical" + app:entries="@{callsViewModel.currentCallData.conferenceParticipants}" + app:layout="@{@layout/voip_conference_incoming_participant_cell}" /> @@ -198,14 +177,14 @@ android:id="@+id/single_call_group" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:visibility="@{callsViewModel.currentCallData.remoteConferenceSubject.length > 0 ? View.GONE : View.VISIBLE, default=visible}" + android:visibility="@{callsViewModel.currentCallData.isConferenceCall ? View.GONE : View.VISIBLE, default=visible}" app:constraint_referenced_ids="incoming_call_timer, avatar, caller_name, sipAddress" /> + type="org.linphone.activities.voip.data.ConferenceInfoParticipantData" /> + android:text="@{data.contact.name ?? data.displayName, default=`Bilbo Baggins`}" /> + android:text="@{data.sipUri, default=`sip:bilbo.baggins@sip.linphone.org`}" /> diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 71325e029..a99385561 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -723,4 +723,5 @@ Informations de l\'appel de groupe Démarrer l\'appel de groupe Appel de groupe entrant + Participants (%d) \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5654ff0e6..07f63c02a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -294,6 +294,7 @@ You\'re the first to join the group call All other participants have left the group call Incoming group call + Participants (%d) Incoming Call