Capture later structured messaging updates
This commit is contained in:
@@ -56,10 +56,12 @@ object NotificationContents {
|
|||||||
/** MessagingStyle also populates generic title/text fields with an alternate rendering. */
|
/** MessagingStyle also populates generic title/text fields with an alternate rendering. */
|
||||||
private fun messagingContents(extras: Bundle): String? {
|
private fun messagingContents(extras: Bundle): String? {
|
||||||
val parts = linkedSetOf<String>()
|
val parts = linkedSetOf<String>()
|
||||||
Notification.MessagingStyle.Message.getMessagesFromBundleArray(
|
listOf(Notification.EXTRA_HISTORIC_MESSAGES, Notification.EXTRA_MESSAGES).forEach { key ->
|
||||||
extras.getParcelableArray(Notification.EXTRA_MESSAGES, Bundle::class.java),
|
Notification.MessagingStyle.Message.getMessagesFromBundleArray(
|
||||||
).forEach { message ->
|
extras.getParcelableArray(key, Bundle::class.java),
|
||||||
listOfNotNull(message.senderPerson?.name, message.text).joinToString(": ").addTo(parts)
|
).forEach { message ->
|
||||||
|
listOfNotNull(message.senderPerson?.name, message.text).joinToString(": ").addTo(parts)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return parts.takeIf { it.isNotEmpty() }?.joinToString("\n")
|
return parts.takeIf { it.isNotEmpty() }?.joinToString("\n")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
when (action) {
|
when (action) {
|
||||||
"post_text" -> postText("Text message")
|
"post_text" -> postText("Text message")
|
||||||
"edit_text" -> postText("Edited message")
|
"edit_text" -> postText("Edited message")
|
||||||
"messaging" -> postMessaging()
|
"messaging" -> postMessaging(updated = false)
|
||||||
|
"messaging_update" -> postMessaging(updated = true)
|
||||||
"image" -> postImage()
|
"image" -> postImage()
|
||||||
"dismissible" -> postDismissible()
|
"dismissible" -> postDismissible()
|
||||||
"big_text" -> postBigText()
|
"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 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 me = Person.Builder().setName("Me").build()
|
||||||
val alice = Person.Builder().setName("Alice").build()
|
val alice = Person.Builder().setName("Alice").build()
|
||||||
val style = Notification.MessagingStyle(me)
|
val style = Notification.MessagingStyle(me).addMessage("Hello from Alice", 1, alice)
|
||||||
.addMessage("Hello from Alice", 1, alice)
|
if (updated) {
|
||||||
.addMessage("A reply from me", 2, null as Person?)
|
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())
|
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"
|
const val GROUP_KEY = "helper-group"
|
||||||
val ACTIONS = listOf(
|
val ACTIONS = listOf(
|
||||||
"Post text" to "post_text", "Edit text" to "edit_text", "Post messaging" to "messaging",
|
"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 image" to "image", "Post dismissible" to "dismissible", "Post big text" to "big_text",
|
||||||
"Post very long text" to "very_long_text",
|
"Post very long text" to "very_long_text",
|
||||||
"Post inbox" to "inbox", "Post progress" to "progress", "Update progress" to "progress_update",
|
"Post inbox" to "inbox", "Post progress" to "progress", "Update progress" to "progress_update",
|
||||||
|
|||||||
Reference in New Issue
Block a user