Commit 89466fdf authored by Leonardo Aramaki's avatar Leonardo Aramaki

Update setting for android O

parent da3d16cd
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<permission <permission
android:name="chat.rocket.android.permission.C2D_MESSAGE" android:name="chat.rocket.android.permission.C2D_MESSAGE"
...@@ -56,10 +57,32 @@ ...@@ -56,10 +57,32 @@
android:permission="com.google.android.c2dm.permission.SEND"> android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter> <intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/> <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.example.gcm"/> <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="chat.rocket.android"/>
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="chat.rocket.android"/>
</intent-filter>
</receiver>
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
android:exported="false" />
<service android:name="com.google.firebase.iid.FirebaseInstanceIdService"
android:exported="true">
<intent-filter android:priority="-500">
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service <service
android:name=".push.gcm.GCMIntentService" android:name=".push.gcm.GCMIntentService"
android:exported="false"> android:exported="false">
......
...@@ -92,13 +92,13 @@ object PushManager { ...@@ -92,13 +92,13 @@ object PushManager {
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notId = pushMessage.notificationId.toInt() val notId = pushMessage.notificationId.toInt()
val groupNotification = createGroupNotification(context, pushMessage)
val groupTuple = groupMap[pushMessage.host] val groupTuple = groupMap[pushMessage.host]
val notification: Notification val notification: Notification
if (isAndroidVersionAtLeast(Build.VERSION_CODES.O)) { if (isAndroidVersionAtLeast(Build.VERSION_CODES.O)) {
notification = createNotificationForOreoAndAbove(context, pushMessage) notification = createNotificationForOreoAndAbove(context, pushMessage)
groupTuple?.let { groupTuple?.let {
val groupNotification = createOreoGroupNotification(context, pushMessage)
notificationManager.notify(groupTuple.first, groupNotification) notificationManager.notify(groupTuple.first, groupNotification)
groupTuple.second.incrementAndGet() groupTuple.second.incrementAndGet()
} }
...@@ -106,6 +106,7 @@ object PushManager { ...@@ -106,6 +106,7 @@ object PushManager {
} else { } else {
notification = createCompatNotification(context, pushMessage) notification = createCompatNotification(context, pushMessage)
groupTuple?.let { groupTuple?.let {
val groupNotification = createCompatGroupNotification(context, pushMessage)
NotificationManagerCompat.from(context).notify(groupTuple.first, groupNotification) NotificationManagerCompat.from(context).notify(groupTuple.first, groupNotification)
groupTuple.second.incrementAndGet() groupTuple.second.incrementAndGet()
} }
...@@ -122,7 +123,7 @@ object PushManager { ...@@ -122,7 +123,7 @@ object PushManager {
} }
} }
private fun createGroupNotification(context: Context, pushMessage: PushMessage): Notification { private fun createCompatGroupNotification(context: Context, pushMessage: PushMessage): Notification {
// Create notification group. // Create notification group.
bundleNotificationsToHost(pushMessage.host) bundleNotificationsToHost(pushMessage.host)
val id = pushMessage.notificationId.toInt() val id = pushMessage.notificationId.toInt()
...@@ -165,6 +166,51 @@ object PushManager { ...@@ -165,6 +166,51 @@ object PushManager {
return notGroupBuilder.build() return notGroupBuilder.build()
} }
@RequiresApi(Build.VERSION_CODES.O)
private fun createOreoGroupNotification(context: Context, pushMessage: PushMessage): Notification {
// Create notification group.
bundleNotificationsToHost(pushMessage.host)
val id = pushMessage.notificationId.toInt()
val contentIntent = getContentIntent(context, id, pushMessage, group = true)
val deleteIntent = getDismissIntent(context, id)
val notGroupBuilder = Notification.Builder(context, pushMessage.notificationId)
.setWhen(pushMessage.createdAt)
.setChannelId(pushMessage.notificationId)
.setContentTitle(pushMessage.title.fromHtml())
.setContentText(pushMessage.message.fromHtml())
.setGroup(pushMessage.host)
.setGroupSummary(true)
.setStyle(Notification.BigTextStyle().bigText(pushMessage.message.fromHtml()))
.setContentIntent(contentIntent)
.setDeleteIntent(deleteIntent)
.setMessageNotification(context)
val subText = RocketChatCache(context).getHostSiteName(pushMessage.host)
if (subText.isNotEmpty()) {
notGroupBuilder.setSubText(subText)
}
val messages = messageStack.get(pushMessage.notificationId.toInt())
val messageCount = messages.size
if (messageCount > 1) {
val summary = pushMessage.summaryText.replace("%n%", messageCount.toString())
val inbox = Notification.InboxStyle()
.setBigContentTitle(pushMessage.title.fromHtml())
.setSummaryText(summary)
notGroupBuilder.setStyle(inbox)
} else {
val bigText = Notification.BigTextStyle()
.bigText(pushMessage.message.fromHtml())
.setBigContentTitle(pushMessage.title.fromHtml())
notGroupBuilder.setStyle(bigText)
}
return notGroupBuilder.build()
}
private fun createCompatNotification(context: Context, pushMessage: PushMessage): Notification { private fun createCompatNotification(context: Context, pushMessage: PushMessage): Notification {
with(pushMessage) { with(pushMessage) {
val id = notificationId.toInt() val id = notificationId.toInt()
...@@ -219,7 +265,7 @@ object PushManager { ...@@ -219,7 +265,7 @@ object PushManager {
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.O)
private fun createNotificationForOreoAndAbove(context: Context, pushMessage: PushMessage): Notification { private fun createNotificationForOreoAndAbove(context: Context, pushMessage: PushMessage): Notification {
val notificationManager: NotificationManager = val manager: NotificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
with(pushMessage) { with(pushMessage) {
...@@ -228,8 +274,14 @@ object PushManager { ...@@ -228,8 +274,14 @@ object PushManager {
val deleteIntent = getDismissIntent(context, id) val deleteIntent = getDismissIntent(context, id)
val channel = NotificationChannel(notificationId, sender.username, NotificationManager.IMPORTANCE_HIGH) val channel = NotificationChannel(notificationId, sender.username, NotificationManager.IMPORTANCE_HIGH)
val notificationBuilder = Notification.Builder(context, pushMessage.rid) channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
channel.enableLights(true)
channel.enableVibration(true)
channel.setShowBadge(true)
manager.createNotificationChannel(channel)
val notificationBuilder = Notification.Builder(context, notificationId)
.setWhen(createdAt) .setWhen(createdAt)
.setChannelId(notificationId)
.setContentTitle(title.fromHtml()) .setContentTitle(title.fromHtml())
.setContentText(message.fromHtml()) .setContentText(message.fromHtml())
.setNumber(count.toInt()) .setNumber(count.toInt())
...@@ -246,7 +298,6 @@ object PushManager { ...@@ -246,7 +298,6 @@ object PushManager {
channel.enableLights(true) channel.enableLights(true)
channel.enableVibration(true) channel.enableVibration(true)
notificationManager.createNotificationChannel(channel)
if ("inbox" == style) { if ("inbox" == style) {
val messages = messageStack.get(notificationId.toInt()) val messages = messageStack.get(notificationId.toInt())
......
...@@ -36,7 +36,7 @@ public class GCMIntentService extends GcmListenerService implements PushConstant ...@@ -36,7 +36,7 @@ public class GCMIntentService extends GcmListenerService implements PushConstant
PushNotificationHandler pushNotificationHandler = new PushNotificationHandler(); PushNotificationHandler pushNotificationHandler = new PushNotificationHandler();
// pushNotificationHandler.showNotificationIfPossible(applicationContext, extras); pushNotificationHandler.showNotificationIfPossible(applicationContext, extras);
PushManager.INSTANCE.handle(applicationContext, extras); PushManager.INSTANCE.handle(applicationContext, extras);
} }
......
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