findfamily: per-person arrival and departure notifications (#618)
- Commit
bb1e269709d28151d943a8f7e28cede3a13d405b- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-31 17:00 UTC (3 months ago)
- Parents
b2882a6
Diff
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.ktindex 4482d689ac..6ca2af0d5a 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt@@ -106,6 +106,7 @@ import com.vayunmathur.findfamily.ui.dialogs.encodeBase26 import com.vayunmathur.findfamily.ui.dialogs.GpsFallbackWarningDialog import com.vayunmathur.findfamily.ui.dialogs.SecurityCodeDialog import com.vayunmathur.findfamily.util.FamilyListActions+import com.vayunmathur.findfamily.util.FindFamilyNotificationChannels import com.vayunmathur.findfamily.util.FamilyListUiState import com.vayunmathur.findfamily.util.FindFamilyViewModel import com.vayunmathur.findfamily.util.MainPageActions@@ -714,6 +715,35 @@ fun PersonDetailSheet(state: PersonUiState, actions: PersonActions) { Spacer(Modifier.height(4.dp)) AutoToggleRow(user, state.waypoints, actions) Spacer(Modifier.height(4.dp))+ // Per-person arrival/departure notification settings (issue #618). Each opens the+ // system channel settings so sound/vibration/DND can be tuned independently.+ val context = LocalContext.current+ Row(+ Modifier.fillMaxWidth(),+ horizontalArrangement = Arrangement.spacedBy(8.dp)+ ) {+ OutlinedButton(+ {+ FindFamilyNotificationChannels.openChannelSettings(+ context, user.id, user.name, arrival = true+ )+ },+ Modifier.weight(1f)+ ) {+ Text(stringResource(R.string.notification_settings_arrival))+ }+ OutlinedButton(+ {+ FindFamilyNotificationChannels.openChannelSettings(+ context, user.id, user.name, arrival = false+ )+ },+ Modifier.weight(1f)+ ) {+ Text(stringResource(R.string.notification_settings_departure))+ }+ }+ Spacer(Modifier.height(4.dp)) } OutlinedButton( { actions.changeConnectedContact() },
findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyNotificationChannels.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyNotificationChannels.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyNotificationChannels.ktnew file mode 100644index 0000000000..fcbf42c953--- /dev/null+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyNotificationChannels.kt@@ -0,0 +1,64 @@+package com.vayunmathur.findfamily.util++import android.app.NotificationChannel+import android.app.NotificationChannelGroup+import android.app.NotificationManager+import android.content.Context+import android.content.Intent+import android.provider.Settings+import com.vayunmathur.findfamily.R++/**+ * Per-person, per-event notification channels for arrivals and departures (issue #618).+ *+ * Each tracked person gets their own channel group containing an "Arrivals" and a "Departures"+ * channel. Because Android exposes sound, vibration, importance and Do-Not-Disturb override as+ * per-channel settings, giving every person/event its own channel lets the user tune each one+ * independently from the system notification settings — no custom pickers required.+ *+ * Channel creation is idempotent: re-creating a channel refreshes its name/description/group but+ * leaves any sound/vibration/DND choices the user has made intact.+ */+object FindFamilyNotificationChannels {++ fun entryExitChannelId(userId: Long, arrival: Boolean): String =+ "entry_exit_${userId}_${if (arrival) "arrival" else "departure"}"++ private fun personGroupId(userId: Long): String = "person_$userId"++ /** Ensure the arrival and departure channels for [userId] exist, grouped under [userName]. */+ fun ensureEntryExitChannels(context: Context, userId: Long, userName: String) {+ val manager = context.getSystemService(NotificationManager::class.java) ?: return+ manager.createNotificationChannelGroup(+ NotificationChannelGroup(personGroupId(userId), userName)+ )+ val arrival = NotificationChannel(+ entryExitChannelId(userId, arrival = true),+ context.getString(R.string.notification_channel_arrival_name, userName),+ NotificationManager.IMPORTANCE_DEFAULT,+ ).apply {+ description = context.getString(R.string.notification_channel_arrival_desc, userName)+ group = personGroupId(userId)+ }+ val departure = NotificationChannel(+ entryExitChannelId(userId, arrival = false),+ context.getString(R.string.notification_channel_departure_name, userName),+ NotificationManager.IMPORTANCE_DEFAULT,+ ).apply {+ description = context.getString(R.string.notification_channel_departure_desc, userName)+ group = personGroupId(userId)+ }+ manager.createNotificationChannels(listOf(arrival, departure))+ }++ /** Open the system settings screen for this person's arrival or departure channel. */+ fun openChannelSettings(context: Context, userId: Long, userName: String, arrival: Boolean) {+ ensureEntryExitChannels(context, userId, userName)+ val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS).apply {+ putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)+ putExtra(Settings.EXTRA_CHANNEL_ID, entryExitChannelId(userId, arrival))+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)+ }+ context.startActivity(intent)+ }+}
findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingService.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingService.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingService.ktindex 225b59e331..4917164e90 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingService.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingService.kt@@ -363,10 +363,10 @@ class LocationTrackingService : Service(), SensorEventListener { if (currentId != prevId && user.id != Networking.userid) { if (currentId != null) { val enteredName = currentWaypoint?.name ?: displayName- createNotificationWithCategory(user.name, getString(R.string.notification_entered_waypoint, user.name, enteredName), "ENTRY_EXIT", user.id)+ notifyEntryExit(user, getString(R.string.notification_entered_waypoint, user.name, enteredName), arrival = true) } else if (prevId != null) { val exitedName = currentWaypoints.find { it.id == prevId }?.name ?: user.locationName- createNotificationWithCategory(user.name, getString(R.string.notification_exited_waypoint, user.name, exitedName), "ENTRY_EXIT", user.id)+ notifyEntryExit(user, getString(R.string.notification_exited_waypoint, user.name, exitedName), arrival = false) } } }@@ -757,6 +757,25 @@ class LocationTrackingService : Service(), SensorEventListener { manager.notify(notificationId, notification) } + /**+ * Post an arrival/departure notification on the person's own per-event channel (issue #618),+ * so its sound, vibration and DND behaviour can be tuned independently in system settings.+ */+ private fun notifyEntryExit(user: User, message: String, arrival: Boolean) {+ val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager+ FindFamilyNotificationChannels.ensureEntryExitChannels(this, user.id, user.name)+ val channelId = FindFamilyNotificationChannels.entryExitChannelId(user.id, arrival)+ val notification = NotificationCompat.Builder(this, channelId)+ .setContentTitle(user.name)+ .setContentText(message)+ .setSmallIcon(R.drawable.ic_launcher_foreground)+ .setAutoCancel(true)+ .build()+ val event = if (arrival) "ARRIVAL" else "DEPARTURE"+ val notificationId = "${user.id}::ENTRY_EXIT::$event".hashCode()+ manager.notify(notificationId, notification)+ }+ /** * Notification fired when an incoming UWB Find Nearby (UWB) request arrives * via the heartbeat. Tapping it opens MainActivity with a deep link to the
findfamily/src/main/res/values/strings.xml
diff --git a/findfamily/src/main/res/values/strings.xml b/findfamily/src/main/res/values/strings.xmlindex 862a039f6e..72f2bb9d2a 100644--- a/findfamily/src/main/res/values/strings.xml+++ b/findfamily/src/main/res/values/strings.xml@@ -15,6 +15,19 @@ <!-- LocationTrackingService: Notification channel description for waypoint entry/exit events --> <string name="notification_channel_entry_exit_desc">Notifications for when family members enter or leave waypoints</string> + <!-- Per-person arrival channel name. %1$s = person name, e.g. Alice -->+ <string name="notification_channel_arrival_name"><xliff:g id="person_name" example="Alice">%1$s</xliff:g> · Arrivals</string>+ <!-- Per-person arrival channel description. %1$s = person name -->+ <string name="notification_channel_arrival_desc">Notifications when <xliff:g id="person_name" example="Alice">%1$s</xliff:g> arrives at a place</string>+ <!-- Per-person departure channel name. %1$s = person name -->+ <string name="notification_channel_departure_name"><xliff:g id="person_name" example="Alice">%1$s</xliff:g> · Departures</string>+ <!-- Per-person departure channel description. %1$s = person name -->+ <string name="notification_channel_departure_desc">Notifications when <xliff:g id="person_name" example="Alice">%1$s</xliff:g> leaves a place</string>+ <!-- PersonDetailSheet: button opening system settings for this person's arrival notifications -->+ <string name="notification_settings_arrival">Arrival alerts</string>+ <!-- PersonDetailSheet: button opening system settings for this person's departure notifications -->+ <string name="notification_settings_departure">Departure alerts</string>+ <!-- LocationTrackingService: Foreground service notification title when tracking is active. Noun phrase --> <string name="notification_tracking_title">FindFamily is active</string> <!-- LocationTrackingService: Foreground service notification body. Sentence explaining sharing state -->