From 33047b5f644cf12e48d7f73999ff644d1404a2de Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 16 Dec 2020 18:49:29 +0100 Subject: [PATCH] VoIP: fix some other issues --- .../app/features/call/VectorCallViewModel.kt | 9 ++++++--- .../app/features/call/webrtc/WebRtcCall.kt | 4 +--- .../app/features/popup/IncomingCallAlert.kt | 19 +++++++++++++------ .../layout/alerter_incoming_call_layout.xml | 3 +++ 4 files changed, 23 insertions(+), 12 deletions(-) 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 ac45cdab5a..6f5a9213ae 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 @@ -123,7 +123,11 @@ class VectorCallViewModel @AssistedInject constructor( private val currentCallListener = object : WebRtcCallManager.CurrentCallListener { override fun onCurrentCallChange(call: WebRtcCall?) { - updateOtherKnownCall(call) + if (call == null) { + _viewEvents.post(VectorCallViewEvents.DismissNoCall) + } else { + updateOtherKnownCall(call) + } } override fun onAudioDevicesChange() { @@ -143,8 +147,7 @@ class VectorCallViewModel @AssistedInject constructor( } } - private fun updateOtherKnownCall(currentCall: WebRtcCall?) { - if (currentCall == null) return + private fun updateOtherKnownCall(currentCall: WebRtcCall) { val otherCall = callManager.getCalls().firstOrNull { it.callId != currentCall.callId && it.mxCall.state is CallState.Connected } diff --git a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt index 41a43dd924..68cbc67b67 100644 --- a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt +++ b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt @@ -707,7 +707,6 @@ class WebRtcCall(val mxCall: MxCall, if (mxCall.state == CallState.Terminated) { return } - val wasConnected = mxCall.state is CallState.Connected mxCall.state = CallState.Terminated // Close tracks ASAP localVideoTrack?.setEnabled(false) @@ -721,8 +720,7 @@ class WebRtcCall(val mxCall: MxCall, } onCallEnded(this) if (originatedByMe) { - // send hang up event - if (wasConnected) { + if (mxCall.state is CallState.Connected || mxCall.isOutgoing) { mxCall.hangUp(reason) } else { mxCall.reject() diff --git a/vector/src/main/java/im/vector/app/features/popup/IncomingCallAlert.kt b/vector/src/main/java/im/vector/app/features/popup/IncomingCallAlert.kt index b3882945b4..f80d6d1bbd 100644 --- a/vector/src/main/java/im/vector/app/features/popup/IncomingCallAlert.kt +++ b/vector/src/main/java/im/vector/app/features/popup/IncomingCallAlert.kt @@ -21,6 +21,7 @@ import android.view.View import android.widget.ImageView import android.widget.TextView import im.vector.app.R +import im.vector.app.core.extensions.setLeftDrawable import im.vector.app.core.glide.GlideApp import im.vector.app.features.home.AvatarRenderer import org.matrix.android.sdk.api.util.MatrixItem @@ -43,18 +44,24 @@ class IncomingCallAlert(uid: String, : VectorAlert.ViewBinder { override fun bind(view: View) { - val callKind = if (isVideoCall) { - R.string.action_video_call + val (callKindText, callKindIcon) = if (isVideoCall) { + Pair(R.string.action_video_call, R.drawable.ic_call_video_small) } else { - R.string.action_voice_call + Pair(R.string.action_voice_call, R.drawable.ic_call_audio_small) + } + view.findViewById(R.id.incomingCallKindView).apply { + setText(callKindText) + setLeftDrawable(callKindIcon) } - view.findViewById(R.id.incomingCallKindView).setText(callKind) view.findViewById(R.id.incomingCallNameView).text = matrixItem?.getBestName() view.findViewById(R.id.incomingCallAvatar)?.let { imageView -> matrixItem?.let { avatarRenderer.render(it, imageView, GlideApp.with(view.context.applicationContext)) } } - view.findViewById(R.id.incomingCallAcceptView).setOnClickListener { - onAccept() + view.findViewById(R.id.incomingCallAcceptView).apply { + setOnClickListener { + onAccept() + } + setImageResource(callKindIcon) } view.findViewById(R.id.incomingCallRejectView).setOnClickListener { onReject() diff --git a/vector/src/main/res/layout/alerter_incoming_call_layout.xml b/vector/src/main/res/layout/alerter_incoming_call_layout.xml index a874e41743..8487d8885f 100644 --- a/vector/src/main/res/layout/alerter_incoming_call_layout.xml +++ b/vector/src/main/res/layout/alerter_incoming_call_layout.xml @@ -45,6 +45,8 @@ android:layout_marginEnd="8dp" android:ellipsize="end" android:textColor="?riotx_text_secondary" + app:drawableTint="?riotx_text_secondary" + android:drawablePadding="4dp" android:textSize="15sp" android:maxLines="1" app:layout_constraintEnd_toStartOf="@+id/incomingCallRejectView" @@ -65,6 +67,7 @@ app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" + app:tint="@color/white" android:src="@drawable/ic_call_answer" />