Fix bugs with switching and render wired headset state in calls.

This commit is contained in:
Cody Henthorne
2023-04-17 12:20:48 -04:00
committed by GitHub
parent e33a68b203
commit e2ade166ec
4 changed files with 23 additions and 14 deletions

View File

@@ -72,21 +72,27 @@ class WebRtcAudioOutputToggleButton @JvmOverloads constructor(context: Context,
}
/**
* DO NOT REMOVE THE ELVIS OPERATOR IN THE FIRST LINE
* DO NOT REMOVE senseless comparison suppression.
* Somehow, through XML inflation (reflection?), [outputState] can actually be null,
* even though the compiler disagrees.
* */
override fun onCreateDrawableState(extraSpace: Int): IntArray {
val currentState = outputState ?: return super.onCreateDrawableState(extraSpace) // DO NOT REMOVE
val currentOutput = currentState.getCurrentOutput()
@Suppress("SENSELESS_COMPARISON")
if (outputState == null) {
return super.onCreateDrawableState(extraSpace)
}
val currentOutput = outputState.getCurrentOutput()
val extra = when (currentOutput) {
WebRtcAudioOutput.HANDSET -> intArrayOf(R.attr.state_handset_selected)
WebRtcAudioOutput.SPEAKER -> intArrayOf(R.attr.state_speaker_selected)
WebRtcAudioOutput.BLUETOOTH_HEADSET -> intArrayOf(R.attr.state_bt_headset_selected)
WebRtcAudioOutput.WIRED_HEADSET -> intArrayOf(R.attr.state_wired_headset_selected)
}
val oldLabel = context.getString(currentOutput.labelRes)
Log.i(TAG, "Switching drawable to $oldLabel")
val label = context.getString(currentOutput.labelRes)
Log.i(TAG, "Switching to $label")
val drawableState = super.onCreateDrawableState(extraSpace + extra.size)
mergeDrawableStates(drawableState, extra)
return drawableState
@@ -96,9 +102,10 @@ class WebRtcAudioOutputToggleButton @JvmOverloads constructor(context: Context,
throw UnsupportedOperationException("This View does not support custom click listeners.")
}
fun setControlAvailability(isEarpieceAvailable: Boolean, isBluetoothHeadsetAvailable: Boolean) {
fun setControlAvailability(isEarpieceAvailable: Boolean, isBluetoothHeadsetAvailable: Boolean, isHeadsetAvailable: Boolean) {
outputState.isEarpieceAvailable = isEarpieceAvailable
outputState.isBluetoothHeadsetAvailable = isBluetoothHeadsetAvailable
outputState.isWiredHeadsetAvailable = isHeadsetAvailable
}
fun setAudioOutput(audioOutput: WebRtcAudioOutput, notifyListener: Boolean) {

View File

@@ -670,7 +670,8 @@ public class WebRtcCallView extends ConstraintLayout {
visibleViewSet.add(audioToggle);
audioToggle.setControlAvailability(webRtcControls.isEarpieceAvailableForAudioToggle(),
webRtcControls.isBluetoothHeadsetAvailableForAudioToggle());
webRtcControls.isBluetoothHeadsetAvailableForAudioToggle(),
webRtcControls.isWiredHeadsetAvailableForAudioToggle());
audioToggle.setAudioOutput(webRtcControls.getAudioOutput(), false);
}

View File

@@ -153,7 +153,7 @@ public final class WebRtcControls {
}
boolean displayAudioToggle() {
return (isPreJoin() || isAtLeastOutgoing()) && (!isLocalVideoEnabled || isBluetoothHeadsetAvailableForAudioToggle());
return (isPreJoin() || isAtLeastOutgoing()) && (!isLocalVideoEnabled || isBluetoothHeadsetAvailableForAudioToggle() || isWiredHeadsetAvailableForAudioToggle());
}
boolean displayCameraToggle() {
@@ -180,6 +180,10 @@ public final class WebRtcControls {
return availableDevices.contains(SignalAudioManager.AudioDevice.BLUETOOTH);
}
boolean isWiredHeadsetAvailableForAudioToggle() {
return availableDevices.contains(SignalAudioManager.AudioDevice.BLUETOOTH);
}
boolean isFadeOutEnabled() {
return isAtLeastOutgoing() && isRemoteVideoEnabled && callState != CallState.RECONNECTING;
}