Improved Audio Settings check
This commit is contained in:
@@ -57,6 +57,10 @@ import androidx.navigation.compose.composable
|
|||||||
import com.tutpro.baresip.CustomElements.AlertDialog
|
import com.tutpro.baresip.CustomElements.AlertDialog
|
||||||
import com.tutpro.baresip.CustomElements.verticalScrollbar
|
import com.tutpro.baresip.CustomElements.verticalScrollbar
|
||||||
|
|
||||||
|
enum class Result {
|
||||||
|
OK, ERROR, RESTART
|
||||||
|
}
|
||||||
|
|
||||||
fun NavGraphBuilder.audioScreenRoute(
|
fun NavGraphBuilder.audioScreenRoute(
|
||||||
navController: NavController,
|
navController: NavController,
|
||||||
) {
|
) {
|
||||||
@@ -67,11 +71,16 @@ fun NavGraphBuilder.audioScreenRoute(
|
|||||||
navController.navigateUp()
|
navController.navigateUp()
|
||||||
},
|
},
|
||||||
checkOnClick = {
|
checkOnClick = {
|
||||||
val result = checkOnClick(ctx)
|
when (checkOnClick(ctx)) {
|
||||||
|
Result.OK -> navController.navigateUp()
|
||||||
|
Result.RESTART -> {
|
||||||
navController.previousBackStackEntry
|
navController.previousBackStackEntry
|
||||||
?.savedStateHandle
|
?.savedStateHandle
|
||||||
?.set("audio_settings_result", result)
|
?.set("audio_settings_result", true)
|
||||||
navController.navigateUp()
|
navController.navigateUp()
|
||||||
|
}
|
||||||
|
Result.ERROR -> {}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -509,7 +518,7 @@ private fun ToneCountry() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkOnClick(ctx: Context): Boolean {
|
private fun checkOnClick(ctx: Context): Result {
|
||||||
|
|
||||||
var restart = false
|
var restart = false
|
||||||
|
|
||||||
@@ -528,7 +537,7 @@ private fun checkOnClick(ctx: Context): Boolean {
|
|||||||
alertTitle.value = ctx.getString(R.string.notice)
|
alertTitle.value = ctx.getString(R.string.notice)
|
||||||
alertMessage.value = "${ctx.getString(R.string.invalid_microphone_gain)}: $gain."
|
alertMessage.value = "${ctx.getString(R.string.invalid_microphone_gain)}: $gain."
|
||||||
showAlert.value = true
|
showAlert.value = true
|
||||||
return false
|
return Result.ERROR
|
||||||
}
|
}
|
||||||
if (gain == "1.0") {
|
if (gain == "1.0") {
|
||||||
Api.module_unload("augain")
|
Api.module_unload("augain")
|
||||||
@@ -540,7 +549,7 @@ private fun checkOnClick(ctx: Context): Boolean {
|
|||||||
alertTitle.value = ctx.getString(R.string.error)
|
alertTitle.value = ctx.getString(R.string.error)
|
||||||
alertMessage.value = ctx.getString(R.string.failed_to_load_module) + ": augain.so"
|
alertMessage.value = ctx.getString(R.string.failed_to_load_module) + ": augain.so"
|
||||||
showAlert.value = true
|
showAlert.value = true
|
||||||
return false
|
return Result.ERROR
|
||||||
}
|
}
|
||||||
Config.addVariable("module", "augain.so")
|
Config.addVariable("module", "augain.so")
|
||||||
}
|
}
|
||||||
@@ -566,7 +575,7 @@ private fun checkOnClick(ctx: Context): Boolean {
|
|||||||
alertTitle.value = ctx.getString(R.string.error)
|
alertTitle.value = ctx.getString(R.string.error)
|
||||||
alertMessage.value = "${ctx.getString(R.string.failed_to_load_module)}: ${module}.so"
|
alertMessage.value = "${ctx.getString(R.string.failed_to_load_module)}: ${module}.so"
|
||||||
showAlert.value = true
|
showAlert.value = true
|
||||||
return false
|
return Result.ERROR
|
||||||
}
|
}
|
||||||
Config.addVariable("module", "${module}.so")
|
Config.addVariable("module", "${module}.so")
|
||||||
save = true
|
save = true
|
||||||
@@ -587,7 +596,7 @@ private fun checkOnClick(ctx: Context): Boolean {
|
|||||||
alertTitle.value = ctx.getString(R.string.notice)
|
alertTitle.value = ctx.getString(R.string.notice)
|
||||||
alertMessage.value = "${ctx.getString(R.string.invalid_opus_bitrate)}: $newOpusBitrate."
|
alertMessage.value = "${ctx.getString(R.string.invalid_opus_bitrate)}: $newOpusBitrate."
|
||||||
showAlert.value = true
|
showAlert.value = true
|
||||||
return false
|
return Result.ERROR
|
||||||
}
|
}
|
||||||
Config.replaceVariable("opus_bitrate", newOpusBitrate)
|
Config.replaceVariable("opus_bitrate", newOpusBitrate)
|
||||||
restart = true
|
restart = true
|
||||||
@@ -599,7 +608,7 @@ private fun checkOnClick(ctx: Context): Boolean {
|
|||||||
alertTitle.value = ctx.getString(R.string.notice)
|
alertTitle.value = ctx.getString(R.string.notice)
|
||||||
alertMessage.value = "${ctx.getString(R.string.invalid_opus_packet_loss)}: $newOpusPacketLoss"
|
alertMessage.value = "${ctx.getString(R.string.invalid_opus_packet_loss)}: $newOpusPacketLoss"
|
||||||
showAlert.value = true
|
showAlert.value = true
|
||||||
return false
|
return Result.ERROR
|
||||||
}
|
}
|
||||||
Config.replaceVariable("opus_packet_loss", newOpusPacketLoss)
|
Config.replaceVariable("opus_packet_loss", newOpusPacketLoss)
|
||||||
restart = true
|
restart = true
|
||||||
@@ -612,7 +621,7 @@ private fun checkOnClick(ctx: Context): Boolean {
|
|||||||
alertTitle.value = ctx.getString(R.string.notice)
|
alertTitle.value = ctx.getString(R.string.notice)
|
||||||
alertMessage.value = String.format(ctx.getString(R.string.invalid_audio_delay), audioDelay)
|
alertMessage.value = String.format(ctx.getString(R.string.invalid_audio_delay), audioDelay)
|
||||||
showAlert.value = true
|
showAlert.value = true
|
||||||
return false
|
return Result.ERROR
|
||||||
}
|
}
|
||||||
Config.replaceVariable("audio_delay", audioDelay)
|
Config.replaceVariable("audio_delay", audioDelay)
|
||||||
BaresipService.audioDelay = audioDelay.toLong()
|
BaresipService.audioDelay = audioDelay.toLong()
|
||||||
@@ -627,7 +636,7 @@ private fun checkOnClick(ctx: Context): Boolean {
|
|||||||
|
|
||||||
if (save) Config.save()
|
if (save) Config.save()
|
||||||
|
|
||||||
return restart
|
return if (restart) Result.RESTART else Result.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkMicGain(micGain: String): Boolean {
|
private fun checkMicGain(micGain: String): Boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user