Commit 6c62d59b authored by Leonardo Aramaki's avatar Leonardo Aramaki

Build and show notifications on android N the same way as of O

parent 941cfa58
...@@ -130,9 +130,9 @@ object PushManager { ...@@ -130,9 +130,9 @@ object PushManager {
} else { } else {
notIdListForHostname.add(0, lastPushMessage) notIdListForHostname.add(0, lastPushMessage)
} }
if (isAndroidVersionAtLeast(Build.VERSION_CODES.O)) { if (isAndroidVersionAtLeast(Build.VERSION_CODES.N)) {
val notification = createSingleNotificationForOreo(context, lastPushMessage) val notification = createSingleNotificationForNougatAndAbove(context, lastPushMessage)
val groupNotification = createGroupNotificationForOreo(context, lastPushMessage) val groupNotification = createGroupNotificationForNougatAndAbove(context, lastPushMessage)
manager.notify(notId, notification) manager.notify(notId, notification)
manager.notify(groupTuple.first, groupNotification) manager.notify(groupTuple.first, groupNotification)
} else { } else {
...@@ -209,21 +209,16 @@ object PushManager { ...@@ -209,21 +209,16 @@ object PushManager {
} }
} }
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.N)
private fun createGroupNotificationForOreo(context: Context, lastPushMessage: PushMessage): Notification { private fun createGroupNotificationForNougatAndAbove(context: Context, lastPushMessage: PushMessage): Notification {
with(lastPushMessage) { with(lastPushMessage) {
val manager: NotificationManager = val manager: NotificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val id = notificationId.toInt() val id = notificationId.toInt()
val contentIntent = getContentIntent(context, id, lastPushMessage, singleConversation = true) val contentIntent = getContentIntent(context, id, lastPushMessage, singleConversation = true)
val deleteIntent = getDismissIntent(context, lastPushMessage) val deleteIntent = getDismissIntent(context, lastPushMessage)
val groupChannel = NotificationChannel(host, host, NotificationManager.IMPORTANCE_HIGH)
groupChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC val builder = Notification.Builder(context)
groupChannel.enableLights(true)
groupChannel.enableVibration(true)
groupChannel.setShowBadge(true)
manager.createNotificationChannel(groupChannel)
val builder = Notification.Builder(context, host)
.setWhen(createdAt) .setWhen(createdAt)
.setContentTitle(title.fromHtml()) .setContentTitle(title.fromHtml())
.setContentText(message.fromHtml()) .setContentText(message.fromHtml())
...@@ -233,6 +228,16 @@ object PushManager { ...@@ -233,6 +228,16 @@ object PushManager {
.setDeleteIntent(deleteIntent) .setDeleteIntent(deleteIntent)
.setMessageNotification(context) .setMessageNotification(context)
if (isAndroidVersionAtLeast(Build.VERSION_CODES.O)) {
builder.setChannelId(host)
val groupChannel = NotificationChannel(host, host, NotificationManager.IMPORTANCE_HIGH)
groupChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
groupChannel.enableLights(false)
groupChannel.enableVibration(true)
groupChannel.setShowBadge(true)
manager.createNotificationChannel(groupChannel)
}
val subText = RocketChatCache(context).getHostSiteName(host) val subText = RocketChatCache(context).getHostSiteName(host)
if (subText.isNotEmpty()) { if (subText.isNotEmpty()) {
builder.setSubText(subText) builder.setSubText(subText)
...@@ -308,8 +313,8 @@ object PushManager { ...@@ -308,8 +313,8 @@ object PushManager {
} }
} }
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.N)
private fun createSingleNotificationForOreo(context: Context, lastPushMessage: PushMessage): Notification { private fun createSingleNotificationForNougatAndAbove(context: Context, lastPushMessage: PushMessage): Notification {
val manager: NotificationManager = val manager: NotificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
...@@ -318,13 +323,7 @@ object PushManager { ...@@ -318,13 +323,7 @@ object PushManager {
val contentIntent = getContentIntent(context, id, lastPushMessage) val contentIntent = getContentIntent(context, id, lastPushMessage)
val deleteIntent = getDismissIntent(context, lastPushMessage) val deleteIntent = getDismissIntent(context, lastPushMessage)
val channel = NotificationChannel(host, host, NotificationManager.IMPORTANCE_HIGH) val builder = Notification.Builder(context)
channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
channel.enableLights(true)
channel.enableVibration(true)
channel.setShowBadge(true)
manager.createNotificationChannel(channel)
val builder = Notification.Builder(context, host)
.setWhen(createdAt) .setWhen(createdAt)
.setContentTitle(title.fromHtml()) .setContentTitle(title.fromHtml())
.setContentText(message.fromHtml()) .setContentText(message.fromHtml())
...@@ -335,6 +334,16 @@ object PushManager { ...@@ -335,6 +334,16 @@ object PushManager {
.setMessageNotification(context) .setMessageNotification(context)
.addReplyAction(context, lastPushMessage) .addReplyAction(context, lastPushMessage)
if (isAndroidVersionAtLeast(android.os.Build.VERSION_CODES.O)) {
builder.setChannelId(host)
val channel = NotificationChannel(host, host, NotificationManager.IMPORTANCE_HIGH)
channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
channel.enableLights(false)
channel.enableVibration(true)
channel.setShowBadge(true)
manager.createNotificationChannel(channel)
}
val subText = RocketChatCache(context).getHostSiteName(lastPushMessage.host) val subText = RocketChatCache(context).getHostSiteName(lastPushMessage.host)
if (subText.isNotEmpty()) { if (subText.isNotEmpty()) {
builder.setSubText(subText) builder.setSubText(subText)
...@@ -344,8 +353,6 @@ object PushManager { ...@@ -344,8 +353,6 @@ object PushManager {
val pushMessageList = hostToPushMessageList.get(host) val pushMessageList = hostToPushMessageList.get(host)
pushMessageList?.let { pushMessageList?.let {
val messageCount = pushMessageList.size
val inbox = Notification.InboxStyle() val inbox = Notification.InboxStyle()
val userMessages = pushMessageList.filter { val userMessages = pushMessageList.filter {
...@@ -419,7 +426,7 @@ object PushManager { ...@@ -419,7 +426,7 @@ object PushManager {
return this return this
} }
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.N)
private fun Notification.Builder.setMessageNotification(ctx: Context): Notification.Builder { private fun Notification.Builder.setMessageNotification(ctx: Context): Notification.Builder {
val res = ctx.resources val res = ctx.resources
val smallIcon = res.getIdentifier( val smallIcon = res.getIdentifier(
......
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