Try to avoid call null pointer exeptions on call row

This commit is contained in:
Juha Heinanen
2025-05-03 16:59:56 +03:00
parent 9ab7413092
commit aa16b68aa3

View File

@ -1278,7 +1278,6 @@ class MainActivity : ComponentActivity() {
if (showHangupButton.value) {
var ua: UserAgent = userAgentOfSelectedAor()
val call = ua.currentCall()!!
IconButton(
modifier = Modifier.size(48.dp),
@ -1305,16 +1304,25 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.size(48.dp),
onClick = {
val aor = ua.account.aor
if (call.onhold) {
Log.d(TAG, "AoR $aor resuming call ${call.callp} with ${callUri.value}")
call.resume()
call.onhold = false
holdIcon.intValue = R.drawable.call_hold
} else {
Log.d(TAG, "AoR $aor holding call ${call.callp} with ${callUri.value}")
call.hold()
call.onhold = true
holdIcon.intValue = R.drawable.resume
val call = ua.currentCall()
if (call != null) {
if (call.onhold) {
Log.d(
TAG,
"AoR $aor resuming call ${call.callp} with ${callUri.value}"
)
call.resume()
call.onhold = false
holdIcon.intValue = R.drawable.call_hold
} else {
Log.d(
TAG,
"AoR $aor holding call ${call.callp} with ${callUri.value}"
)
call.hold()
call.onhold = true
holdIcon.intValue = R.drawable.resume
}
}
},
) {
@ -1331,15 +1339,17 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.size(48.dp),
enabled = transferButtonEnabled.value,
onClick = {
if (call.onHoldCall != null) {
if (!call.executeTransfer()) {
alertTitle.value = getString(R.string.notice)
alertMessage.value = getString(R.string.transfer_failed)
showAlert.value = true
}
val call = ua.currentCall()
if (call != null) {
if (call.onHoldCall != null) {
if (!call.executeTransfer()) {
alertTitle.value = getString(R.string.notice)
alertMessage.value = getString(R.string.transfer_failed)
showAlert.value = true
}
} else
showTransferDialog = true
}
else
showTransferDialog = true
},
) {
Icon(
@ -1480,7 +1490,8 @@ class MainActivity : ComponentActivity() {
}
}
}
if (call.replaces())
val call = ua.currentCall()
if (call != null && call.replaces())
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center,
@ -1583,8 +1594,7 @@ class MainActivity : ComponentActivity() {
val char = it.last()
if (char.isDigit() || char == '*' || char == '#') {
Log.d(TAG, "Got DTMF digit '$char'")
ua = UserAgent.ofAor(viewModel.selectedAor.value)!!
ua.currentCall()!!.sendDigit(char)
ua.currentCall()?.sendDigit(char)
}
}
dtmfText.value = it
@ -1608,9 +1618,9 @@ class MainActivity : ComponentActivity() {
IconButton(
modifier = Modifier.size(48.dp),
onClick = {
ua = UserAgent.ofAor(viewModel.selectedAor.value)!!
val stats = call.stats("audio")
if (call.startTime != null && stats != "") {
val call = ua.currentCall()
val stats = call?.stats("audio")
if (stats != null && call.startTime != null && stats != "") {
val parts = stats.split(",") as java.util.ArrayList
if (parts[2] == "0/0") {
parts[2] = "?/?"
@ -1810,12 +1820,13 @@ class MainActivity : ComponentActivity() {
private fun reject() {
val ua = UserAgent.ofAor(viewModel.selectedAor.value)!!
val aor = ua.account.aor
val call = ua.currentCall()!!
val callp = call.callp
Log.d(TAG, "AoR $aor rejecting call $callp from ${callUri.value}")
call.rejected = true
Api.ua_hangup(ua.uap, callp, 486, "Busy Here")
val call = ua.currentCall()
if (call != null) {
val callp = call.callp
Log.d(TAG, "AoR ${ua.account.aor} rejecting call $callp from ${callUri.value}")
call.rejected = true
Api.ua_hangup(ua.uap, callp, 486, "Busy Here")
}
}
@Composable