From cefb7ffd901c67ab03568586e67025e230e5c40f Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 9 Apr 2021 15:28:25 +0200 Subject: [PATCH] Fixed pause/video buttons to be disabled until next call state update or UI pause/resume --- .../call/viewmodels/ControlsViewModel.kt | 19 +++++++++++++++---- app/src/main/res/layout/call_activity.xml | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsViewModel.kt b/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsViewModel.kt index 51d11d06d..ae769eef9 100644 --- a/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsViewModel.kt +++ b/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsViewModel.kt @@ -26,7 +26,10 @@ import android.os.Vibrator import android.view.animation.LinearInterpolator import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import kotlin.math.max +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import org.linphone.LinphoneApplication import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.corePreferences @@ -386,6 +389,11 @@ class ControlsViewModel : ViewModel() { AudioRouteUtils.routeAudioToBluetooth() } + fun updateMuteMicState() { + isMicrophoneMuted.value = !PermissionHelper.get().hasRecordAudioPermission() || !coreContext.core.micEnabled() + isMuteMicrophoneEnabled.value = coreContext.core.currentCall != null || coreContext.core.isInConference + } + private fun updateAudioRelated() { updateSpeakerState() updateBluetoothHeadsetState() @@ -399,11 +407,14 @@ class ControlsViewModel : ViewModel() { isPauseEnabled.value = currentCall != null && !currentCall.mediaInProgress() isMuteMicrophoneEnabled.value = currentCall != null || coreContext.core.isInConference updateConferenceState() - } - fun updateMuteMicState() { - isMicrophoneMuted.value = !PermissionHelper.get().hasRecordAudioPermission() || !coreContext.core.micEnabled() - isMuteMicrophoneEnabled.value = coreContext.core.currentCall != null || coreContext.core.isInConference + // Check periodically until mediaInProgress is false + if (currentCall != null && currentCall.mediaInProgress()) { + viewModelScope.launch { + delay(1000) + updateUI() + } + } } private fun updateSpeakerState() { diff --git a/app/src/main/res/layout/call_activity.xml b/app/src/main/res/layout/call_activity.xml index 1b96a5c37..ccf0839a6 100644 --- a/app/src/main/res/layout/call_activity.xml +++ b/app/src/main/res/layout/call_activity.xml @@ -53,7 +53,7 @@ tools:layout="@layout/call_status_fragment" />