diff --git a/atox/src/main/kotlin/ActionReceiver.kt b/atox/src/main/kotlin/ActionReceiver.kt index 67fe0562d..0b2c71cc4 100644 --- a/atox/src/main/kotlin/ActionReceiver.kt +++ b/atox/src/main/kotlin/ActionReceiver.kt @@ -6,6 +6,7 @@ package ltd.evilcorp.atox import android.Manifest +import android.app.PendingIntent import android.content.BroadcastReceiver import android.content.Context import android.content.Intent @@ -13,6 +14,8 @@ import android.util.Log import android.widget.Toast import androidx.core.app.RemoteInput import androidx.core.content.IntentCompat +import androidx.core.os.bundleOf +import androidx.navigation.NavDeepLinkBuilder import im.tox.tox4j.av.exceptions.ToxavAnswerException import javax.inject.Inject import kotlinx.coroutines.CoroutineScope @@ -21,6 +24,7 @@ import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import ltd.evilcorp.atox.ui.NotificationHelper +import ltd.evilcorp.atox.ui.chat.CONTACT_PUBLIC_KEY import ltd.evilcorp.core.repository.ContactRepository import ltd.evilcorp.core.vo.Contact import ltd.evilcorp.core.vo.PublicKey @@ -129,19 +133,20 @@ class ActionReceiver : BroadcastReceiver() { return } + // Show the call screen. try { - callManager.startCall(pk) - notificationHelper.showOngoingCallNotification(contact) - } catch (e: ToxavAnswerException) { - Log.e(TAG, e.toString()) - return - } - - val isSendingAudio = context.hasPermission(Manifest.permission.RECORD_AUDIO) && callManager.startSendingAudio() - if (!isSendingAudio) { - withContext(Dispatchers.Main) { - Toast.makeText(context, R.string.call_mic_permission_needed, Toast.LENGTH_LONG).show() - } + deepLinkToCall(context, pk).send() + } catch (e: PendingIntent.CanceledException) { + Log.e(TAG, "PendingIntent.CanceledException: $e}") } } + private fun deepLinkToCall(context: Context, publicKey: PublicKey) = NavDeepLinkBuilder(context) + .setGraph(R.navigation.nav_graph) + .setDestination(R.id.callFragment) + .setArguments( + bundleOf( + CONTACT_PUBLIC_KEY to publicKey.string(), + ), + ) + .createPendingIntent() } diff --git a/atox/src/main/kotlin/ui/NotificationHelper.kt b/atox/src/main/kotlin/ui/NotificationHelper.kt index 5e0304d0e..850c0e16f 100644 --- a/atox/src/main/kotlin/ui/NotificationHelper.kt +++ b/atox/src/main/kotlin/ui/NotificationHelper.kt @@ -314,7 +314,8 @@ class NotificationHelper @Inject constructor(private val context: Context) { val notificationBuilder = NotificationCompat.Builder(context, CALL) - val pendingIntent = deepLinkToChat(PublicKey(c.publicKey)) + // Make notification stay even if it's tapped accidentally. + val pendingIntent = nullIntent() if (context.hasPermission(Manifest.permission.USE_FULL_SCREEN_INTENT)) { // Making the notification persistent takes a full-screen intent. notificationBuilder @@ -392,4 +393,14 @@ class NotificationHelper @Inject constructor(private val context: Context) { ), ) .createPendingIntent() + + private fun nullIntent(): PendingIntent { + val doNothingIntent = Intent() + return PendingIntent.getBroadcast( + context, + 0, + doNothingIntent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE, + ) + } }