Config cannot be reloaded on the fly (ask about restart instead)
Fixed typo in opus_bitrate setting Simplified config string handling
This commit is contained in:
@ -21,7 +21,7 @@ class AudioActivity : AppCompatActivity() {
|
||||
private lateinit var audioDelay: EditText
|
||||
|
||||
private var save = false
|
||||
private var reload = false
|
||||
private var restart = false
|
||||
private var callVolume = BaresipService.callVolume
|
||||
private var oldAudioModules = mutableMapOf<String, Boolean>()
|
||||
private var oldOpusBitrate = ""
|
||||
@ -184,7 +184,7 @@ class AudioActivity : AppCompatActivity() {
|
||||
return false
|
||||
}
|
||||
Config.replaceVariable("opus_bitrate", opusBitRate)
|
||||
reload = true
|
||||
restart = true
|
||||
save = true
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ class AudioActivity : AppCompatActivity() {
|
||||
return false
|
||||
}
|
||||
Config.replaceVariable("opus_packet_loss", opusPacketLoss)
|
||||
reload = true
|
||||
restart = true
|
||||
save = true
|
||||
}
|
||||
|
||||
@ -228,9 +228,10 @@ class AudioActivity : AppCompatActivity() {
|
||||
save = true
|
||||
}
|
||||
|
||||
if (save) Config.save()
|
||||
if (save)
|
||||
Config.save()
|
||||
|
||||
if (reload) Api.reload_config()
|
||||
setResult(if (restart) RESULT_OK else RESULT_CANCELED)
|
||||
|
||||
BaresipService.activities.remove("audio")
|
||||
finish()
|
||||
|
||||
@ -10,7 +10,6 @@ object Config {
|
||||
|
||||
private val configPath = BaresipService.filesPath + "/config"
|
||||
private lateinit var config: String
|
||||
private lateinit var lines: List<String>
|
||||
private lateinit var previousConfig: String
|
||||
private lateinit var previousLines: List<String>
|
||||
|
||||
@ -112,9 +111,9 @@ object Config {
|
||||
|
||||
val opusBitRate = previousVariable("opus_bitrate")
|
||||
config = if (opusBitRate == "")
|
||||
"${config}opus_bit_rate 28000\n"
|
||||
"${config}opus_bitrate 28000\n"
|
||||
else
|
||||
"${config}opus_bit_rate $opusBitRate\n"
|
||||
"${config}opus_bitrate $opusBitRate\n"
|
||||
|
||||
val opusPacketLoss = previousVariable("opus_packet_loss")
|
||||
config = if (opusPacketLoss == "")
|
||||
@ -155,7 +154,7 @@ object Config {
|
||||
}
|
||||
|
||||
fun variable(name: String): String {
|
||||
for (line in lines) {
|
||||
for (line in config.split("\n")) {
|
||||
val nameValue = line.split(" ")
|
||||
if (nameValue.size == 2 && nameValue[0] == name)
|
||||
return nameValue[1].trim()
|
||||
@ -165,7 +164,7 @@ object Config {
|
||||
|
||||
fun variables(name: String): ArrayList<String> {
|
||||
val result = ArrayList<String>()
|
||||
for (line in lines) {
|
||||
for (line in config.split("\n")) {
|
||||
val nameValue = line.split(" ")
|
||||
if (nameValue.size == 2 && nameValue[0] == name)
|
||||
result.add(nameValue[1].trim())
|
||||
@ -197,7 +196,6 @@ object Config {
|
||||
|
||||
fun save() {
|
||||
Utils.putFileContents(configPath, config.toByteArray())
|
||||
lines = config.split("\n")
|
||||
Log.d(TAG, "Saved new config '$config'")
|
||||
// Api.reload_config()
|
||||
}
|
||||
|
||||
@ -69,6 +69,7 @@ class ConfigActivity : AppCompatActivity() {
|
||||
private var oldNetAf = ""
|
||||
private var save = false
|
||||
private var restart = false
|
||||
private var audioRestart = false
|
||||
private var menu: Menu? = null
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
@ -636,7 +637,7 @@ class ConfigActivity : AppCompatActivity() {
|
||||
Config.save()
|
||||
BaresipService.activities.remove("config")
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
if (restart)
|
||||
if (restart || audioRestart)
|
||||
intent.putExtra("restart", true)
|
||||
setResult(RESULT_OK, intent)
|
||||
finish()
|
||||
@ -646,12 +647,21 @@ class ConfigActivity : AppCompatActivity() {
|
||||
private fun goBack() {
|
||||
|
||||
BaresipService.activities.remove("config")
|
||||
setResult(Activity.RESULT_CANCELED, Intent(this, MainActivity::class.java))
|
||||
if (audioRestart) {
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
intent.putExtra("restart", true)
|
||||
setResult(RESULT_OK, intent)
|
||||
} else {
|
||||
setResult(Activity.RESULT_CANCELED, Intent(this, MainActivity::class.java))
|
||||
}
|
||||
finish()
|
||||
|
||||
}
|
||||
|
||||
private fun bindTitles() {
|
||||
val audioRequest = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
audioRestart = it.resultCode == Activity.RESULT_OK
|
||||
}
|
||||
binding.AutoStartTitle.setOnClickListener {
|
||||
Utils.alertView(this, getString(R.string.start_automatically),
|
||||
getString(R.string.start_automatically_help))
|
||||
@ -681,7 +691,7 @@ class ConfigActivity : AppCompatActivity() {
|
||||
getString(R.string.tls_ca_file_help))
|
||||
}
|
||||
binding.AudioSettingsTitle.setOnClickListener {
|
||||
startActivity(Intent(this, AudioActivity::class.java))
|
||||
audioRequest.launch(Intent(this, AudioActivity::class.java))
|
||||
}
|
||||
binding.DarkThemeTitle.setOnClickListener {
|
||||
Utils.alertView(this, getString(R.string.dark_theme),
|
||||
|
||||
Reference in New Issue
Block a user