Reverted changes to audio screen
This commit is contained in:
@@ -44,7 +44,6 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@@ -69,11 +68,15 @@ enum class Result {
|
|||||||
OK, ERROR, RESTART
|
OK, ERROR, RESTART
|
||||||
}
|
}
|
||||||
|
|
||||||
fun NavGraphBuilder.audioScreenRoute(navController: NavController) {
|
fun NavGraphBuilder.audioScreenRoute(
|
||||||
|
navController: NavController,
|
||||||
|
) {
|
||||||
composable("audio") {
|
composable("audio") {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
AudioScreen(
|
AudioScreen(
|
||||||
onBack = { navController.navigateUp() },
|
onBack = {
|
||||||
|
navController.navigateUp()
|
||||||
|
},
|
||||||
checkOnClick = {
|
checkOnClick = {
|
||||||
when (checkOnClick(ctx)) {
|
when (checkOnClick(ctx)) {
|
||||||
Result.OK -> navController.navigateUp()
|
Result.OK -> navController.navigateUp()
|
||||||
@@ -92,7 +95,10 @@ fun NavGraphBuilder.audioScreenRoute(navController: NavController) {
|
|||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun AudioScreen(onBack: () -> Unit, checkOnClick: () -> Unit) {
|
private fun AudioScreen(
|
||||||
|
onBack: () -> Unit,
|
||||||
|
checkOnClick: () -> Unit,
|
||||||
|
) {
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = Modifier.fillMaxSize().imePadding(),
|
modifier = Modifier.fillMaxSize().imePadding(),
|
||||||
containerColor = MaterialTheme.colorScheme.background,
|
containerColor = MaterialTheme.colorScheme.background,
|
||||||
@@ -122,7 +128,7 @@ private fun AudioScreen(onBack: () -> Unit, checkOnClick: () -> Unit) {
|
|||||||
IconButton(onClick = checkOnClick) {
|
IconButton(onClick = checkOnClick) {
|
||||||
Icon(imageVector = Icons.Filled.Check, contentDescription = "Check")
|
Icon(imageVector = Icons.Filled.Check, contentDescription = "Check")
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,19 +137,19 @@ private fun AudioScreen(onBack: () -> Unit, checkOnClick: () -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var newCallVolume = 0
|
private var newCallVolume = BaresipService.callVolume
|
||||||
private var oldMicGain = ""
|
private var oldMicGain = ""
|
||||||
private var newMicGain = ""
|
private var newMicGain = ""
|
||||||
private var oldSpeakerPhone = false
|
private var oldSpeakerPhone = BaresipService.speakerPhone
|
||||||
private var newSpeakerPhone = false
|
private var newSpeakerPhone = oldSpeakerPhone
|
||||||
private var oldAudioModules = ArrayList<String>()
|
private var oldAudioModules = ArrayList<String>()
|
||||||
private var newAudioModules = mutableMapOf<String, Boolean>()
|
private var newAudioModules = mutableMapOf<String, Boolean>()
|
||||||
private var oldOpusBitrate = ""
|
private var oldOpusBitrate = ""
|
||||||
private var newOpusBitrate = ""
|
private var newOpusBitrate = oldOpusBitrate
|
||||||
private var oldOpusPacketLoss = ""
|
private var oldOpusPacketLoss = ""
|
||||||
private var newOpusPacketLoss = ""
|
private var newOpusPacketLoss = oldOpusPacketLoss
|
||||||
private var newAudioDelay = ""
|
private var newAudioDelay = BaresipService.audioDelay.toString()
|
||||||
private var newToneCountry = ""
|
private var newToneCountry = BaresipService.toneCountry
|
||||||
private var newRingtoneUri = ""
|
private var newRingtoneUri = ""
|
||||||
|
|
||||||
private var save = false
|
private var save = false
|
||||||
@@ -155,37 +161,22 @@ private val showAlert = mutableStateOf(false)
|
|||||||
@Composable
|
@Composable
|
||||||
private fun AudioContent(contentPadding: PaddingValues) {
|
private fun AudioContent(contentPadding: PaddingValues) {
|
||||||
|
|
||||||
val ctx = LocalContext.current
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
save = false
|
|
||||||
oldSpeakerPhone = Config.variable("speaker_phone") == "yes"
|
oldSpeakerPhone = Config.variable("speaker_phone") == "yes"
|
||||||
newSpeakerPhone = oldSpeakerPhone
|
newSpeakerPhone = oldSpeakerPhone
|
||||||
oldAudioModules = Config.variables("module")
|
oldAudioModules = Config.variables("module")
|
||||||
newAudioModules.clear()
|
|
||||||
oldOpusBitrate = Config.variable("opus_bitrate")
|
oldOpusBitrate = Config.variable("opus_bitrate")
|
||||||
newOpusBitrate = oldOpusBitrate
|
|
||||||
oldOpusPacketLoss = Config.variable("opus_packet_loss")
|
oldOpusPacketLoss = Config.variable("opus_packet_loss")
|
||||||
newOpusPacketLoss = oldOpusPacketLoss
|
|
||||||
if (!BaresipService.agcAvailable)
|
if (!BaresipService.agcAvailable)
|
||||||
oldMicGain = Config.variable("augain")
|
oldMicGain = Config.variable("augain")
|
||||||
newMicGain = oldMicGain
|
|
||||||
newCallVolume = BaresipService.callVolume
|
|
||||||
newAudioDelay = BaresipService.audioDelay.toString()
|
|
||||||
newToneCountry = BaresipService.toneCountry
|
|
||||||
newRingtoneUri = if (Preferences(ctx).ringtoneUri == "")
|
|
||||||
RingtoneManager.getActualDefaultRingtoneUri(ctx, RingtoneManager.TYPE_RINGTONE).toString()
|
|
||||||
else
|
|
||||||
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()
|
||||||
|
|
||||||
@@ -214,8 +205,12 @@ 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)
|
||||||
var ringtoneUri by remember(newRingtoneUri) {
|
val ctx = LocalContext.current
|
||||||
mutableStateOf(newRingtoneUri)
|
var ringtoneUri by remember {
|
||||||
|
mutableStateOf(if (Preferences(ctx).ringtoneUri == "")
|
||||||
|
RingtoneManager.getActualDefaultRingtoneUri(ctx, RingtoneManager.TYPE_RINGTONE).toString()
|
||||||
|
else
|
||||||
|
Preferences(ctx).ringtoneUri!!)
|
||||||
}
|
}
|
||||||
newRingtoneUri = ringtoneUri
|
newRingtoneUri = ringtoneUri
|
||||||
val launcher = rememberLauncherForActivityResult(
|
val launcher = rememberLauncherForActivityResult(
|
||||||
@@ -282,11 +277,13 @@ private fun ToneCountry() {
|
|||||||
showAlert.value = true
|
showAlert.value = true
|
||||||
},
|
},
|
||||||
fontSize = 18.sp)
|
fontSize = 18.sp)
|
||||||
val isDropDownExpanded = remember { mutableStateOf(false) }
|
val isDropDownExpanded = remember {
|
||||||
|
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 {
|
||||||
mutableIntStateOf(countryValues.indexOf(newToneCountry))
|
mutableIntStateOf(countryValues.indexOf(BaresipService.toneCountry))
|
||||||
}
|
}
|
||||||
Box {
|
Box {
|
||||||
Row(
|
Row(
|
||||||
@@ -305,8 +302,9 @@ private fun ToneCountry() {
|
|||||||
}
|
}
|
||||||
DropdownMenu(
|
DropdownMenu(
|
||||||
expanded = isDropDownExpanded.value,
|
expanded = isDropDownExpanded.value,
|
||||||
onDismissRequest = { isDropDownExpanded.value = false }
|
onDismissRequest = {
|
||||||
) {
|
isDropDownExpanded.value = false
|
||||||
|
}) {
|
||||||
countryNames.forEachIndexed { index, name ->
|
countryNames.forEachIndexed { index, name ->
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text(text = name) },
|
text = { Text(text = name) },
|
||||||
@@ -333,19 +331,17 @@ 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
|
modifier = Modifier.weight(1f)
|
||||||
.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(oldSpeakerPhone) { mutableStateOf(oldSpeakerPhone) }
|
var speakerPhone by remember { mutableStateOf(oldSpeakerPhone) }
|
||||||
Switch(
|
Switch(
|
||||||
checked = speakerPhone,
|
checked = speakerPhone,
|
||||||
onCheckedChange = {
|
onCheckedChange = { speakerPhone = it
|
||||||
speakerPhone = it
|
|
||||||
newSpeakerPhone = speakerPhone
|
newSpeakerPhone = speakerPhone
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -369,17 +365,21 @@ private fun CallVolume() {
|
|||||||
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(newCallVolume) {
|
val itemPosition = remember {
|
||||||
mutableIntStateOf(volValues.indexOf(newCallVolume))
|
mutableIntStateOf(volValues.indexOf(BaresipService.callVolume))
|
||||||
}
|
}
|
||||||
Box {
|
Box {
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.clickable { isDropDownExpanded.value = true }
|
modifier = Modifier.clickable {
|
||||||
|
isDropDownExpanded.value = true
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
Text(text = volNames[itemPosition.intValue])
|
Text(text = volNames[itemPosition.intValue])
|
||||||
Icon(
|
Icon(
|
||||||
@@ -390,8 +390,9 @@ private fun CallVolume() {
|
|||||||
}
|
}
|
||||||
DropdownMenu(
|
DropdownMenu(
|
||||||
expanded = isDropDownExpanded.value,
|
expanded = isDropDownExpanded.value,
|
||||||
onDismissRequest = { isDropDownExpanded.value = false }
|
onDismissRequest = {
|
||||||
) {
|
isDropDownExpanded.value = false
|
||||||
|
}) {
|
||||||
volNames.forEachIndexed { index, vol ->
|
volNames.forEachIndexed { index, vol ->
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text(text = vol) },
|
text = { Text(text = vol) },
|
||||||
@@ -418,13 +419,12 @@ private fun MicGain() {
|
|||||||
) {
|
) {
|
||||||
val microphoneGainTitle = stringResource(R.string.microphone_gain)
|
val microphoneGainTitle = stringResource(R.string.microphone_gain)
|
||||||
val microphoneGainHelp = stringResource(R.string.microphone_gain_help)
|
val microphoneGainHelp = stringResource(R.string.microphone_gain_help)
|
||||||
var micGain by remember(oldMicGain) { mutableStateOf(oldMicGain) }
|
var micGain by remember { mutableStateOf(oldMicGain) }
|
||||||
newMicGain = micGain
|
newMicGain = micGain
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = micGain,
|
value = micGain,
|
||||||
placeholder = { Text(microphoneGainTitle) },
|
placeholder = { Text(microphoneGainTitle) },
|
||||||
onValueChange = {
|
onValueChange = { micGain = it
|
||||||
micGain = it
|
|
||||||
newMicGain = micGain
|
newMicGain = micGain
|
||||||
},
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -463,7 +463,7 @@ private fun AudioModules() {
|
|||||||
) {
|
) {
|
||||||
Text(text = String.format(stringResource(R.string.bullet_item), module), fontSize = 18.sp)
|
Text(text = String.format(stringResource(R.string.bullet_item), module), fontSize = 18.sp)
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
var checked by remember(oldAudioModules) { mutableStateOf(oldAudioModules.contains("${module}.so")) }
|
var checked by remember { mutableStateOf(oldAudioModules.contains("${module}.so")) }
|
||||||
Switch(
|
Switch(
|
||||||
checked = checked,
|
checked = checked,
|
||||||
onCheckedChange = {
|
onCheckedChange = {
|
||||||
@@ -485,7 +485,7 @@ private fun OpusBitRate() {
|
|||||||
) {
|
) {
|
||||||
val opusBitRateTitle = stringResource(R.string.opus_bit_rate)
|
val opusBitRateTitle = stringResource(R.string.opus_bit_rate)
|
||||||
val opusBitRateHelp = stringResource(R.string.opus_bit_rate_help)
|
val opusBitRateHelp = stringResource(R.string.opus_bit_rate_help)
|
||||||
var opusBitrate by remember(oldOpusBitrate) { mutableStateOf(oldOpusBitrate) }
|
var opusBitrate by remember { mutableStateOf(oldOpusBitrate) }
|
||||||
newOpusBitrate = opusBitrate
|
newOpusBitrate = opusBitrate
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = opusBitrate,
|
value = opusBitrate,
|
||||||
@@ -517,7 +517,7 @@ private fun OpusPacketLoss() {
|
|||||||
) {
|
) {
|
||||||
val opusPacketLossTitle = stringResource(R.string.opus_packet_loss)
|
val opusPacketLossTitle = stringResource(R.string.opus_packet_loss)
|
||||||
val opusPacketLossHelp = stringResource(R.string.opus_packet_loss_help)
|
val opusPacketLossHelp = stringResource(R.string.opus_packet_loss_help)
|
||||||
var opusPacketLoss by remember(oldOpusPacketLoss) { mutableStateOf(oldOpusPacketLoss) }
|
var opusPacketLoss by remember { mutableStateOf(oldOpusPacketLoss) }
|
||||||
newOpusPacketLoss = opusPacketLoss
|
newOpusPacketLoss = opusPacketLoss
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = opusPacketLoss,
|
value = opusPacketLoss,
|
||||||
@@ -549,7 +549,7 @@ private fun AudioDelay() {
|
|||||||
) {
|
) {
|
||||||
val audioDelayTitle = stringResource(R.string.audio_delay)
|
val audioDelayTitle = stringResource(R.string.audio_delay)
|
||||||
val audioDelayHelp = stringResource(R.string.audio_delay_help)
|
val audioDelayHelp = stringResource(R.string.audio_delay_help)
|
||||||
var audioDelay by remember(newAudioDelay) { mutableStateOf(newAudioDelay) }
|
var audioDelay by remember { mutableStateOf(BaresipService.audioDelay.toString()) }
|
||||||
newAudioDelay = audioDelay
|
newAudioDelay = audioDelay
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = audioDelay,
|
value = audioDelay,
|
||||||
@@ -581,6 +581,7 @@ 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)
|
||||||
@@ -645,8 +646,7 @@ 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)
|
||||||
@@ -723,4 +723,3 @@ private fun checkAudioDelay(audioDelay: String): Boolean {
|
|||||||
val number = audioDelay.toIntOrNull() ?: return false
|
val number = audioDelay.toIntOrNull() ?: return false
|
||||||
return (number >= 100) && (number <= 3000)
|
return (number >= 100) && (number <= 3000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user