- Always send "started" event to main activity after baresip is started

- No need to send "ua added" events to main activity
This commit is contained in:
Juha Heinanen
2021-01-21 17:10:49 +02:00
parent 31fa509d34
commit ad66007d58
2 changed files with 24 additions and 30 deletions
@@ -427,11 +427,6 @@ class BaresipService: Service() {
else else
status.add(R.drawable.dot_yellow) status.add(R.drawable.dot_yellow)
} }
val intent = Intent("service event")
intent.putExtra("event", "ua added")
intent.putExtra("params", arrayListOf(uap))
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
updateStatusNotification()
} }
@Keep @Keep
@@ -862,14 +857,12 @@ class BaresipService: Service() {
@Keep @Keep
fun started() { fun started() {
Log.d(LOG_TAG, "Received 'started' from baresip") Log.d(LOG_TAG, "Received 'started' from baresip")
if (callActionUri != "") {
val intent = Intent("service event") val intent = Intent("service event")
intent.putExtra("event", "started") intent.putExtra("event", "started")
intent.putExtra("params", arrayListOf(callActionUri)) intent.putExtra("params", arrayListOf(callActionUri))
LocalBroadcastManager.getInstance(this).sendBroadcast(intent) LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
callActionUri = "" callActionUri = ""
} }
}
@Keep @Keep
fun stopped(error: String) { fun stopped(error: String) {
@@ -718,18 +718,26 @@ class MainActivity : AppCompatActivity() {
if (event == "started") { if (event == "started") {
val callActionUri = params[0] val callActionUri = params[0]
Log.d("Baresip", "Handling service event 'started' with '$callActionUri'") Log.d("Baresip", "Handling service event 'started' with '$callActionUri'")
uaAdapter.notifyDataSetChanged()
if (callActionUri != "") {
var ua = UserAgent.ofDomain(Utils.uriHostPart(callActionUri)) var ua = UserAgent.ofDomain(Utils.uriHostPart(callActionUri))
if (ua == null) if (ua == null)
if (BaresipService.uas.size > 0) { if (BaresipService.uas.size > 0) {
ua = BaresipService.uas[0] ua = BaresipService.uas[0]
} else { } else {
Log.w("Baresip", "No UAs to make the call to $callActionUri") Log.w("Baresip", "No UAs to make the call to '$callActionUri'")
return return
} }
spinToAor(ua.account.aor) spinToAor(ua.account.aor)
ua.account.resumeUri = callActionUri ua.account.resumeUri = callActionUri
callUri.setText(callActionUri) callUri.setText(callActionUri)
callButton.performClick() callButton.performClick()
} else {
if (aorSpinner.selectedItemPosition == -1) {
aorSpinner.setSelection(0)
aorSpinner.tag = UserAgent.uas()[0].account.aor
}
}
return return
} }
if (event == "stopped") { if (event == "stopped") {
@@ -769,13 +777,6 @@ class MainActivity : AppCompatActivity() {
for (account_index in UserAgent.uas().indices) { for (account_index in UserAgent.uas().indices) {
if (UserAgent.uas()[account_index].account.aor == aor) { if (UserAgent.uas()[account_index].account.aor == aor) {
when (ev[0]) { when (ev[0]) {
"ua added" -> {
uaAdapter.notifyDataSetChanged()
if (aorSpinner.selectedItemPosition == -1) {
aorSpinner.setSelection(0)
aorSpinner.tag = UserAgent.uas()[0].account.aor
}
}
"registered", "unregistering" -> { "registered", "unregistering" -> {
uaAdapter.notifyDataSetChanged() uaAdapter.notifyDataSetChanged()
} }