-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
262 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...in/java/app/myzel394/alibi/ui/components/AudioRecorder/atoms/MicrophoneSelectionButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package app.myzel394.alibi.ui.components.AudioRecorder.atoms | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.ColumnScope | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.ButtonDefaults | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import app.myzel394.alibi.ui.utils.MicrophoneInfo | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.res.stringResource | ||
import app.myzel394.alibi.R | ||
|
||
@Composable | ||
fun MicrophoneSelectionButton( | ||
microphone: MicrophoneInfo? = null, | ||
selected: Boolean = false, | ||
onSelect: () -> Unit, | ||
) { | ||
Button( | ||
onClick = onSelect, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height(64.dp), | ||
colors = if (selected) ButtonDefaults.buttonColors( | ||
) else ButtonDefaults.textButtonColors(), | ||
) { | ||
MicrophoneTypeInfo( | ||
type = microphone?.type ?: MicrophoneInfo.MicrophoneType.PHONE, | ||
modifier = Modifier.size(ButtonDefaults.IconSize), | ||
) | ||
Spacer(modifier = Modifier.width(ButtonDefaults.IconSpacing)) | ||
Text( | ||
text = microphone?.name | ||
?: stringResource(R.string.ui_audioRecorder_info_microphone_deviceMicrophone), | ||
fontSize = MaterialTheme.typography.bodyLarge.fontSize, | ||
) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/app/myzel394/alibi/ui/components/AudioRecorder/atoms/MicrophoneTypeIcon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package app.myzel394.alibi.ui.components.AudioRecorder.atoms | ||
|
||
import android.R | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.BluetoothAudio | ||
import androidx.compose.material.icons.filled.Memory | ||
import androidx.compose.material.icons.filled.Mic | ||
import androidx.compose.material.icons.filled.MicExternalOn | ||
import androidx.compose.material.icons.filled.Settings | ||
import androidx.compose.material.icons.filled.Smartphone | ||
import androidx.compose.material.icons.filled.Warning | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import app.myzel394.alibi.ui.utils.MicrophoneInfo | ||
|
||
@Composable | ||
fun MicrophoneTypeInfo( | ||
modifier: Modifier = Modifier, | ||
type: MicrophoneInfo.MicrophoneType, | ||
) { | ||
Icon( | ||
imageVector = when (type) { | ||
MicrophoneInfo.MicrophoneType.BLUETOOTH -> Icons.Filled.BluetoothAudio | ||
MicrophoneInfo.MicrophoneType.WIRED -> Icons.Filled.MicExternalOn | ||
MicrophoneInfo.MicrophoneType.PHONE -> Icons.Filled.Smartphone | ||
MicrophoneInfo.MicrophoneType.OTHER -> Icons.Filled.Mic | ||
}, | ||
modifier = modifier, | ||
contentDescription = null, | ||
) | ||
} |
115 changes: 115 additions & 0 deletions
115
...main/java/app/myzel394/alibi/ui/components/AudioRecorder/molecules/MicrophoneSelection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package app.myzel394.alibi.ui.components.AudioRecorder.molecules | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.ButtonDefaults | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.ModalBottomSheet | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import app.myzel394.alibi.R | ||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.MicrophoneSelectionButton | ||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.MicrophoneTypeInfo | ||
import app.myzel394.alibi.ui.models.AudioRecorderModel | ||
import app.myzel394.alibi.ui.utils.MicrophoneInfo | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun MicrophoneSelection( | ||
audioRecorder: AudioRecorderModel, | ||
microphones: List<MicrophoneInfo>, | ||
) { | ||
var showSelection by rememberSaveable { | ||
mutableStateOf(false) | ||
} | ||
|
||
if (showSelection) { | ||
ModalBottomSheet( | ||
onDismissRequest = { | ||
showSelection = false | ||
} | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.padding(horizontal = 16.dp) | ||
.padding(bottom = 24.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.spacedBy(48.dp), | ||
) { | ||
Text( | ||
stringResource(R.string.ui_audioRecorder_info_microphone_changeExplanation), | ||
style = MaterialTheme.typography.bodySmall, | ||
textAlign = TextAlign.Center, | ||
) | ||
|
||
LazyColumn( | ||
modifier = Modifier | ||
.padding(horizontal = 32.dp), | ||
verticalArrangement = Arrangement.spacedBy(8.dp), | ||
) { | ||
item { | ||
MicrophoneSelectionButton( | ||
selected = audioRecorder.recorderService!!.selectedDevice == null, | ||
onSelect = { | ||
audioRecorder.changeMicrophone(null) | ||
showSelection = false | ||
} | ||
) | ||
} | ||
|
||
items(microphones.size) { | ||
val microphone = microphones[it] | ||
|
||
MicrophoneSelectionButton( | ||
microphone = microphone, | ||
selected = audioRecorder.recorderService!!.selectedDevice == microphone, | ||
onSelect = { | ||
audioRecorder.changeMicrophone(microphone) | ||
showSelection = false | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
Button( | ||
onClick = { | ||
showSelection = true | ||
}, | ||
colors = ButtonDefaults.textButtonColors(), | ||
) { | ||
MicrophoneTypeInfo( | ||
type = audioRecorder.recorderService!!.selectedDevice?.type | ||
?: MicrophoneInfo.MicrophoneType.PHONE, | ||
modifier = Modifier.size(ButtonDefaults.IconSize), | ||
) | ||
Spacer(modifier = Modifier.width(ButtonDefaults.IconSpacing)) | ||
Text( | ||
text = audioRecorder.recorderService!!.selectedDevice.let { | ||
it?.name | ||
?: stringResource(R.string.ui_audioRecorder_info_microphone_deviceMicrophone) | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.