Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
feat: implement NotificationDetailDialog to display notification content and URLs within the app
Rishabh Bajpaid9494eaae907
diff --git a/app/src/main/java/com/gotcha/MainActivity.kt b/app/src/main/java/com/gotcha/MainActivity.ktindex ed3cd4d..0ff7b81 100644--- a/app/src/main/java/com/gotcha/MainActivity.kt+++ b/app/src/main/java/com/gotcha/MainActivity.kt@@ -30,6 +30,7 @@ import androidx.compose.runtime.rememberCoroutineScopeimport androidx.compose.runtime.setValueimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.toArgb+import androidx.core.app.NotificationManagerCompatimport androidx.lifecycle.lifecycleScopeimport com.gotcha.agent.ChatViewModelimport com.gotcha.audio.AudioApi@@ -41,6 +42,8 @@ import com.gotcha.data.Settingsimport com.gotcha.data.SettingsRepositoryimport com.gotcha.llm.ChatMessageimport com.gotcha.llm.LLMClient+import com.gotcha.notifications.NotificationDispatcher+import com.gotcha.notifications.NotificationPayloadimport com.gotcha.notifications.ServerMessagesimport com.gotcha.service.AssistiveBallServiceimport com.gotcha.service.GotchaDeviceAdminReceiver@@ -49,6 +52,7 @@ import com.gotcha.tools.ToolResultimport com.gotcha.ui.AppDrawerContentimport com.gotcha.ui.ChatScreenimport com.gotcha.ui.ConnectorsScreen+import com.gotcha.ui.NotificationDetailDialogimport com.gotcha.ui.SettingsPageimport com.gotcha.ui.SettingsScreenimport com.gotcha.ui.theme.GotchaTheme@@ -68,6 +72,9 @@ class MainActivity : ComponentActivity() {private lateinit var settingsRepository: SettingsRepositoryprivate lateinit var samosaAuthManager: SamosaAuthManager+ /** Active notification payload for display in scrollable dialog. */+ private var notificationPayload by mutableStateOf<NotificationPayload?>(null)+/** Set when launched from the assistive ball's "Open Chat" option. */private var openChatRequested by mutableStateOf(false)@@ -141,6 +148,7 @@ class MainActivity : ComponentActivity() {samosaAuthManager = SamosaAuthManager(applicationContext, settingsRepository)openChatRequested = intent?.getBooleanExtra(EXTRA_OPEN_CHAT, false) == trueopenedFromBall = intent?.getBooleanExtra(EXTRA_FROM_ASSISTIVE_BALL, false) == true+ handleNotificationIntent(intent)// Phase 7: tools report special-access markers; open Settings deep-links.// Runtime permissions are no longer requested here — they are pre-configured@@ -297,6 +305,25 @@ class MainActivity : ComponentActivity() {if (intent.getBooleanExtra(EXTRA_FROM_ASSISTIVE_BALL, false)) {openedFromBall = true}+ handleNotificationIntent(intent)+ }++ private fun handleNotificationIntent(intent: Intent?) {+ val title = intent?.getStringExtra(NotificationDispatcher.EXTRA_NOTIFICATION_TITLE)+ val body = intent?.getStringExtra(NotificationDispatcher.EXTRA_NOTIFICATION_BODY)+ if (!title.isNullOrBlank() || !body.isNullOrBlank()) {+ val notifyId = intent?.getIntExtra(NotificationDispatcher.EXTRA_NOTIFICATION_ID, -1) ?: -1+ val url = intent?.getStringExtra(NotificationDispatcher.EXTRA_NOTIFICATION_URL)+ if (notifyId != -1) {+ NotificationManagerCompat.from(this).cancel(notifyId)+ }+ notificationPayload = NotificationPayload(+ id = notifyId,+ title = title.orEmpty(),+ body = body.orEmpty(),+ url = url+ )+ }}override fun onStart() {@@ -650,6 +677,13 @@ class MainActivity : ComponentActivity() {BackHandler(enabled = drawerState.isOpen) {scope.launch { drawerState.close() }}++ notificationPayload?.let { payload ->+ NotificationDetailDialog(+ payload = payload,+ onDismiss = { notificationPayload = null }+ )+ }}/** Cheap "ping" request to validate credentials (Phase 6). */diff --git a/app/src/main/java/com/gotcha/notifications/NotificationDispatcher.kt b/app/src/main/java/com/gotcha/notifications/NotificationDispatcher.ktindex 2e8f4d5..559b19f 100644--- a/app/src/main/java/com/gotcha/notifications/NotificationDispatcher.kt+++ b/app/src/main/java/com/gotcha/notifications/NotificationDispatcher.kt@@ -36,6 +36,7 @@ class NotificationDispatcher(private val api: NotificationApi,private val store: NotificationStore,private val versionName: String,+ @Suppress("UnusedPrivateProperty")private val openIntent: (url: String) -> Intent = { url ->Intent(Intent.ACTION_VIEW, Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP@@ -127,24 +128,34 @@ class NotificationDispatcher(@Suppress("MissingPermission") // hasPostPermission() is enforced in deliver().private fun postOne(msg: NotificationMessage) {val notifyId = stableNotifyId(msg.id)+ val tapIntent = Intent(context, com.gotcha.MainActivity::class.java).apply {+ action = ACTION_SHOW_NOTIFICATION+ putExtra(EXTRA_NOTIFICATION_ID, notifyId)+ putExtra(EXTRA_NOTIFICATION_TITLE, msg.title)+ putExtra(EXTRA_NOTIFICATION_BODY, msg.body)+ if (!msg.url.isNullOrBlank() && msg.url.startsWith("https://")) {+ putExtra(EXTRA_NOTIFICATION_URL, msg.url)+ }+ flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP+ }+ val pending = PendingIntent.getActivity(+ context,+ notifyId,+ tapIntent,+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE+ )+val builder = NotificationCompat.Builder(context, CHANNEL_ID).setSmallIcon(com.gotcha.R.drawable.ic_notification).setContentTitle(msg.title).setContentText(msg.body)+ .setStyle(NotificationCompat.BigTextStyle().bigText(msg.body)).setPriority(msg.androidPriority).setCategory(NotificationCompat.CATEGORY_MESSAGE).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setAutoCancel(true)- if (!msg.url.isNullOrBlank() && msg.url.startsWith("https://")) {- val intent = openIntent(msg.url)- val pending = PendingIntent.getActivity(- context,- notifyId,- intent,- PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE- )- builder.setContentIntent(pending)- }+ .setContentIntent(pending)+NotificationManagerCompat.from(context).notify(notifyId, builder.build())}@@ -214,6 +225,11 @@ class NotificationDispatcher(companion object {const val CHANNEL_ID = "gotcha_messages"+ const val ACTION_SHOW_NOTIFICATION = "com.gotcha.ACTION_SHOW_NOTIFICATION"+ const val EXTRA_NOTIFICATION_ID = "com.gotcha.NOTIFICATION_ID"+ const val EXTRA_NOTIFICATION_TITLE = "com.gotcha.NOTIFICATION_TITLE"+ const val EXTRA_NOTIFICATION_BODY = "com.gotcha.NOTIFICATION_BODY"+ const val EXTRA_NOTIFICATION_URL = "com.gotcha.NOTIFICATION_URL"private const val TAG = "NotificationDispatcher"}}diff --git a/app/src/main/java/com/gotcha/notifications/NotificationsModels.kt b/app/src/main/java/com/gotcha/notifications/NotificationsModels.ktindex 2db43d7..ca9430c 100644--- a/app/src/main/java/com/gotcha/notifications/NotificationsModels.kt+++ b/app/src/main/java/com/gotcha/notifications/NotificationsModels.kt@@ -42,3 +42,13 @@ data class NotificationMessage(else -> 0 // NotificationCompat.PRIORITY_DEFAULT}}++/**+ * Payload model for presenting a full notification in a UI dialog.+ */+data class NotificationPayload(+ val id: Int,+ val title: String,+ val body: String,+ val url: String? = null+)diff --git a/app/src/main/java/com/gotcha/tools/AlarmReceiver.kt b/app/src/main/java/com/gotcha/tools/AlarmReceiver.ktindex 4e91511..d3508f2 100644--- a/app/src/main/java/com/gotcha/tools/AlarmReceiver.kt+++ b/app/src/main/java/com/gotcha/tools/AlarmReceiver.kt@@ -40,12 +40,27 @@ class AlarmReceiver : BroadcastReceiver() {private fun showNotification(context: Context, tag: String, text: String, notifyId: Int, vibrate: Boolean) {val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager+ val tapIntent = Intent(context, com.gotcha.MainActivity::class.java).apply {+ action = com.gotcha.notifications.NotificationDispatcher.ACTION_SHOW_NOTIFICATION+ putExtra(com.gotcha.notifications.NotificationDispatcher.EXTRA_NOTIFICATION_ID, notifyId)+ putExtra(com.gotcha.notifications.NotificationDispatcher.EXTRA_NOTIFICATION_TITLE, "Gotcha")+ putExtra(com.gotcha.notifications.NotificationDispatcher.EXTRA_NOTIFICATION_BODY, text)+ flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP+ }+ val pending = android.app.PendingIntent.getActivity(+ context,+ notifyId,+ tapIntent,+ android.app.PendingIntent.FLAG_UPDATE_CURRENT or android.app.PendingIntent.FLAG_IMMUTABLE+ )val notification = NotificationCompat.Builder(context, if (vibrate) CHANNEL_ID else CHANNEL_ID_SILENT).setSmallIcon(android.R.drawable.ic_lock_idle_alarm).setContentTitle("Gotcha").setContentText(text)+ .setStyle(NotificationCompat.BigTextStyle().bigText(text)).setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true)+ .setContentIntent(pending).build()nm.notify(tag, notifyId, notification)}diff --git a/app/src/main/java/com/gotcha/ui/NotificationDetailDialog.kt b/app/src/main/java/com/gotcha/ui/NotificationDetailDialog.ktnew file mode 100644index 0000000..7d6039c--- /dev/null+++ b/app/src/main/java/com/gotcha/ui/NotificationDetailDialog.kt@@ -0,0 +1,82 @@+package com.gotcha.ui++import android.content.Intent+import android.net.Uri+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.heightIn+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll+import androidx.compose.material3.AlertDialog+import androidx.compose.material3.Button+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Text+import androidx.compose.material3.TextButton+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.unit.dp+import com.gotcha.notifications.NotificationPayload++@Composable+fun NotificationDetailDialog(+ payload: NotificationPayload,+ onDismiss: () -> Unit+) {+ val context = LocalContext.current+ val scrollState = rememberScrollState()++ AlertDialog(+ onDismissRequest = onDismiss,+ title = {+ Text(+ text = payload.title,+ style = MaterialTheme.typography.titleLarge+ )+ },+ text = {+ Box(+ modifier = Modifier+ .fillMaxWidth()+ .heightIn(max = 350.dp)+ .verticalScroll(scrollState)+ ) {+ Text(+ text = payload.body,+ style = MaterialTheme.typography.bodyMedium,+ color = MaterialTheme.colorScheme.onSurfaceVariant+ )+ }+ },+ confirmButton = {+ val hasValidUrl = !payload.url.isNullOrBlank() && payload.url.startsWith("https://")+ if (hasValidUrl) {+ Button(+ onClick = {+ onDismiss()+ val intent = Intent(Intent.ACTION_VIEW, Uri.parse(payload.url)).apply {+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)+ }+ try {+ context.startActivity(intent)+ } catch (_: Exception) {}+ }+ ) {+ Text("Open Link")+ }+ } else {+ Button(onClick = onDismiss) {+ Text("OK")+ }+ }+ },+ dismissButton = {+ val hasValidUrl = !payload.url.isNullOrBlank() && payload.url.startsWith("https://")+ if (hasValidUrl) {+ TextButton(onClick = onDismiss) {+ Text("Close")+ }+ }+ }+ )+}diff --git a/app/src/test/java/com/gotcha/notifications/NotificationDispatcherTest.kt b/app/src/test/java/com/gotcha/notifications/NotificationDispatcherTest.ktindex c81cdf4..f5b57d1 100644--- a/app/src/test/java/com/gotcha/notifications/NotificationDispatcherTest.kt+++ b/app/src/test/java/com/gotcha/notifications/NotificationDispatcherTest.kt@@ -170,6 +170,15 @@ class NotificationDispatcherTest {assertEquals(1_000L, store.lastFetchedAt())}+ @Test+ fun `notification intent constants are formatted correctly`() {+ assertEquals("com.gotcha.ACTION_SHOW_NOTIFICATION", NotificationDispatcher.ACTION_SHOW_NOTIFICATION)+ assertEquals("com.gotcha.NOTIFICATION_ID", NotificationDispatcher.EXTRA_NOTIFICATION_ID)+ assertEquals("com.gotcha.NOTIFICATION_TITLE", NotificationDispatcher.EXTRA_NOTIFICATION_TITLE)+ assertEquals("com.gotcha.NOTIFICATION_BODY", NotificationDispatcher.EXTRA_NOTIFICATION_BODY)+ assertEquals("com.gotcha.NOTIFICATION_URL", NotificationDispatcher.EXTRA_NOTIFICATION_URL)+ }+private fun msg(id: String,title: String = "T",