Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions atox/src/main/kotlin/ActionReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
package ltd.evilcorp.atox

import android.Manifest
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
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
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
13 changes: 12 additions & 1 deletion atox/src/main/kotlin/ui/NotificationHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
}
}
Loading