New version of audio screen refactoring

This commit is contained in:
Juha Heinanen
2026-07-03 09:20:15 +03:00
parent 20cda1e231
commit c1b56df7d2

View File

@ -74,9 +74,7 @@ fun NavGraphBuilder.audioScreenRoute(
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()
@ -95,10 +93,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,
@ -164,19 +159,20 @@ private fun AudioContent(contentPadding: PaddingValues) {
oldSpeakerPhone = Config.variable("speaker_phone") == "yes" oldSpeakerPhone = Config.variable("speaker_phone") == "yes"
newSpeakerPhone = oldSpeakerPhone newSpeakerPhone = oldSpeakerPhone
oldAudioModules = Config.variables("module") oldAudioModules = Config.variables("module")
for (module in Config.audioModules)
newAudioModules[module] = oldAudioModules.contains("${module}.so")
oldOpusBitrate = Config.variable("opus_bitrate") oldOpusBitrate = Config.variable("opus_bitrate")
oldOpusPacketLoss = Config.variable("opus_packet_loss") oldOpusPacketLoss = Config.variable("opus_packet_loss")
if (!BaresipService.agcAvailable) if (!BaresipService.agcAvailable)
oldMicGain = Config.variable("augain") oldMicGain = Config.variable("augain")
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()
@ -270,20 +266,23 @@ private fun ToneCountry() {
val toneCountryTitle = stringResource(R.string.tone_country) val toneCountryTitle = stringResource(R.string.tone_country)
val toneCountryHelp = stringResource(R.string.tone_country_help) val toneCountryHelp = stringResource(R.string.tone_country_help)
Text(text = toneCountryTitle, Text(text = toneCountryTitle,
modifier = Modifier.weight(1f) modifier = Modifier
.weight(1f)
.clickable { .clickable {
alertTitle.value = toneCountryTitle alertTitle.value = toneCountryTitle
alertMessage.value = toneCountryHelp alertMessage.value = toneCountryHelp
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 { val itemPosition = remember {
mutableIntStateOf(countryValues.indexOf(BaresipService.toneCountry)) val index = countryValues.indexOf(BaresipService.toneCountry)
mutableIntStateOf(if (index != -1) index else countryValues.indexOf("us"))
} }
Box { Box {
Row( Row(
@ -302,9 +301,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) },
@ -312,7 +310,8 @@ private fun ToneCountry() {
isDropDownExpanded.value = false isDropDownExpanded.value = false
itemPosition.intValue = index itemPosition.intValue = index
newToneCountry = countryValues[index] newToneCountry = countryValues[index]
}) }
)
if (index < 10) if (index < 10)
HorizontalDivider(thickness = 1.dp) HorizontalDivider(thickness = 1.dp)
} }
@ -331,17 +330,20 @@ 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
showAlert.value = true showAlert.value = true
}, },
fontSize = 18.sp) fontSize = 18.sp
)
var speakerPhone by remember { mutableStateOf(oldSpeakerPhone) } var speakerPhone by remember { mutableStateOf(oldSpeakerPhone) }
Switch( Switch(
checked = speakerPhone, checked = speakerPhone,
onCheckedChange = { speakerPhone = it onCheckedChange = {
speakerPhone = it
newSpeakerPhone = speakerPhone newSpeakerPhone = speakerPhone
} }
) )
@ -364,14 +366,14 @@ private fun CallVolume() {
alertMessage.value = defaultCallVolumeHelp alertMessage.value = defaultCallVolumeHelp
showAlert.value = true showAlert.value = true
}, },
fontSize = 18.sp) fontSize = 18.sp
val isDropDownExpanded = remember { )
mutableStateOf(false) val isDropDownExpanded = remember { 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 { val itemPosition = remember {
mutableIntStateOf(volValues.indexOf(BaresipService.callVolume)) val index = volValues.indexOf(BaresipService.callVolume)
mutableIntStateOf(if (index != -1) index else 0)
} }
Box { Box {
Row( Row(
@ -390,9 +392,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) },
@ -424,7 +425,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
@ -575,6 +577,7 @@ private fun AudioDelay() {
private fun checkOnClick(ctx: Context): Result { private fun checkOnClick(ctx: Context): Result {
var restart = false var restart = false
save = false
if (Preferences(ctx).ringtoneUri != newRingtoneUri) { if (Preferences(ctx).ringtoneUri != newRingtoneUri) {
Preferences(ctx).ringtoneUri = newRingtoneUri Preferences(ctx).ringtoneUri = newRingtoneUri
@ -646,7 +649,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)
@ -701,11 +705,11 @@ private fun checkOnClick(ctx: Context): Result {
private fun checkMicGain(micGain: String): Boolean { private fun checkMicGain(micGain: String): Boolean {
val number = val number =
try { try {
micGain.toDouble() micGain.toDouble()
} catch (_: NumberFormatException) { } catch (_: NumberFormatException) {
return false return false
} }
return number >= 1.0 return number >= 1.0
} }