diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 146210d5..69cc0789 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -36,6 +36,8 @@ import kotlin.concurrent.schedule import kotlin.math.roundToInt import android.media.MediaPlayer import android.telecom.TelecomManager +import android.widget.Toast +import android.os.Looper class BaresipService: Service() { @@ -572,22 +574,29 @@ class BaresipService: Service() { else status[account_index] = R.drawable.dot_green updateStatusNotification() - if (!Utils.isVisible()) + if (!isMainVisible) return } "registering failed" -> { status[account_index] = R.drawable.dot_red updateStatusNotification() - if (ev.size > 1 && ev[1] == "Invalid argument") - // Likely due to DNS lookup failure - newEvent = "registering failed,DNS lookup failed" - if (!Utils.isVisible()) + if (Utils.isVisible()) { + val reason = if (ev.size > 1) { + if (ev[1] == "Invalid argument") // Likely due to DNS lookup failure + ": DNS lookup failed" + else + ": ${ev[1]}" + } else + "" + toast(String.format(getString(R.string.registering_failed), aor) + reason) + } + if (!isMainVisible) return } "unregistering" -> { status[account_index] = R.drawable.dot_white updateStatusNotification() - if (!Utils.isVisible()) + if (!isMainVisible) return } "call outgoing" -> { @@ -1071,6 +1080,12 @@ class BaresipService: Service() { } } + private fun toast(message: String) { + Handler(Looper.getMainLooper()).post { + Toast.makeText(this@BaresipService.applicationContext, message, Toast.LENGTH_LONG).show() + } + } + private fun getActionText(@StringRes stringRes: Int, @ColorRes colorRes: Int): Spannable { val spannable: Spannable = SpannableString(applicationContext.getText(stringRes)) if (VERSION.SDK_INT >= 25) { diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index f5c3f332..ea240f89 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -939,16 +939,9 @@ class MainActivity : AppCompatActivity() { for (account_index in UserAgent.uas().indices) { if (UserAgent.uas()[account_index].account.aor == aor) { when (ev[0]) { - "registered", "unregistering" -> { + "registered", "unregistering", "registering failed" -> { uaAdapter.notifyDataSetChanged() } - "registering failed" -> { - uaAdapter.notifyDataSetChanged() - Toast.makeText(applicationContext, - String.format(getString(R.string.registering_failed), aor) + - ": ${ev[1]}", - Toast.LENGTH_LONG).show() - } "call rejected" -> { if (aor == aorSpinner.tag) { callsButton.setImageResource(R.drawable.calls_missed)