Skip to content

Commit 40cd781

Browse files
committed
Add preventDefault overload with discard parameter
Must use function overload instead of default parameter due to java limitation. @jvmoverloads does not work when the default parameter is defined in an interface
1 parent 1bda4eb commit 40cd781

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/notifications/INotificationWillDisplayEvent.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ interface INotificationWillDisplayEvent {
3838
* caller still has the option to display the notification by calling `notification.display()`.
3939
*/
4040
fun preventDefault()
41+
42+
/**
43+
* Call this to prevent OneSignal from displaying the notification automatically.
44+
* @param discard an [preventDefault] set to true to dismiss the notification with no
45+
* possibility of displaying it in the future.
46+
*/
47+
fun preventDefault(discard: Boolean)
4148
}

OneSignalSDK/onesignal/notifications/src/main/java/com/onesignal/notifications/internal/NotificationWillDisplayEvent.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ internal class NotificationWillDisplayEvent(
77
override val notification: Notification,
88
) : INotificationWillDisplayEvent {
99
var isPreventDefault: Boolean = false
10+
var discard: Boolean = false
1011

1112
override fun preventDefault() {
13+
preventDefault(false)
14+
}
15+
16+
override fun preventDefault(discard: Boolean) {
1217
Logging.debug("NotificationWillDisplayEvent.preventDefault()")
1318
isPreventDefault = true
19+
this.discard = discard
1420
}
1521
}

0 commit comments

Comments
 (0)