From 2eb8b496cd45b75a2afbab59d4fb2383bdd9bb69 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 26 Oct 2023 16:53:17 +0200 Subject: [PATCH] Various fixes & improvements --- .../org/linphone/contacts/ContactsManager.kt | 19 +++++++++++--- .../fragment/ActiveConferenceCallFragment.kt | 26 +++++++++++++++++++ .../linphone/ui/call/model/ConferenceModel.kt | 7 ++++- .../ui/call/viewmodel/CurrentCallViewModel.kt | 6 ++++- .../viewmodel/MeetingWaitingRoomViewModel.kt | 8 +++--- .../ui/main/viewmodel/MainViewModel.kt | 24 ++++++++--------- .../call_active_conference_fragment.xml | 24 +++++------------ .../res/layout/call_conference_grid_cell.xml | 15 +++++++---- .../layout/meeting_waiting_room_fragment.xml | 13 ++++++++++ 9 files changed, 96 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/org/linphone/contacts/ContactsManager.kt b/app/src/main/java/org/linphone/contacts/ContactsManager.kt index 9db118bb3..00d42ae78 100644 --- a/app/src/main/java/org/linphone/contacts/ContactsManager.kt +++ b/app/src/main/java/org/linphone/contacts/ContactsManager.kt @@ -189,13 +189,24 @@ class ContactsManager @UiThread constructor(context: Context) { val foundInMap = if (avatarsMap.keys.contains(key)) avatarsMap[key] else null if (foundInMap != null) return foundInMap - val friend = coreContext.contactsManager.findContactByAddress(clone) - val avatar = if (friend != null) { - ContactAvatarModel(friend) - } else { + val localAccount = coreContext.core.accountList.find { + it.params.identityAddress?.weakEqual(clone) == true + } + val avatar = if (localAccount != null) { val fakeFriend = coreContext.core.createFriend() fakeFriend.address = clone + fakeFriend.name = LinphoneUtils.getDisplayName(localAccount.params.identityAddress) + fakeFriend.photo = localAccount.params.pictureUri ContactAvatarModel(fakeFriend) + } else { + val friend = coreContext.contactsManager.findContactByAddress(clone) + if (friend != null) { + ContactAvatarModel(friend) + } else { + val fakeFriend = coreContext.core.createFriend() + fakeFriend.address = clone + ContactAvatarModel(fakeFriend) + } } avatarsMap[key] = avatar diff --git a/app/src/main/java/org/linphone/ui/call/fragment/ActiveConferenceCallFragment.kt b/app/src/main/java/org/linphone/ui/call/fragment/ActiveConferenceCallFragment.kt index ed20d7baa..448faf223 100644 --- a/app/src/main/java/org/linphone/ui/call/fragment/ActiveConferenceCallFragment.kt +++ b/app/src/main/java/org/linphone/ui/call/fragment/ActiveConferenceCallFragment.kt @@ -26,6 +26,7 @@ import android.view.View import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider import com.google.android.material.bottomsheet.BottomSheetBehavior +import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.databinding.CallActiveConferenceFragmentBinding import org.linphone.ui.call.viewmodel.CallsViewModel import org.linphone.ui.call.viewmodel.CurrentCallViewModel @@ -85,5 +86,30 @@ class ActiveConferenceCallFragment : GenericCallFragment() { } } } + + actionsBottomSheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { + override fun onStateChanged(bottomSheet: View, newState: Int) { + when (newState) { + BottomSheetBehavior.STATE_COLLAPSED, BottomSheetBehavior.STATE_HIDDEN -> { + callViewModel.isActionsMenuExpanded.value = false + } + BottomSheetBehavior.STATE_EXPANDED -> { + callViewModel.isActionsMenuExpanded.value = true + } + else -> {} + } + } + + override fun onSlide(bottomSheet: View, slideOffset: Float) {} + }) + } + + override fun onResume() { + super.onResume() + + coreContext.postOnCoreThread { + // Need to be done manually + callViewModel.updateCallDuration() + } } } diff --git a/app/src/main/java/org/linphone/ui/call/model/ConferenceModel.kt b/app/src/main/java/org/linphone/ui/call/model/ConferenceModel.kt index 01bef7e8b..770a755e0 100644 --- a/app/src/main/java/org/linphone/ui/call/model/ConferenceModel.kt +++ b/app/src/main/java/org/linphone/ui/call/model/ConferenceModel.kt @@ -95,6 +95,9 @@ class ConferenceModel { @WorkerThread override fun onStateChanged(conference: Conference, state: Conference.State) { Log.i("$TAG State changed [$state]") + if (conference.state == Conference.State.Created) { + computeParticipantsDevices() + } } } @@ -121,7 +124,9 @@ class ConferenceModel { ) subject.postValue(conference.subject) - computeParticipantsDevices() + if (conference.state == Conference.State.Created) { + computeParticipantsDevices() + } } @WorkerThread diff --git a/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt b/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt index 78f5731c7..2cc491ba2 100644 --- a/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt +++ b/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt @@ -783,10 +783,14 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() { model.trust.postValue(securityLevel) contact.postValue(model) } else { + val conferenceInfo = coreContext.core.findConferenceInformationFromUri( + call.remoteAddress + ) val fakeFriend = coreContext.core.createFriend() - fakeFriend.name = LinphoneUtils.getDisplayName(address) + fakeFriend.name = conferenceInfo?.subject ?: LinphoneUtils.getDisplayName(address) fakeFriend.addAddress(address) val model = ContactAvatarModel(fakeFriend) + model.showConferenceIcon.postValue(conferenceInfo != null) model.trust.postValue(securityLevel) contact.postValue(model) displayedName.postValue(fakeFriend.name) diff --git a/app/src/main/java/org/linphone/ui/main/meetings/viewmodel/MeetingWaitingRoomViewModel.kt b/app/src/main/java/org/linphone/ui/main/meetings/viewmodel/MeetingWaitingRoomViewModel.kt index 55552974f..99c20b13b 100644 --- a/app/src/main/java/org/linphone/ui/main/meetings/viewmodel/MeetingWaitingRoomViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/meetings/viewmodel/MeetingWaitingRoomViewModel.kt @@ -32,7 +32,6 @@ import org.linphone.core.Factory import org.linphone.core.tools.Log import org.linphone.ui.main.contacts.model.ContactAvatarModel import org.linphone.utils.Event -import org.linphone.utils.LinphoneUtils import org.linphone.utils.TimestampUtils class MeetingWaitingRoomViewModel @UiThread constructor() : ViewModel() { @@ -195,10 +194,9 @@ class MeetingWaitingRoomViewModel @UiThread constructor() : ViewModel() { dateTime.postValue("$date | $startTime - $endTime") val localAddress = coreContext.core.defaultAccount?.params?.identityAddress - val fakeFriend = coreContext.core.createFriend() - fakeFriend.address = localAddress - fakeFriend.name = LinphoneUtils.getDisplayName(localAddress) - val avatarModel = ContactAvatarModel(fakeFriend) + val avatarModel = coreContext.contactsManager.getContactAvatarModelForAddress( + localAddress + ) selfAvatar.postValue(avatarModel) } } diff --git a/app/src/main/java/org/linphone/ui/main/viewmodel/MainViewModel.kt b/app/src/main/java/org/linphone/ui/main/viewmodel/MainViewModel.kt index eed74bd98..fa5f91a2f 100644 --- a/app/src/main/java/org/linphone/ui/main/viewmodel/MainViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/viewmodel/MainViewModel.kt @@ -186,26 +186,26 @@ class MainViewModel @UiThread constructor() : ViewModel() { private fun updateCurrentCallInfo() { val core = coreContext.core if (core.callsNb == 1) { - val currentCall = core.currentCall + val currentCall = core.currentCall ?: core.calls.firstOrNull() if (currentCall != null) { val contact = coreContext.contactsManager.findContactByAddress( currentCall.remoteAddress ) - callLabel.postValue( - contact?.name ?: LinphoneUtils.getDisplayName(currentCall.remoteAddress) - ) - callsStatus.postValue(LinphoneUtils.callStateToString(currentCall.state)) - } else { - val firstCall = core.calls.firstOrNull() - if (firstCall != null) { - val contact = coreContext.contactsManager.findContactByAddress( - firstCall.remoteAddress + if (contact != null) { + callLabel.postValue( + contact.name ?: LinphoneUtils.getDisplayName(currentCall.remoteAddress) + ) + } else { + val conferenceInfo = coreContext.core.findConferenceInformationFromUri( + currentCall.remoteAddress ) callLabel.postValue( - contact?.name ?: LinphoneUtils.getDisplayName(firstCall.remoteAddress) + conferenceInfo?.subject ?: LinphoneUtils.getDisplayName( + currentCall.remoteAddress + ) ) - callsStatus.postValue(LinphoneUtils.callStateToString(firstCall.state)) } + callsStatus.postValue(LinphoneUtils.callStateToString(currentCall.state)) } } else { callLabel.postValue( diff --git a/app/src/main/res/layout/call_active_conference_fragment.xml b/app/src/main/res/layout/call_active_conference_fragment.xml index 53342dec8..19ce33059 100644 --- a/app/src/main/res/layout/call_active_conference_fragment.xml +++ b/app/src/main/res/layout/call_active_conference_fragment.xml @@ -36,20 +36,6 @@ android:layout_height="match_parent" android:background="@color/gray_900"> - - - - + app:layout_constraintTop_toTopOf="parent"/> + + diff --git a/app/src/main/res/layout/meeting_waiting_room_fragment.xml b/app/src/main/res/layout/meeting_waiting_room_fragment.xml index 72640054b..3b228d2c0 100644 --- a/app/src/main/res/layout/meeting_waiting_room_fragment.xml +++ b/app/src/main/res/layout/meeting_waiting_room_fragment.xml @@ -92,6 +92,19 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/back" app:layout_constraintBottom_toTopOf="@id/toggle_mute_mic"/> + +