mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
feat: Allow user to select default microphone if selected on disconnected
This commit is contained in:
parent
d559fb45a5
commit
8fd57aace3
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user