Commit 87d0435d authored by Leonardo Aramaki's avatar Leonardo Aramaki

Replicate inbox notification build support to Oreo

parent 2c8e5e9c
...@@ -246,6 +246,33 @@ object PushManager { ...@@ -246,6 +246,33 @@ object PushManager {
channel.enableLights(true) channel.enableLights(true)
channel.enableVibration(true) channel.enableVibration(true)
notificationManager.createNotificationChannel(channel) notificationManager.createNotificationChannel(channel)
if ("inbox" == style) {
val messages = messageStack.get(notificationId.toInt())
val messageCount = messages.size
if (messageCount > 1) {
val summary = summaryText.replace("%n%", messageCount.toString())
.fromHtml()
val inbox = NotificationCompat.InboxStyle()
.setBigContentTitle(title.fromHtml())
.setSummaryText(summary)
messages.forEach { msg ->
inbox.addLine(msg.fromHtml())
}
notificationBuilder.setStyle(inbox)
} else {
val bigText = NotificationCompat.BigTextStyle()
.bigText(message.fromHtml())
.setBigContentTitle(title.fromHtml())
notificationBuilder.setStyle(bigText)
}
} else {
notificationBuilder.setContentText(message.fromHtml())
}
return notificationBuilder.build() return notificationBuilder.build()
} }
} }
...@@ -407,28 +434,31 @@ object PushManager { ...@@ -407,28 +434,31 @@ object PushManager {
if (context == null) { if (context == null) {
return return
} }
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val message: CharSequence? = extractMessage(intent) synchronized(this) {
val pushMessage = intent?.extras?.getSerializable("push") as PushMessage? val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val message: CharSequence? = extractMessage(intent)
if (pushMessage != null) { val pushMessage = intent?.extras?.getSerializable("push") as PushMessage?
val singleNotId = pushMessage.notificationId.toInt()
val groupTuple = groupMap.get(pushMessage.host) if (pushMessage != null) {
for (msg in messageStack[singleNotId]) { val singleNotId = pushMessage.notificationId.toInt()
manager.cancel(singleNotId) val groupTuple = groupMap.get(pushMessage.host)
groupTuple?.second?.decrementAndGet() for (msg in messageStack[singleNotId]) {
println("Decremented") manager.cancel(singleNotId)
} groupTuple?.second?.decrementAndGet()
clearMessageBundle(singleNotId) println("Decremented")
if (groupTuple != null) { }
val groupNotId = groupTuple.first clearMessageBundle(singleNotId)
val totalNot = groupTuple.second.get() if (groupTuple != null) {
if (totalNot == 0) { val groupNotId = groupTuple.first
manager.cancel(groupNotId) val totalNot = groupTuple.second.get()
if (totalNot == 0) {
manager.cancel(groupNotId)
}
}
if (message != null) {
sendMessage(context, message, pushMessage.rid)
} }
}
if (message != null) {
sendMessage(context, message, pushMessage.rid)
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment