Skip to content

WIP - Fix grouping with setColor used in a NSE #2267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Examples/OneSignalDemo/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
}

android {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.onesignal.sdktest.notification

import android.graphics.Color
import android.util.Log
import androidx.core.app.NotificationCompat
import com.onesignal.notifications.INotificationReceivedEvent
import com.onesignal.notifications.INotificationServiceExtension
import com.onesignal.sdktest.R
import com.onesignal.sdktest.constant.Tag

class NotificationServiceExtension : INotificationServiceExtension {
override fun onNotificationReceived(event: INotificationReceivedEvent) {
Log.v(
Tag.LOG_TAG,
"IRemoteNotificationReceivedHandler fired with INotificationReceivedEvent: $event"
)

val notification = event.notification

if (notification.actionButtons != null) {
for (button in notification.actionButtons!!) {
Log.v(
Tag.LOG_TAG,
"ActionButton: $button"
)
}
}

notification.setExtender { builder: NotificationCompat.Builder ->
builder.setColor(Color.GREEN)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ class NotificationGenerationJob(
var overriddenTitleFromExtender: CharSequence? = null
var overriddenSound: Uri? = null
var overriddenFlags: Int? = null
var overriddenColor: Int? = null
var orgFlags: Int? = null
var orgSound: Uri? = null
var orgColor: Int? = null

constructor(jsonPayload: JSONObject, time: ITime) : this(
Notification(jsonPayload, time),
Expand Down Expand Up @@ -73,8 +75,10 @@ class NotificationGenerationJob(
", overriddenTitleFromExtender=" + overriddenTitleFromExtender +
", overriddenSound=" + overriddenSound +
", overriddenFlags=" + overriddenFlags +
", overriddenColor=" + overriddenColor +
", orgFlags=" + orgFlags +
", orgSound=" + orgSound +
", orgColor=" + orgColor +
", notification=" + notification +
'}'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ internal class NotificationDisplayer(
var mNotification = mNotificationField[notificationBuilder] as Notification
notificationJob.orgFlags = mNotification.flags
notificationJob.orgSound = mNotification.sound
notificationJob.orgColor = mNotification.color

notificationBuilder!!.extend(notificationJob.notification!!.notificationExtender!!)
mNotification = mNotificationField[notificationBuilder] as Notification
val mContentTextField =
Expand All @@ -214,6 +216,15 @@ internal class NotificationDisplayer(
val mContentTitle = mContentTitleField[notificationBuilder] as CharSequence?
notificationJob.overriddenBodyFromExtender = mContentText
notificationJob.overriddenTitleFromExtender = mContentTitle

val mColor =
NotificationCompat.Builder::class.java.getDeclaredField("mColor")
mColor.isAccessible = true
val color = mColor[notificationBuilder] as Int?
if (color != notificationJob.orgColor) {
notificationJob.overriddenColor = color
}

if (!notificationJob.isRestoring) {
notificationJob.overriddenFlags = mNotification.flags
notificationJob.overriddenSound = mNotification.sound
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ internal class SummaryNotificationDisplayer(
for (line in summaryList) inboxStyle.addLine(line)
inboxStyle.setBigContentTitle(summaryMessage)
summaryBuilder.setStyle(inboxStyle)

if (notificationJob.overriddenColor != null) {
summaryBuilder.setColor(
notificationJob.overriddenColor!!,
)
}

summaryNotification = summaryBuilder.build()
} else {
// First notification with this group key, post like a normal notification.
Expand Down Expand Up @@ -244,6 +251,13 @@ internal class SummaryNotificationDisplayer(
} catch (t: Throwable) {
// do nothing in this case...Android support lib 26 isn't in the project
}

if (notificationJob.overriddenColor != null) {
summaryBuilder.setColor(
notificationJob.overriddenColor!!,
)
}

summaryNotification = summaryBuilder.build()
_notificationDisplayBuilder.addXiaomiSettings(notifBuilder, summaryNotification)
}
Expand Down Expand Up @@ -282,6 +296,11 @@ internal class SummaryNotificationDisplayer(
notificationJob.overriddenFlags!!,
)
}
if (notificationJob.overriddenColor != null) {
summaryBuilder!!.setColor(
notificationJob.overriddenColor!!,
)
}

// The summary is designed to fit all notifications.
// Default small and large icons are used instead of the payload options to enforce this.
Expand Down
Loading