mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
feat: Add MicrophoneReconnectedDialog functionality
This commit is contained in:
parent
07757f34bb
commit
14abd1aee0
@ -155,7 +155,19 @@ class AudioRecorderService : IntervalRecorderService() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (addedDevices?.find { it.id == selectedMicrophone!!.deviceInfo.id } != null) {
|
||||
// We can't compare the ID, as it seems to be changing on each reconnect
|
||||
val newDevice = addedDevices?.find {
|
||||
it.productName == selectedMicrophone!!.deviceInfo.productName &&
|
||||
it.isSink == selectedMicrophone!!.deviceInfo.isSink &&
|
||||
it.type == selectedMicrophone!!.deviceInfo.type && (
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
it.address == selectedMicrophone!!.deviceInfo.address
|
||||
} else true
|
||||
)
|
||||
}
|
||||
if (newDevice != null) {
|
||||
changeMicrophone(MicrophoneInfo.fromDeviceInfo(newDevice))
|
||||
|
||||
onMicrophoneReconnected()
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ fun MicrophoneDisconnectedDialog(
|
||||
stringResource(
|
||||
R.string.ui_audioRecorder_error_microphoneDisconnected_message,
|
||||
microphoneName,
|
||||
microphoneName,
|
||||
)
|
||||
)
|
||||
},
|
||||
|
@ -0,0 +1,63 @@
|
||||
package app.myzel394.alibi.ui.components.AudioRecorder.atoms
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.MicOff
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import app.myzel394.alibi.R
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun MicrophoneReconnectedDialog(
|
||||
microphoneName: String,
|
||||
onClose: () -> Unit,
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onClose,
|
||||
title = {
|
||||
Text(
|
||||
stringResource(
|
||||
R.string.ui_audioRecorder_error_microphoneReconnected_title,
|
||||
),
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
stringResource(
|
||||
R.string.ui_audioRecorder_error_microphoneReconnected_message,
|
||||
microphoneName,
|
||||
)
|
||||
)
|
||||
},
|
||||
icon = {
|
||||
Icon(
|
||||
Icons.Default.Star,
|
||||
contentDescription = null,
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
val label = stringResource(R.string.dialog_close_neutral_label)
|
||||
|
||||
Button(
|
||||
modifier = Modifier
|
||||
.semantics {
|
||||
contentDescription = label
|
||||
},
|
||||
onClick = onClose,
|
||||
) {
|
||||
Text(label)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
@ -25,6 +25,7 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.DeleteButton
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.MicrophoneDisconnectedDialog
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.MicrophoneReconnectedDialog
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.PauseResumeButton
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.RealtimeAudioVisualizer
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.RecordingTime
|
||||
@ -166,6 +167,15 @@ fun RecordingStatus(
|
||||
)
|
||||
}
|
||||
|
||||
if (showMicrophoneStatusDialog == AudioRecorderModel.MicrophoneConnectivityStatus.CONNECTED) {
|
||||
MicrophoneReconnectedDialog(
|
||||
onClose = {
|
||||
showMicrophoneStatusDialog = null
|
||||
},
|
||||
microphoneName = audioRecorder.selectedMicrophone?.name ?: "",
|
||||
)
|
||||
}
|
||||
|
||||
if (microphones.isNotEmpty()) {
|
||||
MicrophoneSelection(
|
||||
microphones = microphones,
|
||||
|
@ -66,5 +66,7 @@
|
||||
<string name="ui_audioRecorder_info_microphone_deviceMicrophone">Device Microphone</string>
|
||||
<string name="ui_audioRecorder_info_microphone_changeExplanation">The selected microphone will be immediately activated</string>
|
||||
<string name="ui_audioRecorder_error_microphoneDisconnected_title">Microphone disconnected</string>
|
||||
<string name="ui_audioRecorder_error_microphoneDisconnected_message"><xliff:g name="name">%s</xliff:g> disconnected. Alibi will use the default microphone instead. We will automatically switch back to <xliff:g name="name">%s</xliff:g> once it reconnects.</string>
|
||||
<string name="ui_audioRecorder_error_microphoneDisconnected_message"><xliff:g name="name">%s</xliff:g> disconnected. Alibi will use the default microphone instead. We will automatically switch back to <xliff:g name="nam">%s</xliff:g> once it reconnects.</string>
|
||||
<string name="ui_audioRecorder_error_microphoneReconnected_title">Microphone reconnected</string>
|
||||
<string name="ui_audioRecorder_error_microphoneReconnected_message"><xliff:g name="name">%s</xliff:g> reconnected! Alibi automatically changed the microphone input to it.</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user