From 1d0abc4cb9e568657726b76a9850f36e72ab6d44 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 2 Oct 2023 11:56:18 +0200 Subject: [PATCH] Attended transfer --- .../ui/call/fragment/ActiveCallFragment.kt | 12 ++++--- .../ui/call/viewmodel/CurrentCallViewModel.kt | 33 +++++++++++++++++++ .../res/layout-land/call_extra_actions.xml | 7 ++-- .../main/res/layout/call_active_fragment.xml | 4 --- .../main/res/layout/call_extra_actions.xml | 7 ++-- 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/linphone/ui/call/fragment/ActiveCallFragment.kt b/app/src/main/java/org/linphone/ui/call/fragment/ActiveCallFragment.kt index 602ead36f..4b73b1376 100644 --- a/app/src/main/java/org/linphone/ui/call/fragment/ActiveCallFragment.kt +++ b/app/src/main/java/org/linphone/ui/call/fragment/ActiveCallFragment.kt @@ -135,11 +135,6 @@ class ActiveCallFragment : GenericCallFragment() { findNavController().navigate(action) } - binding.setTransferClickListener { - val action = ActiveCallFragmentDirections.actionActiveCallFragmentToTransferCallFragment() - findNavController().navigate(action) - } - binding.setCallsListClickListener { val action = ActiveCallFragmentDirections.actionActiveCallFragmentToCallsListFragment() findNavController().navigate(action) @@ -153,6 +148,13 @@ class ActiveCallFragment : GenericCallFragment() { updateHingeRelatedConstraints(feature) } + callViewModel.goToInitiateBlindTransferEvent.observe(viewLifecycleOwner) { + it.consume { + val action = ActiveCallFragmentDirections.actionActiveCallFragmentToTransferCallFragment() + findNavController().navigate(action) + } + } + callViewModel.fullScreenMode.observe(viewLifecycleOwner) { hide -> Log.i("$TAG Switching full screen mode to ${if (hide) "ON" else "OFF"}") sharedViewModel.toggleFullScreenEvent.value = Event(hide) 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 d14b4a14f..84957191e 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 @@ -102,6 +102,10 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() { MutableLiveData() } + val goToInitiateBlindTransferEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + val goTEndedCallEvent: MutableLiveData> by lazy { MutableLiveData>() } @@ -595,6 +599,35 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() { showNumpadBottomSheetEvent.value = Event(true) } + @UiThread + fun transferClicked() { + coreContext.postOnCoreThread { core -> + if (core.callsNb == 1) { + Log.i("$TAG Only one call, initiate blind call transfer") + goToInitiateBlindTransferEvent.postValue(Event(true)) + } else { + val callToTransferTo = core.calls.findLast { + it.state == Call.State.Paused && it != currentCall + } + if (callToTransferTo == null) { + Log.e( + "$TAG Couldn't find a call in Paused state to transfer current call to" + ) + return@postOnCoreThread + } + + Log.i( + "$TAG Doing an attended transfer between currently displayed call [${currentCall.remoteAddress.asStringUriOnly()}] and paused call [${callToTransferTo.remoteAddress.asStringUriOnly()}]" + ) + if (callToTransferTo.transferToAnother(currentCall) != 0) { + Log.e("$TAG Failed to make attended transfer!") + } else { + Log.i("$TAG Attended transfer is successful") + } + } + } + } + @WorkerThread fun blindTransferCallTo(to: Address) { if (::currentCall.isInitialized) { diff --git a/app/src/main/res/layout-land/call_extra_actions.xml b/app/src/main/res/layout-land/call_extra_actions.xml index 74cb51310..6e9492e92 100644 --- a/app/src/main/res/layout-land/call_extra_actions.xml +++ b/app/src/main/res/layout-land/call_extra_actions.xml @@ -5,9 +5,6 @@ - @@ -45,7 +42,7 @@ - @@ -267,7 +264,6 @@ layout="@layout/call_extra_actions" bind:viewModel="@{viewModel}" bind:callsViewModel="@{callsViewModel}" - bind:transferClickListener="@{transferClickListener}" bind:newCallClickListener="@{newCallClickListener}" bind:callsListClickListener="@{callsListClickListener}"/> diff --git a/app/src/main/res/layout/call_extra_actions.xml b/app/src/main/res/layout/call_extra_actions.xml index 8c8ed5c1d..33e3f2832 100644 --- a/app/src/main/res/layout/call_extra_actions.xml +++ b/app/src/main/res/layout/call_extra_actions.xml @@ -5,9 +5,6 @@ - @@ -45,7 +42,7 @@