From eac72a0e423485874ae6b3113d3091b743386aed Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Sat, 11 Jan 2025 11:19:31 +0100 Subject: [PATCH] Do not show call ended fragment if accepted/declined on another device --- .../java/org/linphone/ui/call/CallActivity.kt | 7 +++ .../ui/call/viewmodel/CurrentCallViewModel.kt | 52 ++++++++++++------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/linphone/ui/call/CallActivity.kt b/app/src/main/java/org/linphone/ui/call/CallActivity.kt index c1826637a..c75c4a087 100644 --- a/app/src/main/java/org/linphone/ui/call/CallActivity.kt +++ b/app/src/main/java/org/linphone/ui/call/CallActivity.kt @@ -233,6 +233,13 @@ class CallActivity : GenericActivity() { } } + callViewModel.finishActivityEvent.observe(this) { + it.consume { + Log.i("$TAG Finishing activity") + finish() + } + } + callViewModel.requestRecordAudioPermission.observe(this) { it.consume { Log.w("$TAG Asking for RECORD_AUDIO permission") 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 a2304eca6..bc032adba 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 @@ -149,6 +149,10 @@ class CurrentCallViewModel MutableLiveData>() } + val finishActivityEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + val requestRecordAudioPermission: MutableLiveData> by lazy { MutableLiveData>() } @@ -314,27 +318,11 @@ class CurrentCallViewModel configureCall(newCurrentCall) updateEncryption() } else { - Log.e( - "$TAG Failed to get a valid call to display, go to ended call fragment" - ) - updateCallDuration() - val text = if (call.state == Call.State.Error) { - LinphoneUtils.getCallErrorInfoToast(call) - } else { - "" - } - goToEndedCallEvent.postValue(Event(text)) + Log.e("$TAG Failed to get a valid call to display") + endCall(call) } } else { - updateCallDuration() - Log.i("$TAG Call is ending, go to ended call fragment") - // Show that call was ended for a few seconds, then leave - val text = if (call.state == Call.State.Error) { - LinphoneUtils.getCallErrorInfoToast(call) - } else { - "" - } - goToEndedCallEvent.postValue(Event(text)) + endCall(call) } } else { val videoEnabled = call.currentParams.isVideoEnabled @@ -1426,4 +1414,30 @@ class CurrentCallViewModel } return params } + + @WorkerThread + private fun endCall(call: Call) { + val reason = call.reason + val status = call.callLog.status + Log.i("$TAG Call is ending with status [$status] because of reason [$reason]") + + when (status) { + Call.Status.AcceptedElsewhere, Call.Status.DeclinedElsewhere -> { + Log.i("$TAG Call was accepted/declined on another device, do not show ended call fragment") + finishActivityEvent.postValue(Event(true)) + } + else -> { + Log.i("$TAG Go to ended call fragment") + updateCallDuration() + + // Show that call was ended for a few seconds, then leave + val text = if (call.state == Call.State.Error) { + LinphoneUtils.getCallErrorInfoToast(call) + } else { + "" + } + goToEndedCallEvent.postValue(Event(text)) + } + } + } }