diff --git a/changelog.d/5081.bugfix b/changelog.d/5081.bugfix new file mode 100644 index 0000000000..6ec6dcc43e --- /dev/null +++ b/changelog.d/5081.bugfix @@ -0,0 +1 @@ +Selecting Transfer in a call should immediately put the other person on hold until the call connects or the Transfer is cancelled. \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt index 22f1fc40a2..642d259723 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt @@ -16,6 +16,7 @@ package im.vector.app.features.call +import android.app.Activity import android.app.KeyguardManager import android.app.PictureInPictureParams import android.content.Context @@ -43,6 +44,7 @@ import com.google.android.material.card.MaterialCardView import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.android.AndroidEntryPoint import im.vector.app.R +import im.vector.app.core.extensions.registerStartForActivityResult import im.vector.app.core.extensions.setTextOrHide import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.utils.PERMISSIONS_FOR_AUDIO_IP_CALL @@ -518,13 +520,19 @@ class VectorCallActivity : VectorBaseActivity(), CallContro } is VectorCallViewEvents.ShowCallTransferScreen -> { val callId = withState(callViewModel) { it.callId } - navigator.openCallTransfer(this, callId) + navigator.openCallTransfer(this, callTransferActivityResultLauncher, callId) } null -> { } } } + private val callTransferActivityResultLauncher = registerStartForActivityResult { activityResult -> + if (activityResult.resultCode == Activity.RESULT_CANCELED) { + callViewModel.handle(VectorCallViewActions.CallTransferSelectionCancelled) + } + } + private fun onErrorTimoutConnect(turn: TurnServerResponse?) { Timber.tag(loggerTag.value).d("onErrorTimoutConnect $turn") // TODO ask to use default stun, etc... diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallViewActions.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallViewActions.kt index 67aa7bede2..fb39660282 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallViewActions.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallViewActions.kt @@ -36,5 +36,6 @@ sealed class VectorCallViewActions : VectorViewModelAction { object ToggleCamera : VectorCallViewActions() object ToggleHDSD : VectorCallViewActions() object InitiateCallTransfer : VectorCallViewActions() + object CallTransferSelectionCancelled : VectorCallViewActions() object TransferCall : VectorCallViewActions() } diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt index 5af2b826af..4aca0ea499 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt @@ -319,10 +319,14 @@ class VectorCallViewModel @AssistedInject constructor( call?.sendDtmfDigit(action.digit) } VectorCallViewActions.InitiateCallTransfer -> { + call?.updateRemoteOnHold(true) _viewEvents.post( VectorCallViewEvents.ShowCallTransferScreen ) } + VectorCallViewActions.CallTransferSelectionCancelled -> { + call?.updateRemoteOnHold(false) + } VectorCallViewActions.TransferCall -> { handleCallTransfer() } diff --git a/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferActivity.kt b/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferActivity.kt index 959e96cc4c..0e63316bbe 100644 --- a/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferActivity.kt @@ -16,6 +16,7 @@ package im.vector.app.features.call.transfer +import android.app.Activity import android.content.Context import android.content.Intent import android.os.Bundle @@ -55,7 +56,7 @@ class CallTransferActivity : VectorBaseActivity() { callTransferViewModel.observeViewEvents { when (it) { - is CallTransferViewEvents.Dismiss -> finish() + is CallTransferViewEvents.Complete -> handleComplete() CallTransferViewEvents.Loading -> showWaitingView() is CallTransferViewEvents.FailToTransfer -> showSnackbar(getString(R.string.call_transfer_failure)) } @@ -93,6 +94,11 @@ class CallTransferActivity : VectorBaseActivity() { } } + private fun handleComplete() { + setResult(Activity.RESULT_OK) + finish() + } + companion object { fun newIntent(context: Context, callId: String): Intent { diff --git a/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferViewEvents.kt b/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferViewEvents.kt index fd4c9d672d..a8451e4fb5 100644 --- a/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferViewEvents.kt +++ b/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferViewEvents.kt @@ -19,7 +19,7 @@ package im.vector.app.features.call.transfer import im.vector.app.core.platform.VectorViewEvents sealed class CallTransferViewEvents : VectorViewEvents { - object Dismiss : CallTransferViewEvents() + object Complete : CallTransferViewEvents() object Loading : CallTransferViewEvents() object FailToTransfer : CallTransferViewEvents() } diff --git a/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferViewModel.kt b/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferViewModel.kt index ffc6ff9bc3..de6a5de539 100644 --- a/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferViewModel.kt @@ -50,14 +50,14 @@ class CallTransferViewModel @AssistedInject constructor(@Assisted initialState: private val callListener = object : WebRtcCall.Listener { override fun onStateUpdate(call: MxCall) { if (call.state is CallState.Ended) { - _viewEvents.post(CallTransferViewEvents.Dismiss) + _viewEvents.post(CallTransferViewEvents.Complete) } } } init { if (call == null) { - _viewEvents.post(CallTransferViewEvents.Dismiss) + _viewEvents.post(CallTransferViewEvents.Complete) } else { call.addListener(callListener) } @@ -89,7 +89,7 @@ class CallTransferViewModel @AssistedInject constructor(@Assisted initialState: } else { call?.transferToUser(action.selectedUserId, null) } - _viewEvents.post(CallTransferViewEvents.Dismiss) + _viewEvents.post(CallTransferViewEvents.Complete) } catch (failure: Throwable) { _viewEvents.post(CallTransferViewEvents.FailToTransfer) } @@ -111,7 +111,7 @@ class CallTransferViewModel @AssistedInject constructor(@Assisted initialState: } else { call?.transferToUser(result.userId, result.roomId) } - _viewEvents.post(CallTransferViewEvents.Dismiss) + _viewEvents.post(CallTransferViewEvents.Complete) } catch (failure: Throwable) { _viewEvents.post(CallTransferViewEvents.FailToTransfer) } diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index f66ced3299..8f0b1723a0 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -524,9 +524,13 @@ class DefaultNavigator @Inject constructor( context.startActivity(RoomDevToolActivity.intent(context, roomId)) } - override fun openCallTransfer(context: Context, callId: String) { + override fun openCallTransfer( + context: Context, + activityResultLauncher: ActivityResultLauncher, + callId: String + ) { val intent = CallTransferActivity.newIntent(context, callId) - context.startActivity(intent) + activityResultLauncher.launch(intent) } override fun openCreatePoll(context: Context, roomId: String, editedEventId: String?, mode: PollMode) { diff --git a/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt b/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt index 775272bd33..d6ca83a8a3 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt @@ -149,7 +149,11 @@ interface Navigator { fun openDevTools(context: Context, roomId: String) - fun openCallTransfer(context: Context, callId: String) + fun openCallTransfer( + context: Context, + activityResultLauncher: ActivityResultLauncher, + callId: String + ) fun openCreatePoll(context: Context, roomId: String, editedEventId: String?, mode: PollMode)