srctree

Robin Linden parent 57bb5309 421c2775
Allow ending an ongoing call from its notification

inlinesplit
atox/src/main/kotlin/ActionReceiver.kt added: 24, removed: 7, total 17
@@ -64,8 +64,8 @@ class ActionReceiver : BroadcastReceiver() {
 
intent.getStringExtra(KEY_CALL)?.also { callChoice ->
val pk = intent.getStringExtra(KEY_CONTACT_PK)?.let { PublicKey(it) } ?: return
if (callChoice == "accept") {
scope.launch {
when (callChoice) {
"accept" -> scope.launch {
val contact = contactManager.get(pk).firstOrNull().let {
if (it != null) {
it
@@ -91,9 +91,10 @@ class ActionReceiver : BroadcastReceiver() {
}
}
}
} else if (callChoice == "reject") {
callManager.endCall(pk)
notificationHelper.dismissCallNotification(pk)
"reject", "end call" -> {
callManager.endCall(pk)
notificationHelper.dismissCallNotification(pk)
}
}
}
}
 
atox/src/main/kotlin/ui/NotificationHelper.kt added: 24, removed: 7, total 17
@@ -204,6 +204,22 @@ class NotificationHelper @Inject constructor(
.addDestination(R.id.callFragment, bundleOf(CONTACT_PUBLIC_KEY to contact.publicKey))
.createPendingIntent()
)
.addAction(
NotificationCompat.Action
.Builder(
IconCompat.createWithResource(context, R.drawable.ic_call_end),
context.getString(R.string.end_call),
PendingIntentCompat.getBroadcast(
context,
"${contact.publicKey}_end_call".hashCode(),
Intent(context, ActionReceiver::class.java)
.putExtra(KEY_CONTACT_PK, contact.publicKey)
.putExtra(KEY_CALL, "end call"),
PendingIntent.FLAG_UPDATE_CURRENT
)
)
.build()
)
.setOngoing(true)
.setSilent(true)