Skip to content

Commit bb9f076

Browse files
TrueWatcherrobinlinden
authored andcommitted
Make accepting an incoming call open the call screen
1 parent df5b658 commit bb9f076

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

atox/src/main/kotlin/ActionReceiver.kt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
package ltd.evilcorp.atox
77

88
import android.Manifest
9+
import android.app.PendingIntent
910
import android.content.BroadcastReceiver
1011
import android.content.Context
1112
import android.content.Intent
1213
import android.util.Log
1314
import android.widget.Toast
1415
import androidx.core.app.RemoteInput
1516
import androidx.core.content.IntentCompat
17+
import androidx.core.os.bundleOf
18+
import androidx.navigation.NavDeepLinkBuilder
1619
import im.tox.tox4j.av.exceptions.ToxavAnswerException
1720
import javax.inject.Inject
1821
import kotlinx.coroutines.CoroutineScope
@@ -21,6 +24,7 @@ import kotlinx.coroutines.flow.firstOrNull
2124
import kotlinx.coroutines.launch
2225
import kotlinx.coroutines.withContext
2326
import ltd.evilcorp.atox.ui.NotificationHelper
27+
import ltd.evilcorp.atox.ui.chat.CONTACT_PUBLIC_KEY
2428
import ltd.evilcorp.core.repository.ContactRepository
2529
import ltd.evilcorp.core.vo.Contact
2630
import ltd.evilcorp.core.vo.PublicKey
@@ -129,19 +133,20 @@ class ActionReceiver : BroadcastReceiver() {
129133
return
130134
}
131135

136+
// Show the call screen.
132137
try {
133-
callManager.startCall(pk)
134-
notificationHelper.showOngoingCallNotification(contact)
135-
} catch (e: ToxavAnswerException) {
136-
Log.e(TAG, e.toString())
137-
return
138-
}
139-
140-
val isSendingAudio = context.hasPermission(Manifest.permission.RECORD_AUDIO) && callManager.startSendingAudio()
141-
if (!isSendingAudio) {
142-
withContext(Dispatchers.Main) {
143-
Toast.makeText(context, R.string.call_mic_permission_needed, Toast.LENGTH_LONG).show()
144-
}
138+
deepLinkToCall(context, pk).send()
139+
} catch (e: PendingIntent.CanceledException) {
140+
Log.e(TAG, "PendingIntent.CanceledException: $e}")
145141
}
146142
}
143+
private fun deepLinkToCall(context: Context, publicKey: PublicKey) = NavDeepLinkBuilder(context)
144+
.setGraph(R.navigation.nav_graph)
145+
.setDestination(R.id.callFragment)
146+
.setArguments(
147+
bundleOf(
148+
CONTACT_PUBLIC_KEY to publicKey.string(),
149+
),
150+
)
151+
.createPendingIntent()
147152
}

atox/src/main/kotlin/ui/NotificationHelper.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ class NotificationHelper @Inject constructor(private val context: Context) {
314314

315315
val notificationBuilder = NotificationCompat.Builder(context, CALL)
316316

317-
val pendingIntent = deepLinkToChat(PublicKey(c.publicKey))
317+
// Make notification stay even if it's tapped accidentally.
318+
val pendingIntent = nullIntent()
318319
if (context.hasPermission(Manifest.permission.USE_FULL_SCREEN_INTENT)) {
319320
// Making the notification persistent takes a full-screen intent.
320321
notificationBuilder
@@ -392,4 +393,14 @@ class NotificationHelper @Inject constructor(private val context: Context) {
392393
),
393394
)
394395
.createPendingIntent()
396+
397+
private fun nullIntent(): PendingIntent {
398+
val doNothingIntent = Intent()
399+
return PendingIntent.getBroadcast(
400+
context,
401+
0,
402+
doNothingIntent,
403+
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
404+
)
405+
}
395406
}

0 commit comments

Comments
 (0)