feat: Add MicrophoneReconnectedDialog functionality

This commit is contained in:
Myzel394 2023-10-21 21:37:03 +02:00
parent 07757f34bb
commit 14abd1aee0
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
5 changed files with 90 additions and 2 deletions

View File

@ -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()
}
}

View File

@ -36,6 +36,7 @@ fun MicrophoneDisconnectedDialog(
stringResource(
R.string.ui_audioRecorder_error_microphoneDisconnected_message,
microphoneName,
microphoneName,
)
)
},

View File

@ -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)
}
}
)
}

View File

@ -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,

View File

@ -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>