From 4e8bd7a0d50d371e8ff933d0aa3d9141a8573f8a Mon Sep 17 00:00:00 2001 From: markvdouw Date: Fri, 5 Jan 2024 09:16:04 -0300 Subject: [PATCH] Migration from 16.x to 17.x (latest version) Doc. https://github.com/urbanairship/android-library/blob/17.0.0/documentation/migration/migration-guide-16-17.md --- build.gradle | 2 +- .../com/mparticle/kits/MParticleAutopilot.kt | 26 ++++++++++--------- .../com/mparticle/kits/UrbanAirshipKit.kt | 26 ++++++++----------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/build.gradle b/build.gradle index 42beb7c..1f2fbb8 100644 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,7 @@ android { dependencies { compileOnly 'androidx.legacy:legacy-support-v4:1.0.0' - api 'com.urbanairship.android:urbanairship-core:16.9.0' + api 'com.urbanairship.android:urbanairship-core:17.7.1' testImplementation 'junit:junit:4.13.2' testImplementation files('libs/java-json.jar') } diff --git a/src/main/kotlin/com/mparticle/kits/MParticleAutopilot.kt b/src/main/kotlin/com/mparticle/kits/MParticleAutopilot.kt index 301db6f..e139a72 100644 --- a/src/main/kotlin/com/mparticle/kits/MParticleAutopilot.kt +++ b/src/main/kotlin/com/mparticle/kits/MParticleAutopilot.kt @@ -9,6 +9,7 @@ import com.urbanairship.AirshipConfigOptions import com.urbanairship.Autopilot import com.urbanairship.UAirship import com.urbanairship.channel.AirshipChannelListener +import com.urbanairship.push.PushNotificationStatus import com.urbanairship.util.UAStringUtil /** @@ -49,22 +50,23 @@ class MParticleAutopilot : Autopilot() { val token = airship.pushManager.pushToken MParticlePushProvider.instance.setRegistrationToken(token) airship.channel.addChannelListener(object : AirshipChannelListener { - override fun onChannelCreated(s: String) { - callChannelIdListener() + override fun onChannelCreated(channelId: String) { + TODO("Not yet implemented") } - override fun onChannelUpdated(s: String) { - callChannelIdListener() + }) + fun callChannelIdListener() { + val channelIdListener = MParticle.getInstance() + ?.getKitInstance(MParticle.ServiceProviders.URBAN_AIRSHIP) + if (channelIdListener != null) { + (channelIdListener as ChannelIdListener).channelIdUpdated() } + } + //The onChange fun within the AirshipChannelListener was removed. + //PushNotificationStatusListener reporting changes instead (ref. [#https://github.com/urbanairship/android-library/blob/17.0.0/documentation/migration/migration-guide-16-17.md]) + airship.pushManager.addNotificationStatusListener { callChannelIdListener() } - private fun callChannelIdListener() { - val channelIdListener = MParticle.getInstance() - ?.getKitInstance(MParticle.ServiceProviders.URBAN_AIRSHIP) - if (channelIdListener != null) { - (channelIdListener as ChannelIdListener).channelIdUpdated() - } - } - }) + airship.channel.addChannelListener { callChannelIdListener() } } override fun allowEarlyTakeOff(context: Context): Boolean = false diff --git a/src/main/kotlin/com/mparticle/kits/UrbanAirshipKit.kt b/src/main/kotlin/com/mparticle/kits/UrbanAirshipKit.kt index 9440a5c..9e26459 100644 --- a/src/main/kotlin/com/mparticle/kits/UrbanAirshipKit.kt +++ b/src/main/kotlin/com/mparticle/kits/UrbanAirshipKit.kt @@ -1,26 +1,22 @@ package com.mparticle.kits import android.content.Context -import com.mparticle.kits.KitIntegration.CommerceListener -import com.urbanairship.Autopilot -import com.urbanairship.UAirship import android.content.Intent -import com.urbanairship.analytics.InstallReceiver -import com.urbanairship.push.PushMessage -import com.urbanairship.push.PushProviderBridge -import java.lang.Exception import com.mparticle.MPEvent -import com.urbanairship.analytics.CustomEvent -import com.mparticle.commerce.CommerceEvent -import java.util.LinkedList import com.mparticle.MParticle.IdentityType +import com.mparticle.commerce.CommerceEvent import com.mparticle.commerce.Product +import com.mparticle.kits.KitIntegration.CommerceListener +import com.urbanairship.Autopilot +import com.urbanairship.UAirship +import com.urbanairship.analytics.CustomEvent +import com.urbanairship.analytics.InstallReceiver import com.urbanairship.analytics.RetailEventTemplate import com.urbanairship.json.JsonValue -import java.util.HashSet +import com.urbanairship.push.PushMessage +import com.urbanairship.push.PushProviderBridge import java.math.BigDecimal -import java.util.ArrayList -import java.util.HashMap +import java.util.LinkedList /** * mParticle-Urban Airship Kit integration @@ -193,7 +189,7 @@ class UrbanAirshipKit : KitIntegration(), KitIntegration.PushListener, KitIntegr .apply() } if (identityType == configuration?.userIdField) { - UAirship.shared().namedUser.id = identity + UAirship.shared().contact.identify(identity) // Previously setting namedUser but now is immutable } } @@ -206,7 +202,7 @@ class UrbanAirshipKit : KitIntegration(), KitIntegration.PushListener, KitIntegr .apply() } if (identityType == configuration?.userIdField) { - UAirship.shared().namedUser.id = null + UAirship.shared().contact.reset() // Previously setting namedUser to null but now is immutable } }