Skip to content

Commit ec958ff

Browse files
mmustafa-tseMohammed Mustafa
andauthored
feat: Update Airship SDK to v20.x (#190)
* feat: Update Airship SDK to v20.x * remove unused imports * replaced retail event format with kotlin format * nit clean up * update format and nit * update airship 20.3.0 and restore push functionality and clean kotlin format * nit formatting * remove unused import --------- Co-authored-by: Mohammed Mustafa <mohammedmustafa@Mohammeds-MacBook-Pro.local>
1 parent 6bcd6af commit ec958ff

4 files changed

Lines changed: 94 additions & 134 deletions

File tree

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '2.0.20'
2+
ext.kotlin_version = '2.2.20'
33
if (!project.hasProperty('version') || project.version.equals('unspecified')) {
44
project.version = '+'
55
}
@@ -36,7 +36,7 @@ apply plugin: 'com.mparticle.kit'
3636

3737
android {
3838
namespace 'com.mparticle.kits.urbanairship'
39-
compileSdk = 33
39+
compileSdk = 36
4040
buildFeatures {
4141
buildConfig = true
4242
}
@@ -59,7 +59,7 @@ android {
5959

6060
dependencies {
6161
compileOnly 'androidx.legacy:legacy-support-v4:1.0.0'
62-
api 'com.urbanairship.android:urbanairship-core:19.9.1'
62+
api 'com.urbanairship.android:urbanairship-core:20.3.0'
6363
testImplementation 'junit:junit:4.13.2'
6464
testImplementation files('libs/java-json.jar')
6565
}

src/main/kotlin/com/mparticle/kits/MParticleAutopilot.kt

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.mparticle.kits
22

33
import android.content.Context
4-
import android.graphics.Color
4+
import androidx.core.content.edit
5+
import androidx.core.graphics.toColorInt
56
import com.mparticle.MParticle
67
import com.mparticle.internal.Logger
78
import com.mparticle.kits.UrbanAirshipKit.ChannelIdListener
9+
import com.urbanairship.Airship
810
import com.urbanairship.AirshipConfigOptions
911
import com.urbanairship.Autopilot
10-
import com.urbanairship.UAirship
11-
import com.urbanairship.util.UAStringUtil
1212

1313
/**
1414
* Autopilot for UrbanAirshipKit integration.
@@ -35,29 +35,28 @@ class MParticleAutopilot : Autopilot() {
3535
.setInProduction(true)
3636
}
3737
if ("EU".equals(preferences.getString(DOMAIN, null), true)) {
38-
optionsBuilder.setSite(AirshipConfigOptions.SITE_EU)
38+
optionsBuilder.setSite(AirshipConfigOptions.Site.SITE_EU)
3939
}
4040
val customDomain = preferences.getString(CUSTOM_DOMAIN_PROXY_URL, null)
41-
if (!UAStringUtil.isEmpty(customDomain)) {
41+
if (!customDomain.isNullOrEmpty()) {
4242
optionsBuilder.setInitialConfigUrl(customDomain).setUrlAllowList(arrayOf(customDomain))
4343
}
4444
return optionsBuilder.build()
4545
}
4646

47-
override fun onAirshipReady(airship: UAirship) {
47+
override fun onAirshipReady(context: Context) {
4848
val preferences =
49-
UAirship
50-
.getApplicationContext()
49+
Airship.application.applicationContext
5150
.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
5251
if (preferences.getBoolean(FIRST_RUN_KEY, true)) {
53-
preferences.edit().putBoolean(FIRST_RUN_KEY, false).apply()
54-
airship.pushManager.userNotificationsEnabled = true
52+
preferences.edit { putBoolean(FIRST_RUN_KEY, false) }
53+
Airship.push.userNotificationsEnabled = true
5554
}
5655

5756
// Restore the last registration token
58-
val token = airship.pushManager.pushToken
57+
val token = Airship.push.pushToken
5958
MParticlePushProvider.instance.setRegistrationToken(token)
60-
airship.channel.addChannelListener { callChannelIdListener() }
59+
Airship.channel.addChannelListener { callChannelIdListener() }
6160

6261
callChannelIdListener()
6362
}
@@ -96,41 +95,43 @@ class MParticleAutopilot : Autopilot() {
9695
context: Context,
9796
configuration: UrbanAirshipConfiguration,
9897
) {
99-
val editor =
100-
context
101-
.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
102-
.edit()
103-
.putString(APP_KEY, configuration.applicationKey)
104-
.putString(APP_SECRET, configuration.applicationSecret)
105-
.putString(DOMAIN, configuration.domain)
106-
.putString(CUSTOM_DOMAIN_PROXY_URL, configuration.customDomainProxyUrl)
98+
context
99+
.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
100+
.edit {
101+
putString(APP_KEY, configuration.applicationKey)
102+
.putString(APP_SECRET, configuration.applicationSecret)
103+
.putString(DOMAIN, configuration.domain)
104+
.putString(CUSTOM_DOMAIN_PROXY_URL, configuration.customDomainProxyUrl)
107105

108-
// Convert accent color hex string to an int
109-
val accentColor = configuration.notificationColor
110-
if (!UAStringUtil.isEmpty(accentColor)) {
111-
try {
112-
editor.putInt(NOTIFICATION_COLOR, Color.parseColor(accentColor))
113-
} catch (e: IllegalArgumentException) {
114-
Logger.warning(e, "Unable to parse notification accent color: $accentColor")
115-
}
116-
}
106+
// Convert accent color hex string to an int
107+
val accentColor = configuration.notificationColor
108+
if (!accentColor.isNullOrEmpty()) {
109+
try {
110+
putInt(NOTIFICATION_COLOR, accentColor.toColorInt())
111+
} catch (e: IllegalArgumentException) {
112+
Logger.warning(
113+
e,
114+
"Unable to parse notification accent color: $accentColor",
115+
)
116+
}
117+
}
117118

118-
// Convert notification name to a drawable resource ID
119-
val notificationIconName = configuration.notificationIconName
120-
if (!UAStringUtil.isEmpty(notificationIconName)) {
121-
val id =
122-
context.resources.getIdentifier(
123-
notificationIconName,
124-
"drawable",
125-
context.packageName,
126-
)
127-
if (id != 0) {
128-
editor.putInt(NOTIFICATION_ICON_NAME, id)
129-
} else {
130-
Logger.error("Unable to find notification icon with name: $notificationIconName")
119+
// Convert notification name to a drawable resource ID
120+
val notificationIconName = configuration.notificationIconName
121+
if (!notificationIconName.isNullOrEmpty()) {
122+
val id =
123+
context.resources.getIdentifier(
124+
notificationIconName,
125+
"drawable",
126+
context.packageName,
127+
)
128+
if (id != 0) {
129+
putInt(NOTIFICATION_ICON_NAME, id)
130+
} else {
131+
Logger.error("Unable to find notification icon with name: $notificationIconName")
132+
}
133+
}
131134
}
132-
}
133-
editor.apply()
134135
}
135136
}
136137
}

src/main/kotlin/com/mparticle/kits/MParticlePushProvider.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mparticle.kits
22

33
import android.content.Context
4-
import com.urbanairship.UAirship
4+
import com.urbanairship.Platform
55
import com.urbanairship.push.PushProvider
66

77
/**
@@ -10,9 +10,9 @@ import com.urbanairship.push.PushProvider
1010
internal class MParticlePushProvider private constructor() : PushProvider {
1111
private var token: String? = null
1212

13-
override fun getPlatform(): Int = UAirship.ANDROID_PLATFORM
13+
override val platform: Platform = Platform.ANDROID
1414

15-
override fun getDeliveryType(): String = PushProvider.FCM_DELIVERY_TYPE
15+
override val deliveryType: PushProvider.DeliveryType = PushProvider.DeliveryType.FCM
1616

1717
override fun getRegistrationToken(context: Context): String? = token
1818

0 commit comments

Comments
 (0)