Code improvement

This commit is contained in:
Sylvain Berfini 2021-03-24 15:37:24 +01:00
parent c5f40c8eed
commit 704e7d84fa
3 changed files with 14 additions and 26 deletions

View file

@ -55,7 +55,7 @@ class ControlsFadingViewModel : ViewModel() {
) {
if (state == Call.State.StreamsRunning || state == Call.State.Updating || state == Call.State.UpdatedByRemote) {
val isVideoCall = coreContext.isVideoCallOrConferenceActive()
Log.i("[Controls Fading] Call is in state $state, video is enabled? $videoEnabled")
Log.i("[Controls Fading] Call is in state $state, video is ${if (isVideoCall) "enabled" else "disabled"}")
if (isVideoCall) {
videoEnabled.value = true
startTimer()

View file

@ -188,7 +188,7 @@ class ControlsViewModel : ViewModel() {
override fun onAudioDevicesListUpdated(core: Core) {
if (core.callsNb == 0) return
updateAudioRoutesState()
routeAudioToBluetoothIfAvailable(core.currentCall ?: core.calls[0])
coreContext.routeAudioToBluetoothIfAvailable(core.currentCall ?: core.calls[0])
}
}
@ -443,18 +443,6 @@ class ControlsViewModel : ViewModel() {
isBluetoothHeadsetSelected.value = audioDevice?.type == AudioDevice.Type.Bluetooth
}
private fun routeAudioToBluetoothIfAvailable(call: Call) {
for (audioDevice in coreContext.core.audioDevices) {
if (audioDevice.type == AudioDevice.Type.Bluetooth &&
audioDevice.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) {
Log.i("[Call] Found bluetooth audio device [${audioDevice.deviceName}], routing audio to it")
call.outputAudioDevice = audioDevice
return
}
}
Log.w("[Call] Didn't find any bluetooth audio device, keeping current audio route")
}
private fun updateVideoAvailable() {
val core = coreContext.core
val currentCall = core.currentCall

View file

@ -549,6 +549,18 @@ class CoreContext(val context: Context, coreConfig: Config) {
}
}
fun routeAudioToBluetoothIfAvailable(call: Call) {
for (audioDevice in core.audioDevices) {
if (audioDevice.type == AudioDevice.Type.Bluetooth &&
audioDevice.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) {
Log.i("[Context] Found bluetooth audio device [${audioDevice.deviceName}], routing audio to it")
call.outputAudioDevice = audioDevice
return
}
}
Log.w("[Context] Didn't find any bluetooth audio device, keeping default audio route")
}
/* Start call related activities */
private fun onIncomingReceived() {
@ -589,16 +601,4 @@ class CoreContext(val context: Context, coreConfig: Config) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
context.startActivity(intent)
}
private fun routeAudioToBluetoothIfAvailable(call: Call) {
for (audioDevice in core.audioDevices) {
if (audioDevice.type == AudioDevice.Type.Bluetooth &&
audioDevice.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) {
Log.i("[Context] Found bluetooth audio device [${audioDevice.deviceName}], routing audio to it")
call.outputAudioDevice = audioDevice
return
}
}
Log.w("[Context] Didn't find any bluetooth audio device, keeping default audio route")
}
}