Skip to content
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

feat: Migration from 16.x to 17.x (latest version) #185

Merged
merged 2 commits into from
Jan 25, 2024
Merged
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
25 changes: 10 additions & 15 deletions src/main/kotlin/com/mparticle/kits/MParticleAutopilot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is being used

import com.urbanairship.util.UAStringUtil

/**
Expand Down Expand Up @@ -48,23 +49,17 @@ class MParticleAutopilot : Autopilot() {
// Restore the last registration token
val token = airship.pushManager.pushToken
MParticlePushProvider.instance.setRegistrationToken(token)
airship.channel.addChannelListener(object : AirshipChannelListener {
override fun onChannelCreated(s: String) {
callChannelIdListener()
}
airship.channel.addChannelListener { callChannelIdListener() }

override fun onChannelUpdated(s: String) {
callChannelIdListener()
}
callChannelIdListener()
}

private fun callChannelIdListener() {
val channelIdListener = MParticle.getInstance()
?.getKitInstance(MParticle.ServiceProviders.URBAN_AIRSHIP)
if (channelIdListener != null) {
(channelIdListener as ChannelIdListener).channelIdUpdated()
}
}
})
fun callChannelIdListener() {
val channelIdListener = MParticle.getInstance()
?.getKitInstance(MParticle.ServiceProviders.URBAN_AIRSHIP)
if (channelIdListener != null) {
(channelIdListener as ChannelIdListener).channelIdUpdated()
}
}

override fun allowEarlyTakeOff(context: Context): Boolean = false
Expand Down
28 changes: 12 additions & 16 deletions src/main/kotlin/com/mparticle/kits/UrbanAirshipKit.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
}

Expand All @@ -205,8 +201,8 @@ class UrbanAirshipKit : KitIntegration(), KitIntegration.PushListener, KitIntegr
.removeIdentifier(airshipId)
.apply()
}
if (identityType == configuration?.userIdField) {
UAirship.shared().namedUser.id = null
if (identityType == configuration?.userIdField && UAirship.shared().contact.namedUserId != null) {
UAirship.shared().contact.reset() // Previously setting namedUser to null but now is immutable
Copy link
Contributor

@rlepinski rlepinski Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically the same thing as setting it null if the user is only managed through the SDK, but its possible that if the was set to a user server side this would now reset that association. I think it would be safer to only reset it if its not set through the SDK:

if (UAirship.shared().contact.namedUserId != null) {
    UAirship.shared().contact.reset()
}

}
}

Expand Down