@@ -16,7 +16,6 @@ import com.urbanairship.config.AirshipRuntimeConfig
16
16
import com.urbanairship.json.JsonMap
17
17
import com.urbanairship.liveupdate.data.LiveUpdateDatabase
18
18
import com.urbanairship.liveupdate.notification.LiveUpdatePayload
19
- import com.urbanairship.push.PushListener
20
19
import com.urbanairship.push.PushManager
21
20
22
21
/* *
@@ -38,13 +37,7 @@ internal constructor(
38
37
) : AirshipComponent (context, dataStore) {
39
38
40
39
private val isFeatureEnabled: Boolean
41
- get() = privacyManager.isEnabled(FEATURE_PUSH ) && channel.id != null
42
-
43
- private val pushListener = PushListener { message, _ ->
44
- message.liveUpdatePayload
45
- ?.let { LiveUpdatePayload .fromJson(it) }
46
- ?.let { registrar.onLiveUpdatePushReceived(message, it) }
47
- }
40
+ get() = privacyManager.isEnabled(FEATURE_PUSH )
48
41
49
42
public constructor (
50
43
context: Context ,
@@ -158,7 +151,15 @@ internal constructor(
158
151
public override fun init () {
159
152
super .init ()
160
153
154
+ channel.addChannelListener { updateLiveActivityEnablement() }
161
155
privacyManager.addListener { updateLiveActivityEnablement() }
156
+
157
+ pushManager.addPushListener { message, _ ->
158
+ message.liveUpdatePayload
159
+ ?.let { LiveUpdatePayload .fromJson(it) }
160
+ ?.let { registrar.onLiveUpdatePushReceived(message, it) }
161
+ }
162
+
162
163
updateLiveActivityEnablement()
163
164
}
164
165
@@ -169,16 +170,13 @@ internal constructor(
169
170
170
171
private fun updateLiveActivityEnablement () {
171
172
if (isFeatureEnabled) {
172
- pushManager.addPushListener(pushListener)
173
-
174
173
// Check for any active live Updates that have had their notifications cleared.
175
174
// This makes sure we'll end the live update if the notification is dropped due
176
175
// to an app upgrade or other cases where we don't get notified of the dismiss.
177
176
registrar.stopLiveUpdatesForClearedNotifications()
178
177
} else {
179
178
// Clear all live updates.
180
179
registrar.clearAll()
181
- pushManager.removePushListener(pushListener)
182
180
}
183
181
}
184
182
0 commit comments