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