- Moved configuration of account's audio codecs to a new activity.
This commit is contained in:
@@ -15,6 +15,7 @@ class Account(val accp: String) {
|
||||
var mediaNat = account_medianat(accp)
|
||||
var stunServer = ""
|
||||
var audioCodec = ArrayList<String>()
|
||||
var videoCodec = ArrayList<String>()
|
||||
var regint = account_regint(accp)
|
||||
var mediaEnc = account_mediaenc(accp)
|
||||
var preferIPv6Media = false
|
||||
@@ -247,6 +248,7 @@ external fun account_set_mediaenc(acc: String, mediaenc: String): Int
|
||||
external fun account_medianat(acc: String): String
|
||||
external fun account_set_medianat(acc: String, medianat: String): Int
|
||||
external fun account_set_audio_codecs(acc: String, codecs: String): Int
|
||||
external fun account_set_video_codecs(acc: String, codecs: String): Int
|
||||
external fun account_set_mwi(acc: String, value: String): Int
|
||||
external fun account_vm_uri(acc: String): String
|
||||
external fun account_extra(acc: String): String
|
||||
|
||||
@@ -37,7 +37,6 @@ class AccountActivity : AppCompatActivity() {
|
||||
internal lateinit var vmUri: EditText
|
||||
internal lateinit var defaultCheck: CheckBox
|
||||
|
||||
private var newCodecs = ArrayList<String>()
|
||||
private var save = false
|
||||
private var uaIndex= -1
|
||||
|
||||
@@ -83,39 +82,6 @@ class AccountActivity : AppCompatActivity() {
|
||||
regCheck = findViewById(R.id.Register) as CheckBox
|
||||
regCheck.isChecked = acc.regint > 0
|
||||
|
||||
val audioCodecs = ArrayList(Api.audio_codecs().split(","))
|
||||
newCodecs.addAll(acc.audioCodec)
|
||||
while (newCodecs.size < audioCodecs.size) newCodecs.add("-")
|
||||
val layout = findViewById(R.id.CodecSpinners) as LinearLayout
|
||||
val spinnerList = Array(audioCodecs.size, {_ -> ArrayList<String>()})
|
||||
for (i in audioCodecs.indices) {
|
||||
val spinner = Spinner(applicationContext)
|
||||
spinner.id = i + 100
|
||||
spinner.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
|
||||
layout.addView(spinner)
|
||||
if (acc.audioCodec.size > i) {
|
||||
val codec = acc.audioCodec[i]
|
||||
spinnerList[i].add(codec)
|
||||
spinnerList[i].add("-")
|
||||
for (c in audioCodecs) if (c != codec) spinnerList[i].add(c)
|
||||
} else {
|
||||
spinnerList[i].addAll(audioCodecs)
|
||||
spinnerList[i].add(0, "-")
|
||||
}
|
||||
val codecSpinner = findViewById(spinner.id) as Spinner
|
||||
val adapter = ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
|
||||
spinnerList[i])
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
codecSpinner.adapter = adapter
|
||||
codecSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
|
||||
newCodecs.set(parent.id - 100, parent.selectedItem.toString())
|
||||
}
|
||||
override fun onNothingSelected(parent: AdapterView<*>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mediaNat = acc.mediaNat
|
||||
val mediaNatSpinner = findViewById(R.id.mediaNatSpinner) as Spinner
|
||||
val mediaNatKeys = arrayListOf("stun", "ice", "")
|
||||
@@ -379,18 +345,6 @@ class AccountActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
val ac = ArrayList(LinkedHashSet<String>(newCodecs.filter { it != "-" } as ArrayList<String>))
|
||||
if (ac != acc.audioCodec) {
|
||||
val acList = Utils.implode(ac, ",")
|
||||
if (account_set_audio_codecs(acc.accp, acList) == 0) {
|
||||
Log.d("Baresip", "New audio codecs '$acList'")
|
||||
acc.audioCodec = ac
|
||||
save = true
|
||||
} else {
|
||||
Log.e("Baresip", "Setting of audio codecs '$acList' failed")
|
||||
}
|
||||
}
|
||||
|
||||
if (mediaEnc != acc.mediaEnc) {
|
||||
if (account_set_mediaenc(acc.accp, mediaEnc) == 0) {
|
||||
acc.mediaEnc = account_mediaenc(acc.accp)
|
||||
@@ -506,8 +460,12 @@ class AccountActivity : AppCompatActivity() {
|
||||
getString(R.string.register_help))
|
||||
}
|
||||
findViewById(R.id.AudioCodecsTitle) as TextView -> {
|
||||
Utils.alertView(this, getString(R.string.audio_codecs),
|
||||
getString(R.string.audio_codecs_help))
|
||||
val i = Intent(this, CodecsActivity::class.java)
|
||||
val b = Bundle()
|
||||
b.putString("aor", aor)
|
||||
b.putString("media", "audio")
|
||||
i.putExtras(b)
|
||||
startActivity(i)
|
||||
}
|
||||
findViewById(R.id.MediaNatTitle) as TextView -> {
|
||||
Utils.alertView(this, getString(R.string.media_nat),
|
||||
|
||||
@@ -186,7 +186,6 @@ class AccountsActivity : AppCompatActivity() {
|
||||
count++
|
||||
}
|
||||
Utils.putFileContents(BaresipService.filesPath + "/accounts", accounts.toByteArray())
|
||||
Log.d("Baresip", "Saved $count account(s) to '${BaresipService.filesPath}/accounts'")
|
||||
// Log.d("Baresip", "Saved accounts '${accounts}' to '${BaresipService.filesPath}/accounts'")
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ object Api {
|
||||
val VIDMODE_ON = 1
|
||||
|
||||
external fun audio_codecs(): String
|
||||
external fun video_codecs(): String
|
||||
external fun uag_current_set(uap: String)
|
||||
external fun uag_reset_transp(reg: Boolean, reinvite: Boolean)
|
||||
external fun ua_account(ua: String): String
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import android.widget.LinearLayout.LayoutParams
|
||||
|
||||
class CodecsActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var acc: Account
|
||||
private lateinit var ua: UserAgent
|
||||
private var aor = ""
|
||||
private var newCodecs = ArrayList<String>()
|
||||
private var media = ""
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_codecs)
|
||||
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
aor = intent.getStringExtra("aor")!!
|
||||
media = intent.getStringExtra("media")!!
|
||||
|
||||
Utils.addActivity("codecs,$aor,$media")
|
||||
|
||||
ua = UserAgent.ofAor(aor)!!
|
||||
acc = ua.account
|
||||
|
||||
val codecs: ArrayList<String>
|
||||
|
||||
val title = findViewById(R.id.CodecsTitle) as TextView
|
||||
|
||||
if (media == "audio") {
|
||||
title.text = getString(R.string.audio_codecs)
|
||||
codecs = ArrayList(Api.audio_codecs().split(","))
|
||||
newCodecs.addAll(acc.audioCodec)
|
||||
} else {
|
||||
title.text = getString(R.string.video_codecs)
|
||||
codecs = ArrayList(Api.video_codecs().split(","))
|
||||
newCodecs.addAll(acc.videoCodec)
|
||||
}
|
||||
|
||||
while (newCodecs.size < codecs.size) newCodecs.add("-")
|
||||
|
||||
val layout = findViewById(R.id.SpinnerTable) as TableLayout
|
||||
val spinnerList = Array(codecs.size, {_ -> ArrayList<String>()})
|
||||
for (i in codecs.indices) {
|
||||
val spinner = Spinner(applicationContext)
|
||||
spinner.id = i + 100
|
||||
spinner.layoutParams = TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
|
||||
LayoutParams.WRAP_CONTENT)
|
||||
spinner.layoutParams.height = 75
|
||||
layout.addView(spinner)
|
||||
if (acc.audioCodec.size > i) {
|
||||
val codec = acc.audioCodec[i]
|
||||
spinnerList[i].add(codec)
|
||||
spinnerList[i].add("-")
|
||||
for (c in codecs) if (c != codec) spinnerList[i].add(c)
|
||||
} else {
|
||||
spinnerList[i].addAll(codecs)
|
||||
spinnerList[i].add(0, "-")
|
||||
}
|
||||
val codecSpinner = findViewById(spinner.id) as Spinner
|
||||
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item,
|
||||
spinnerList[i])
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
codecSpinner.adapter = adapter
|
||||
codecSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
|
||||
newCodecs.set(parent.id - 100, parent.selectedItem.toString())
|
||||
}
|
||||
override fun onNothingSelected(parent: AdapterView<*>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
|
||||
super.onCreateOptionsMenu(menu)
|
||||
val inflater = menuInflater
|
||||
inflater.inflate(R.menu.check_icon, menu)
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
|
||||
if (BaresipService.activities.indexOf("codecs,$aor,$media") == -1)
|
||||
return true
|
||||
|
||||
when (item.itemId) {
|
||||
|
||||
R.id.checkIcon -> {
|
||||
|
||||
var save = false
|
||||
val mc = ArrayList(LinkedHashSet<String>(newCodecs.filter { it != "-" } as ArrayList<String>))
|
||||
val mcList = Utils.implode(mc, ",")
|
||||
|
||||
if (media == "audio")
|
||||
if (mc != acc.audioCodec) {
|
||||
if (account_set_audio_codecs(acc.accp, mcList) == 0) {
|
||||
Log.d("Baresip", "New audio codecs '$mcList'")
|
||||
acc.audioCodec = mc
|
||||
save = true
|
||||
} else {
|
||||
Log.e("Baresip", "Setting of audio codecs '$mcList' failed")
|
||||
}
|
||||
}
|
||||
|
||||
if (media == "video")
|
||||
if (mc != acc.videoCodec) {
|
||||
if (account_set_video_codecs(acc.accp, mcList) == 0) {
|
||||
Log.d("Baresip", "New video codecs '$mcList'")
|
||||
acc.audioCodec = mc
|
||||
save = true
|
||||
} else {
|
||||
Log.e("Baresip", "Setting of video codecs '$mcList' failed")
|
||||
}
|
||||
}
|
||||
|
||||
if (save) {
|
||||
AccountsActivity.saveAccounts()
|
||||
if (Api.ua_update_account(ua.uap) != 0)
|
||||
Log.e("Baresip", "Failed to update UA ${ua.uap} with AoR $aor")
|
||||
}
|
||||
|
||||
if ((acc.regint > 0) && !((acc.authUser != "") && (acc.authPass == "")))
|
||||
Api.ua_register(ua.uap)
|
||||
|
||||
BaresipService.activities.remove("codecs,$aor,$media")
|
||||
finish()
|
||||
return true
|
||||
}
|
||||
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item)
|
||||
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
BaresipService.activities.remove("codecs,$aor,$media")
|
||||
finish()
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
MainActivity.activityAor = aor
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
fun onClick(v: View) {
|
||||
when (v) {
|
||||
findViewById(R.id.CodecsTitle) as TextView -> {
|
||||
if (media == "audio")
|
||||
Utils.alertView(this, getString(R.string.audio_codecs),
|
||||
getString(R.string.audio_codecs_help))
|
||||
else
|
||||
Utils.alertView(this, getString(R.string.video_codecs),
|
||||
getString(R.string.video_codecs_help))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1391,6 +1391,14 @@ class MainActivity : AppCompatActivity() {
|
||||
i.putExtras(b)
|
||||
startActivityForResult(i, ACCOUNT_CODE)
|
||||
}
|
||||
"codecs" -> {
|
||||
val i = Intent(this, CodecsActivity::class.java)
|
||||
val b = Bundle()
|
||||
b.putString("aor", activity[1])
|
||||
b.putString("media", activity[2])
|
||||
i.putExtras(b)
|
||||
startActivity(i)
|
||||
}
|
||||
"about" -> {
|
||||
val i = Intent(this, AboutActivity::class.java)
|
||||
startActivityForResult(i, ABOUT_CODE)
|
||||
@@ -1482,7 +1490,6 @@ class MainActivity : AppCompatActivity() {
|
||||
const val BACKUP_PERMISSION_REQUEST_CODE = 1
|
||||
const val RESTORE_PERMISSION_REQUEST_CODE = 2
|
||||
const val RECORD_PERMISSION_REQUEST_CODE = 3
|
||||
const val RESTART_REQUEST_CODE = 4
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user