Code styling improvements

This commit is contained in:
Juha Heinanen
2026-07-02 21:21:44 +03:00
parent 7ca288060c
commit 0b86daddf8

View File

@ -69,15 +69,11 @@ enum class Result {
OK, ERROR, RESTART OK, ERROR, RESTART
} }
fun NavGraphBuilder.audioScreenRoute( fun NavGraphBuilder.audioScreenRoute(navController: NavController) {
navController: NavController,
) {
composable("audio") { composable("audio") {
val ctx = LocalContext.current val ctx = LocalContext.current
AudioScreen( AudioScreen(
onBack = { onBack = { navController.navigateUp() },
navController.navigateUp()
},
checkOnClick = { checkOnClick = {
when (checkOnClick(ctx)) { when (checkOnClick(ctx)) {
Result.OK -> navController.navigateUp() Result.OK -> navController.navigateUp()
@ -96,10 +92,7 @@ fun NavGraphBuilder.audioScreenRoute(
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
private fun AudioScreen( private fun AudioScreen(onBack: () -> Unit, checkOnClick: () -> Unit) {
onBack: () -> Unit,
checkOnClick: () -> Unit,
) {
Scaffold( Scaffold(
modifier = Modifier.fillMaxSize().imePadding(), modifier = Modifier.fillMaxSize().imePadding(),
containerColor = MaterialTheme.colorScheme.background, containerColor = MaterialTheme.colorScheme.background,
@ -129,7 +122,7 @@ private fun AudioScreen(
IconButton(onClick = checkOnClick) { IconButton(onClick = checkOnClick) {
Icon(imageVector = Icons.Filled.Check, contentDescription = "Check") Icon(imageVector = Icons.Filled.Check, contentDescription = "Check")
} }
}, }
) )
} }
} }
@ -186,14 +179,13 @@ private fun AudioContent(contentPadding: PaddingValues) {
Preferences(ctx).ringtoneUri!! Preferences(ctx).ringtoneUri!!
} }
if (showAlert.value) { if (showAlert.value)
AlertDialog( AlertDialog(
showDialog = showAlert, showDialog = showAlert,
title = alertTitle.value, title = alertTitle.value,
message = alertMessage.value, message = alertMessage.value,
lastButtonText = stringResource(R.string.ok), lastButtonText = stringResource(R.string.ok),
) )
}
val scrollState = rememberScrollState() val scrollState = rememberScrollState()
@ -222,7 +214,6 @@ private fun AudioContent(contentPadding: PaddingValues) {
private fun Ringtone() { private fun Ringtone() {
val ringToneTitle = stringResource(R.string.ringtone) val ringToneTitle = stringResource(R.string.ringtone)
val selectRingToneMessage = stringResource(R.string.select_ringtone) val selectRingToneMessage = stringResource(R.string.select_ringtone)
val ctx = LocalContext.current
var ringtoneUri by remember(newRingtoneUri) { var ringtoneUri by remember(newRingtoneUri) {
mutableStateOf(newRingtoneUri) mutableStateOf(newRingtoneUri)
} }
@ -291,9 +282,7 @@ private fun ToneCountry() {
showAlert.value = true showAlert.value = true
}, },
fontSize = 18.sp) fontSize = 18.sp)
val isDropDownExpanded = remember { val isDropDownExpanded = remember { mutableStateOf(false) }
mutableStateOf(false)
}
val countryNames = arrayListOf("BG", "BR", "DE", "CZ", "ES", "FI", "FR", "GB", "JP", "NO", "NZ", "SE", "RU", "US") val countryNames = arrayListOf("BG", "BR", "DE", "CZ", "ES", "FI", "FR", "GB", "JP", "NO", "NZ", "SE", "RU", "US")
val countryValues = arrayListOf("bg", "br", "de", "cz", "es", "fi", "fr", "uk", "jp", "no", "nz", "se", "ru", "us") val countryValues = arrayListOf("bg", "br", "de", "cz", "es", "fi", "fr", "uk", "jp", "no", "nz", "se", "ru", "us")
val itemPosition = remember(newToneCountry) { val itemPosition = remember(newToneCountry) {
@ -316,9 +305,8 @@ private fun ToneCountry() {
} }
DropdownMenu( DropdownMenu(
expanded = isDropDownExpanded.value, expanded = isDropDownExpanded.value,
onDismissRequest = { onDismissRequest = { isDropDownExpanded.value = false }
isDropDownExpanded.value = false ) {
}) {
countryNames.forEachIndexed { index, name -> countryNames.forEachIndexed { index, name ->
DropdownMenuItem( DropdownMenuItem(
text = { Text(text = name) }, text = { Text(text = name) },
@ -345,7 +333,8 @@ private fun SpeakerPhone() {
val speakerPhoneTitle = stringResource(R.string.speaker_phone) val speakerPhoneTitle = stringResource(R.string.speaker_phone)
val speakerPhoneHelp = stringResource(R.string.speaker_phone_help) val speakerPhoneHelp = stringResource(R.string.speaker_phone_help)
Text(text = speakerPhoneTitle, Text(text = speakerPhoneTitle,
modifier = Modifier.weight(1f) modifier = Modifier
.weight(1f)
.clickable { .clickable {
alertTitle.value = speakerPhoneTitle alertTitle.value = speakerPhoneTitle
alertMessage.value = speakerPhoneHelp alertMessage.value = speakerPhoneHelp
@ -355,7 +344,8 @@ private fun SpeakerPhone() {
var speakerPhone by remember(oldSpeakerPhone) { mutableStateOf(oldSpeakerPhone) } var speakerPhone by remember(oldSpeakerPhone) { mutableStateOf(oldSpeakerPhone) }
Switch( Switch(
checked = speakerPhone, checked = speakerPhone,
onCheckedChange = { speakerPhone = it onCheckedChange = {
speakerPhone = it
newSpeakerPhone = speakerPhone newSpeakerPhone = speakerPhone
} }
) )
@ -379,9 +369,7 @@ private fun CallVolume() {
showAlert.value = true showAlert.value = true
}, },
fontSize = 18.sp) fontSize = 18.sp)
val isDropDownExpanded = remember { val isDropDownExpanded = remember { mutableStateOf(false) }
mutableStateOf(false)
}
val volNames = listOf("--", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10") val volNames = listOf("--", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10")
val volValues = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) val volValues = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val itemPosition = remember(newCallVolume) { val itemPosition = remember(newCallVolume) {
@ -391,9 +379,7 @@ private fun CallVolume() {
Row( Row(
horizontalArrangement = Arrangement.Center, horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clickable { modifier = Modifier.clickable { isDropDownExpanded.value = true }
isDropDownExpanded.value = true
}
) { ) {
Text(text = volNames[itemPosition.intValue]) Text(text = volNames[itemPosition.intValue])
Icon( Icon(
@ -404,9 +390,8 @@ private fun CallVolume() {
} }
DropdownMenu( DropdownMenu(
expanded = isDropDownExpanded.value, expanded = isDropDownExpanded.value,
onDismissRequest = { onDismissRequest = { isDropDownExpanded.value = false }
isDropDownExpanded.value = false ) {
}) {
volNames.forEachIndexed { index, vol -> volNames.forEachIndexed { index, vol ->
DropdownMenuItem( DropdownMenuItem(
text = { Text(text = vol) }, text = { Text(text = vol) },
@ -438,7 +423,8 @@ private fun MicGain() {
OutlinedTextField( OutlinedTextField(
value = micGain, value = micGain,
placeholder = { Text(microphoneGainTitle) }, placeholder = { Text(microphoneGainTitle) },
onValueChange = { micGain = it onValueChange = {
micGain = it
newMicGain = micGain newMicGain = micGain
}, },
modifier = Modifier modifier = Modifier
@ -595,7 +581,6 @@ private fun checkOnClick(ctx: Context): Result {
BaresipService.rt = RingtoneManager.getRingtone(ctx, newRingtoneUri.toUri()) BaresipService.rt = RingtoneManager.getRingtone(ctx, newRingtoneUri.toUri())
} }
if (BaresipService.toneCountry != newToneCountry) { if (BaresipService.toneCountry != newToneCountry) {
BaresipService.toneCountry = newToneCountry BaresipService.toneCountry = newToneCountry
Config.replaceVariable("tone_country", newToneCountry) Config.replaceVariable("tone_country", newToneCountry)
@ -660,7 +645,8 @@ private fun checkOnClick(ctx: Context): Result {
Config.addVariable("module", "${module}.so") Config.addVariable("module", "${module}.so")
save = true save = true
} }
} else if (oldAudioModules.contains("${module}.so")) { }
else if (oldAudioModules.contains("${module}.so")) {
Api.module_unload("${module}.so") Api.module_unload("${module}.so")
Config.removeVariableValue("module", "${module}.so") Config.removeVariableValue("module", "${module}.so")
for (ua in BaresipService.uas.value) for (ua in BaresipService.uas.value)