Do not show call ended fragment if accepted/declined on another device

This commit is contained in:
Sylvain Berfini 2025-01-11 11:19:31 +01:00
parent de29fbc125
commit eac72a0e42
2 changed files with 40 additions and 19 deletions

View file

@ -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")

View file

@ -149,6 +149,10 @@ class CurrentCallViewModel
MutableLiveData<Event<String>>()
}
val finishActivityEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
val requestRecordAudioPermission: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
@ -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))
}
}
}
}