@@ -80,10 +80,26 @@ class NotificationHelper(private val context: Context) {
8080 // A notification can be shown as a bubble by calling setBubbleMetadata()
8181 .setBubbleMetadata(
8282 Notification .BubbleMetadata .Builder ()
83+ .createIntentBubble(
84+ // The Intent to be used for the expanded bubble.
85+ PendingIntent .getActivity(
86+ context,
87+ REQUEST_BUBBLE ,
88+ // Launch BubbleActivity as the expanded bubble.
89+ Intent (context, BubbleActivity ::class .java)
90+ .setAction(Intent .ACTION_VIEW )
91+ .setData(
92+ Uri .parse(
93+ " https://android.example.com/chat/${chat.contact.id} "
94+ )
95+ ),
96+ PendingIntent .FLAG_UPDATE_CURRENT
97+ ),
98+ // The icon of the bubble.
99+ icon
100+ )
83101 // The height of the expanded bubble.
84102 .setDesiredHeight(context.resources.getDimensionPixelSize(R .dimen.bubble_height))
85- // The icon of the bubble.
86- .setIcon(icon)
87103 .apply {
88104 // When the bubble is explicitly opened by the user, we can show the bubble
89105 // automatically in the expanded state. This works only when the app is in
@@ -93,18 +109,6 @@ class NotificationHelper(private val context: Context) {
93109 setSuppressNotification(true )
94110 }
95111 }
96- // The Intent to be used for the expanded bubble.
97- .setIntent(
98- PendingIntent .getActivity(
99- context,
100- REQUEST_BUBBLE ,
101- // Launch BubbleActivity as the expanded bubble.
102- Intent (context, BubbleActivity ::class .java)
103- .setAction(Intent .ACTION_VIEW )
104- .setData(Uri .parse(" https://android.example.com/chat/${chat.contact.id} " )),
105- PendingIntent .FLAG_UPDATE_CURRENT
106- )
107- )
108112 .build()
109113 )
110114 // The user can turn off the bubble in system settings. In that case, this notification
@@ -130,36 +134,33 @@ class NotificationHelper(private val context: Context) {
130134
131135 if (fromUser) {
132136 // This is a Bubble explicitly opened by the user.
133- builder.setContentText(context.getString(R .string.chat_with_contact, chat.contact.name))
137+ builder
138+ .setStyle(
139+ Notification .MessagingStyle (person)
140+ .addMessage(
141+ context.getString(R .string.chat_with_contact, chat.contact.name),
142+ System .currentTimeMillis(),
143+ person
144+ )
145+ .setGroupConversation(false )
146+ )
147+ .setContentText(context.getString(R .string.chat_with_contact, chat.contact.name))
134148 } else {
135149 // Let's add some more content to the notification in case it falls back to a normal
136150 // notification.
137151 val lastOutgoingId = chat.messages.last { ! it.isIncoming }.id
138152 val newMessages = chat.messages.filter { message ->
139153 message.id > lastOutgoingId
140154 }
141- val lastMessage = newMessages.last()
142155 builder
143156 .setStyle(
144- if (lastMessage.photo != null ) {
145- Notification .BigPictureStyle ()
146- .bigPicture(
147- BitmapFactory .decodeResource(
148- context.resources,
149- lastMessage.photo
150- )
151- )
152- .bigLargeIcon(icon)
153- .setSummaryText(lastMessage.text)
154- } else {
155- Notification .MessagingStyle (person)
156- .apply {
157- for (message in newMessages) {
158- addMessage(message.text, message.timestamp, person)
159- }
157+ Notification .MessagingStyle (person)
158+ .apply {
159+ for (message in newMessages) {
160+ addMessage(message.text, message.timestamp, person)
160161 }
161- .setGroupConversation( false )
162- }
162+ }
163+ .setGroupConversation( false )
163164 )
164165 .setContentText(newMessages.joinToString(" \n " ) { it.text })
165166 .setWhen(newMessages.last().timestamp)
0 commit comments