From ab0cc34b24752749809f9a405a6b743571eae5f6 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 25 Feb 2022 13:42:42 +0100 Subject: [PATCH] Conference: disable video when using audio only layout + sort participants device depending on layout --- .../ConferenceWaitingRoomViewModel.kt | 14 ++++-- .../fragments/ConferenceLayoutFragment.kt | 44 ------------------- .../voip/viewmodels/ConferenceViewModel.kt | 43 +++++++++++++++++- .../voip_conference_layout_fragment.xml | 11 +++-- 4 files changed, 61 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/org/linphone/activities/main/conference/viewmodels/ConferenceWaitingRoomViewModel.kt b/app/src/main/java/org/linphone/activities/main/conference/viewmodels/ConferenceWaitingRoomViewModel.kt index 8625c6168..ff0b9c197 100644 --- a/app/src/main/java/org/linphone/activities/main/conference/viewmodels/ConferenceWaitingRoomViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/conference/viewmodels/ConferenceWaitingRoomViewModel.kt @@ -106,7 +106,7 @@ class ConferenceWaitingRoomViewModel : ViewModel() { isAudioOnlyLayoutSelected.value = false updateLayout() - isVideoAvailable.value = core.isVideoCaptureEnabled || core.isVideoPreviewEnabled + isVideoAvailable.value = isAudioOnlyLayoutSelected.value == false && (core.isVideoCaptureEnabled || core.isVideoPreviewEnabled) callParams.isVideoEnabled = isVideoAvailable.value == true callParams.videoDirection = if (core.videoActivationPolicy.automaticallyInitiate) MediaDirection.SendRecv else MediaDirection.RecvOnly Log.i("[Conference Waiting Room] Video will be ${if (callParams.isVideoEnabled) "enabled" else "disabled"}") @@ -233,6 +233,7 @@ class ConferenceWaitingRoomViewModel : ViewModel() { askPermissionEvent.value = Event(Manifest.permission.CAMERA) return } + callParams.isVideoEnabled = isVideoAvailable.value == true callParams.videoDirection = if (callParams.videoDirection == MediaDirection.SendRecv) MediaDirection.RecvOnly else MediaDirection.SendRecv Log.i("[Conference Waiting Room] Video will be ${if (callParams.isVideoEnabled) "enabled" else "disabled"}") updateVideoState() @@ -240,6 +241,7 @@ class ConferenceWaitingRoomViewModel : ViewModel() { fun enableVideo() { Log.i("[Conference Waiting Room] Video will be enabled") + callParams.isVideoEnabled = isVideoAvailable.value == true callParams.videoDirection = MediaDirection.SendRecv updateVideoState() } @@ -288,13 +290,19 @@ class ConferenceWaitingRoomViewModel : ViewModel() { } private fun updateLayout() { - val layout = coreContext.core.defaultConferenceLayout + val core = coreContext.core + val layout = core.defaultConferenceLayout isActiveSpeakerLayoutSelected.value = layout == ConferenceLayout.ActiveSpeaker isAudioOnlyLayoutSelected.value = layout == ConferenceLayout.Legacy // TODO: FIXME: Replace Legacy by AudioOnly + + isVideoAvailable.value = isAudioOnlyLayoutSelected.value == false && (core.isVideoCaptureEnabled || core.isVideoPreviewEnabled) + callParams.isVideoEnabled = isVideoAvailable.value == true && isAudioOnlyLayoutSelected.value == false + if (isAudioOnlyLayoutSelected.value == true) callParams.videoDirection = MediaDirection.RecvOnly + updateVideoState() } private fun updateVideoState() { - isVideoEnabled.value = callParams.videoDirection == MediaDirection.SendRecv + isVideoEnabled.value = callParams.isVideoEnabled && callParams.videoDirection == MediaDirection.SendRecv isSwitchCameraAvailable.value = callParams.isVideoEnabled && coreContext.showSwitchCameraButton() coreContext.core.isVideoPreviewEnabled = callParams.isVideoEnabled } diff --git a/app/src/main/java/org/linphone/activities/voip/fragments/ConferenceLayoutFragment.kt b/app/src/main/java/org/linphone/activities/voip/fragments/ConferenceLayoutFragment.kt index 8c70d994a..c248b9d3c 100644 --- a/app/src/main/java/org/linphone/activities/voip/fragments/ConferenceLayoutFragment.kt +++ b/app/src/main/java/org/linphone/activities/voip/fragments/ConferenceLayoutFragment.kt @@ -26,8 +26,6 @@ import androidx.navigation.navGraphViewModels import org.linphone.R import org.linphone.activities.GenericFragment import org.linphone.activities.voip.viewmodels.ConferenceViewModel -import org.linphone.core.ConferenceLayout -import org.linphone.core.tools.Log import org.linphone.databinding.VoipConferenceLayoutFragmentBinding class ConferenceLayoutFragment : GenericFragment() { @@ -46,48 +44,6 @@ class ConferenceLayoutFragment : GenericFragment): ArrayList { + val sortedList = arrayListOf() + sortedList.addAll(devices) + + val meDeviceData = sortedList.find { + it.isMe + } + if (meDeviceData != null) { + val index = sortedList.indexOf(meDeviceData) + val expectedIndex = if (conferenceActiveSpeakerDisplayMode.value == true) { + 0 + } else { + sortedList.size - 1 + } + if (index != expectedIndex) { + Log.i("[Conference] Me device data is at index $index, moving it to index $expectedIndex") + sortedList.removeAt(index) + sortedList.add(expectedIndex, meDeviceData) + } + } + + return sortedList + } } diff --git a/app/src/main/res/layout/voip_conference_layout_fragment.xml b/app/src/main/res/layout/voip_conference_layout_fragment.xml index 8b816322c..aa81801b2 100644 --- a/app/src/main/res/layout/voip_conference_layout_fragment.xml +++ b/app/src/main/res/layout/voip_conference_layout_fragment.xml @@ -4,6 +4,7 @@ + @@ -59,6 +60,7 @@ android:orientation="vertical"> @@ -77,6 +79,7 @@ android:background="?attr/dividerColor" /> @@ -94,7 +97,9 @@ android:layout_height="1dp" android:background="?attr/dividerColor" /> +