From ad66007d58196c0646c3af57348c325a3d2ad9c4 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Thu, 21 Jan 2021 17:10:49 +0200 Subject: [PATCH] - Always send "started" event to main activity after baresip is started - No need to send "ua added" events to main activity --- .../com/tutpro/baresip/BaresipService.kt | 17 +++------ .../kotlin/com/tutpro/baresip/MainActivity.kt | 37 ++++++++++--------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index bf1c754d..6a2c2854 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -427,11 +427,6 @@ class BaresipService: Service() { else 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 @@ -862,13 +857,11 @@ class BaresipService: Service() { @Keep fun started() { Log.d(LOG_TAG, "Received 'started' from baresip") - if (callActionUri != "") { - val intent = Intent("service event") - intent.putExtra("event", "started") - intent.putExtra("params", arrayListOf(callActionUri)) - LocalBroadcastManager.getInstance(this).sendBroadcast(intent) - callActionUri = "" - } + val intent = Intent("service event") + intent.putExtra("event", "started") + intent.putExtra("params", arrayListOf(callActionUri)) + LocalBroadcastManager.getInstance(this).sendBroadcast(intent) + callActionUri = "" } @Keep diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index ed3dbe2a..d9c7ce98 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -718,18 +718,26 @@ class MainActivity : AppCompatActivity() { if (event == "started") { val callActionUri = params[0] Log.d("Baresip", "Handling service event 'started' with '$callActionUri'") - var ua = UserAgent.ofDomain(Utils.uriHostPart(callActionUri)) - if (ua == null) - if (BaresipService.uas.size > 0) { - ua = BaresipService.uas[0] - } else { - Log.w("Baresip", "No UAs to make the call to $callActionUri") - return + uaAdapter.notifyDataSetChanged() + if (callActionUri != "") { + var ua = UserAgent.ofDomain(Utils.uriHostPart(callActionUri)) + if (ua == null) + if (BaresipService.uas.size > 0) { + ua = BaresipService.uas[0] + } else { + Log.w("Baresip", "No UAs to make the call to '$callActionUri'") + return + } + spinToAor(ua.account.aor) + ua.account.resumeUri = callActionUri + callUri.setText(callActionUri) + callButton.performClick() + } else { + if (aorSpinner.selectedItemPosition == -1) { + aorSpinner.setSelection(0) + aorSpinner.tag = UserAgent.uas()[0].account.aor } - spinToAor(ua.account.aor) - ua.account.resumeUri = callActionUri - callUri.setText(callActionUri) - callButton.performClick() + } return } if (event == "stopped") { @@ -769,13 +777,6 @@ class MainActivity : AppCompatActivity() { for (account_index in UserAgent.uas().indices) { if (UserAgent.uas()[account_index].account.aor == aor) { when (ev[0]) { - "ua added" -> { - uaAdapter.notifyDataSetChanged() - if (aorSpinner.selectedItemPosition == -1) { - aorSpinner.setSelection(0) - aorSpinner.tag = UserAgent.uas()[0].account.aor - } - } "registered", "unregistering" -> { uaAdapter.notifyDataSetChanged() }