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