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

View File

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

View File

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