feat: Allow user to select default microphone if selected on disconnected

This commit is contained in:
Myzel394 2023-10-22 00:42:01 +02:00
parent d559fb45a5
commit 8fd57aace3
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
3 changed files with 20 additions and 12 deletions

View File

@ -37,6 +37,7 @@ fun MicrophoneSelectionButton(
microphone: MicrophoneInfo? = null, microphone: MicrophoneInfo? = null,
selected: Boolean = false, selected: Boolean = false,
selectedAsFallback: Boolean = false, selectedAsFallback: Boolean = false,
disabled: Boolean = false,
onSelect: () -> Unit, onSelect: () -> Unit,
) { ) {
val dataStore = LocalContext.current.dataStore val dataStore = LocalContext.current.dataStore
@ -47,11 +48,11 @@ fun MicrophoneSelectionButton(
Button( Button(
onClick = onSelect, onClick = onSelect,
enabled = !disabled,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(64.dp), .height(64.dp),
colors = if (selected) ButtonDefaults.buttonColors( colors = if (selected) ButtonDefaults.buttonColors() else ButtonDefaults.textButtonColors(),
) else ButtonDefaults.textButtonColors(),
) { ) {
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,

View File

@ -57,19 +57,25 @@ fun MicrophoneSelection(
} }
val sheetState = rememberModalBottomSheetState() val sheetState = rememberModalBottomSheetState()
val allMicrophones = MicrophoneInfo.fetchDeviceMicrophones(context)
val visibleMicrophones = MicrophoneInfo.filterMicrophones(allMicrophones)
val hiddenMicrophones = allMicrophones - visibleMicrophones.toSet()
val dataStore = LocalContext.current.dataStore val dataStore = LocalContext.current.dataStore
val settings = dataStore val settings = dataStore
.data .data
.collectAsState(initial = AppSettings.getDefaultInstance()) .collectAsState(initial = AppSettings.getDefaultInstance())
.value .value
val allMicrophones = MicrophoneInfo.fetchDeviceMicrophones(context)
val visibleMicrophones = MicrophoneInfo.filterMicrophones(allMicrophones)
val hiddenMicrophones = allMicrophones - visibleMicrophones.toSet()
val isTryingToReconnect = val isTryingToReconnect =
audioRecorder.selectedMicrophone != null && audioRecorder.microphoneStatus == AudioRecorderModel.MicrophoneConnectivityStatus.DISCONNECTED audioRecorder.selectedMicrophone != null && audioRecorder.microphoneStatus == AudioRecorderModel.MicrophoneConnectivityStatus.DISCONNECTED
val shownMicrophones = if (isTryingToReconnect && visibleMicrophones.isEmpty()) {
listOf(audioRecorder.selectedMicrophone!!)
} else {
visibleMicrophones
}
if (showSelection) { if (showSelection) {
ModalBottomSheet( ModalBottomSheet(
onDismissRequest = { onDismissRequest = {
@ -95,8 +101,8 @@ fun MicrophoneSelection(
type = MessageType.INFO, type = MessageType.INFO,
message = stringResource( message = stringResource(
R.string.ui_audioRecorder_error_microphoneDisconnected_message, R.string.ui_audioRecorder_error_microphoneDisconnected_message,
audioRecorder.recorderService!!.selectedMicrophone?.name ?: "", audioRecorder.selectedMicrophone?.name ?: "",
audioRecorder.recorderService!!.selectedMicrophone?.name ?: "", audioRecorder.selectedMicrophone?.name ?: "",
) )
) )
@ -116,12 +122,13 @@ fun MicrophoneSelection(
) )
} }
items(visibleMicrophones.size) { items(shownMicrophones.size) {
val microphone = visibleMicrophones[it] val microphone = shownMicrophones[it]
MicrophoneSelectionButton( MicrophoneSelectionButton(
microphone = microphone, microphone = microphone,
selected = audioRecorder.selectedMicrophone == microphone, selected = audioRecorder.selectedMicrophone == microphone,
disabled = isTryingToReconnect && microphone == audioRecorder.selectedMicrophone,
onSelect = { onSelect = {
audioRecorder.changeMicrophone(microphone) audioRecorder.changeMicrophone(microphone)
showSelection = false showSelection = false
@ -174,7 +181,7 @@ fun MicrophoneSelection(
Box {} Box {}
} }
if (visibleMicrophones.isNotEmpty() || (settings.audioRecorderSettings.showAllMicrophones && hiddenMicrophones.isNotEmpty())) { if (shownMicrophones.isNotEmpty() || (settings.audioRecorderSettings.showAllMicrophones && hiddenMicrophones.isNotEmpty())) {
Button( Button(
onClick = { onClick = {
showSelection = true showSelection = true

View File

@ -32,7 +32,7 @@ fun MicrophoneStatus(
} }
LaunchedEffect(microphoneStatus) { LaunchedEffect(microphoneStatus) {
if (microphoneStatus != previousStatus && showMicrophoneStatusDialog == null && previousStatus != null) { if (microphoneStatus != previousStatus && showMicrophoneStatusDialog == null && previousStatus != null && audioRecorder.selectedMicrophone != null) {
showMicrophoneStatusDialog = microphoneStatus showMicrophoneStatusDialog = microphoneStatus
} }
} }