Skip to content

Commit 2b804a6

Browse files
committed
revert: "feat: Update Airship SDK to v20.x (#190)"
This reverts commit ec958ff.
1 parent ec958ff commit 2b804a6

4 files changed

Lines changed: 134 additions & 94 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.2.20'
2+
ext.kotlin_version = '2.0.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 = 36
39+
compileSdk = 33
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:20.3.0'
62+
api 'com.urbanairship.android:urbanairship-core:19.9.1'
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: 44 additions & 45 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 androidx.core.content.edit
5-
import androidx.core.graphics.toColorInt
4+
import android.graphics.Color
65
import com.mparticle.MParticle
76
import com.mparticle.internal.Logger
87
import com.mparticle.kits.UrbanAirshipKit.ChannelIdListener
9-
import com.urbanairship.Airship
108
import com.urbanairship.AirshipConfigOptions
119
import com.urbanairship.Autopilot
10+
import com.urbanairship.UAirship
11+
import com.urbanairship.util.UAStringUtil
1212

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

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

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

6162
callChannelIdListener()
6263
}
@@ -95,43 +96,41 @@ class MParticleAutopilot : Autopilot() {
9596
context: Context,
9697
configuration: UrbanAirshipConfiguration,
9798
) {
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)
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)
105107

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-
}
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+
}
118117

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-
}
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")
134131
}
132+
}
133+
editor.apply()
135134
}
136135
}
137136
}

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.Platform
4+
import com.urbanairship.UAirship
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 val platform: Platform = Platform.ANDROID
13+
override fun getPlatform(): Int = UAirship.ANDROID_PLATFORM
1414

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

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

0 commit comments

Comments
 (0)