From 6eaf2a8784ed58fa37f97f0c0e4e6bac32ba6f41 Mon Sep 17 00:00:00 2001 From: ajp_anton Date: Sat, 8 Aug 2026 04:33:16 +0000 Subject: [PATCH] Capture later structured messaging updates --- .../capture/NotificationSnapshot.kt | 10 ++++++---- .../notificationlog/helper/MainActivity.kt | 14 +++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/se/ajpanton/notificationlog/capture/NotificationSnapshot.kt b/app/src/main/java/se/ajpanton/notificationlog/capture/NotificationSnapshot.kt index 7b5e0f0..53a4895 100644 --- a/app/src/main/java/se/ajpanton/notificationlog/capture/NotificationSnapshot.kt +++ b/app/src/main/java/se/ajpanton/notificationlog/capture/NotificationSnapshot.kt @@ -56,10 +56,12 @@ object NotificationContents { /** MessagingStyle also populates generic title/text fields with an alternate rendering. */ private fun messagingContents(extras: Bundle): String? { val parts = linkedSetOf() - Notification.MessagingStyle.Message.getMessagesFromBundleArray( - extras.getParcelableArray(Notification.EXTRA_MESSAGES, Bundle::class.java), - ).forEach { message -> - listOfNotNull(message.senderPerson?.name, message.text).joinToString(": ").addTo(parts) + listOf(Notification.EXTRA_HISTORIC_MESSAGES, Notification.EXTRA_MESSAGES).forEach { key -> + Notification.MessagingStyle.Message.getMessagesFromBundleArray( + extras.getParcelableArray(key, Bundle::class.java), + ).forEach { message -> + listOfNotNull(message.senderPerson?.name, message.text).joinToString(": ").addTo(parts) + } } return parts.takeIf { it.isNotEmpty() }?.joinToString("\n") } diff --git a/test-helper/src/main/java/se/ajpanton/notificationlog/helper/MainActivity.kt b/test-helper/src/main/java/se/ajpanton/notificationlog/helper/MainActivity.kt index 2ef99e6..409df06 100644 --- a/test-helper/src/main/java/se/ajpanton/notificationlog/helper/MainActivity.kt +++ b/test-helper/src/main/java/se/ajpanton/notificationlog/helper/MainActivity.kt @@ -46,7 +46,8 @@ class MainActivity : AppCompatActivity() { when (action) { "post_text" -> postText("Text message") "edit_text" -> postText("Edited message") - "messaging" -> postMessaging() + "messaging" -> postMessaging(updated = false) + "messaging_update" -> postMessaging(updated = true) "image" -> postImage() "dismissible" -> postDismissible() "big_text" -> postBigText() @@ -66,12 +67,14 @@ class MainActivity : AppCompatActivity() { private fun postText(text: String) = manager.notify(TEXT_ID, base().setContentTitle("Helper").setContentText(text).build()) - private fun postMessaging() { + private fun postMessaging(updated: Boolean) { val me = Person.Builder().setName("Me").build() val alice = Person.Builder().setName("Alice").build() - val style = Notification.MessagingStyle(me) - .addMessage("Hello from Alice", 1, alice) - .addMessage("A reply from me", 2, null as Person?) + val style = Notification.MessagingStyle(me).addMessage("Hello from Alice", 1, alice) + if (updated) { + style.addMessage("Another message from Alice", 2, alice) + .addMessage("A reply from me", 3, null as Person?) + } manager.notify(MESSAGING_ID, base().setSmallIcon(android.R.drawable.ic_dialog_email).setStyle(style).build()) } @@ -126,6 +129,7 @@ class MainActivity : AppCompatActivity() { const val GROUP_KEY = "helper-group" val ACTIONS = listOf( "Post text" to "post_text", "Edit text" to "edit_text", "Post messaging" to "messaging", + "Update messaging" to "messaging_update", "Post image" to "image", "Post dismissible" to "dismissible", "Post big text" to "big_text", "Post very long text" to "very_long_text", "Post inbox" to "inbox", "Post progress" to "progress", "Update progress" to "progress_update",