Skip to content

Commit f55532b

Browse files
authored
Merge pull request #173 from Notificare/feature/SDK-556-subscription-id-event
Add onSubscriptionIdChanged event
2 parents 67714a6 + 05aaae9 commit f55532b

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

notificare-push/src/main/java/re/notifica/push/NotificarePushIntentReceiver.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import re.notifica.push.ktx.INTENT_ACTION_ACTION_OPENED
1111
import re.notifica.push.ktx.INTENT_ACTION_LIVE_ACTIVITY_UPDATE
1212
import re.notifica.push.ktx.INTENT_ACTION_NOTIFICATION_OPENED
1313
import re.notifica.push.ktx.INTENT_ACTION_NOTIFICATION_RECEIVED
14+
import re.notifica.push.ktx.INTENT_ACTION_SUBSCRIPTION_ID_CHANGED
1415
import re.notifica.push.ktx.INTENT_ACTION_SYSTEM_NOTIFICATION_RECEIVED
1516
import re.notifica.push.ktx.INTENT_ACTION_TOKEN_CHANGED
1617
import re.notifica.push.ktx.INTENT_ACTION_UNKNOWN_NOTIFICATION_RECEIVED
1718
import re.notifica.push.ktx.INTENT_EXTRA_DELIVERY_MECHANISM
1819
import re.notifica.push.ktx.INTENT_EXTRA_LIVE_ACTIVITY_UPDATE
20+
import re.notifica.push.ktx.INTENT_EXTRA_SUBSCRIPTION_ID
1921
import re.notifica.push.ktx.INTENT_EXTRA_TOKEN
2022
import re.notifica.push.models.NotificareLiveActivityUpdate
2123
import re.notifica.push.models.NotificareNotificationDeliveryMechanism
@@ -25,11 +27,16 @@ import re.notifica.push.models.NotificareUnknownNotification
2527
public open class NotificarePushIntentReceiver : BroadcastReceiver() {
2628
override fun onReceive(context: Context, intent: Intent) {
2729
when (intent.action) {
30+
Notificare.INTENT_ACTION_SUBSCRIPTION_ID_CHANGED -> {
31+
val subscriptionId = intent.getStringExtra(Notificare.INTENT_EXTRA_SUBSCRIPTION_ID)
32+
onSubscriptionIdChanged(context, subscriptionId)
33+
}
2834
Notificare.INTENT_ACTION_TOKEN_CHANGED -> {
2935
val token: String = requireNotNull(
3036
intent.getStringExtra(Notificare.INTENT_EXTRA_TOKEN)
3137
)
3238

39+
@Suppress("DEPRECATION")
3340
onTokenChanged(context, token)
3441
}
3542
Notificare.INTENT_ACTION_NOTIFICATION_RECEIVED -> {
@@ -85,6 +92,16 @@ public open class NotificarePushIntentReceiver : BroadcastReceiver() {
8592
}
8693
}
8794

95+
protected open fun onSubscriptionIdChanged(context: Context, subscriptionId: String?) {
96+
NotificareLogger.debug(
97+
"The subscription id changed, please override onSubscriptionIdChanged if you want to receive these intents."
98+
)
99+
}
100+
101+
@Deprecated(
102+
message = "Use onSubscriptionIdChanged() instead.",
103+
replaceWith = ReplaceWith("onSubscriptionIdChanged(context, subscriptionId)")
104+
)
88105
protected open fun onTokenChanged(context: Context, token: String) {
89106
NotificareLogger.debug(
90107
"The push token changed, please override onTokenChanged if you want to receive these intents."

notificare-push/src/main/java/re/notifica/push/internal/NotificarePushImpl.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ import re.notifica.push.ktx.INTENT_ACTION_NOTIFICATION_OPENED
6868
import re.notifica.push.ktx.INTENT_ACTION_NOTIFICATION_RECEIVED
6969
import re.notifica.push.ktx.INTENT_ACTION_QUICK_RESPONSE
7070
import re.notifica.push.ktx.INTENT_ACTION_REMOTE_MESSAGE_OPENED
71+
import re.notifica.push.ktx.INTENT_ACTION_SUBSCRIPTION_ID_CHANGED
7172
import re.notifica.push.ktx.INTENT_ACTION_SYSTEM_NOTIFICATION_RECEIVED
7273
import re.notifica.push.ktx.INTENT_ACTION_TOKEN_CHANGED
7374
import re.notifica.push.ktx.INTENT_ACTION_UNKNOWN_NOTIFICATION_RECEIVED
7475
import re.notifica.push.ktx.INTENT_EXTRA_DELIVERY_MECHANISM
7576
import re.notifica.push.ktx.INTENT_EXTRA_LIVE_ACTIVITY_UPDATE
7677
import re.notifica.push.ktx.INTENT_EXTRA_REMOTE_MESSAGE
78+
import re.notifica.push.ktx.INTENT_EXTRA_SUBSCRIPTION_ID
7779
import re.notifica.push.ktx.INTENT_EXTRA_TEXT_RESPONSE
7880
import re.notifica.push.ktx.INTENT_EXTRA_TOKEN
7981
import re.notifica.push.ktx.logNotificationInfluenced
@@ -928,8 +930,12 @@ internal object NotificarePushImpl : NotificareModule(), NotificarePush, Notific
928930
this@NotificarePushImpl.subscriptionId = token
929931
this@NotificarePushImpl.allowedUI = allowedUI
930932

931-
// TODO: The TOKEN_CHANGED intent does not support null tokens.
932-
// This requires a new intent or a breaking change in the current one.
933+
Notificare.requireContext().sendBroadcast(
934+
Intent(Notificare.requireContext(), intentReceiver)
935+
.setAction(Notificare.INTENT_ACTION_SUBSCRIPTION_ID_CHANGED)
936+
.putExtra(Notificare.INTENT_EXTRA_SUBSCRIPTION_ID, token)
937+
)
938+
933939
if (token != null && previousSubscriptionId != token) {
934940
Notificare.requireContext().sendBroadcast(
935941
Intent(Notificare.requireContext(), intentReceiver)

notificare-push/src/main/java/re/notifica/push/ktx/Augment.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ internal fun Notificare.eventsInternal(): NotificareInternalEventsModule {
1717

1818
// region Intent actions
1919

20+
public val Notificare.INTENT_ACTION_SUBSCRIPTION_ID_CHANGED: String
21+
get() = "re.notifica.intent.action.SubscriptionIdChanged"
22+
2023
public val Notificare.INTENT_ACTION_TOKEN_CHANGED: String
2124
get() = "re.notifica.intent.action.TokenChanged"
2225

@@ -48,6 +51,9 @@ public val Notificare.INTENT_ACTION_LIVE_ACTIVITY_UPDATE: String
4851

4952
// region Intent extras
5053

54+
public val Notificare.INTENT_EXTRA_SUBSCRIPTION_ID: String
55+
get() = "re.notifica.intent.extra.SubscriptionId"
56+
5157
public val Notificare.INTENT_EXTRA_TOKEN: String
5258
get() = "re.notifica.intent.extra.Token"
5359

0 commit comments

Comments
 (0)