Skip to content
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
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '2.0.20'
ext.kotlin_version = '2.2.20'
if (!project.hasProperty('version') || project.version.equals('unspecified')) {
project.version = '+'
}
Expand Down Expand Up @@ -36,7 +36,7 @@ apply plugin: 'com.mparticle.kit'

android {
namespace 'com.mparticle.kits.urbanairship'
compileSdk = 33
compileSdk = 36
buildFeatures {
buildConfig = true
}
Expand All @@ -59,7 +59,7 @@ android {

dependencies {
compileOnly 'androidx.legacy:legacy-support-v4:1.0.0'
api 'com.urbanairship.android:urbanairship-core:19.9.1'
api 'com.urbanairship.android:urbanairship-core:20.3.0'
testImplementation 'junit:junit:4.13.2'
testImplementation files('libs/java-json.jar')
}
89 changes: 45 additions & 44 deletions src/main/kotlin/com/mparticle/kits/MParticleAutopilot.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.mparticle.kits

import android.content.Context
import android.graphics.Color
import androidx.core.content.edit
import androidx.core.graphics.toColorInt
import com.mparticle.MParticle
import com.mparticle.internal.Logger
import com.mparticle.kits.UrbanAirshipKit.ChannelIdListener
import com.urbanairship.Airship
import com.urbanairship.AirshipConfigOptions
import com.urbanairship.Autopilot
import com.urbanairship.UAirship
import com.urbanairship.util.UAStringUtil

/**
* Autopilot for UrbanAirshipKit integration.
Expand All @@ -35,29 +35,28 @@ class MParticleAutopilot : Autopilot() {
.setInProduction(true)
}
if ("EU".equals(preferences.getString(DOMAIN, null), true)) {
optionsBuilder.setSite(AirshipConfigOptions.SITE_EU)
optionsBuilder.setSite(AirshipConfigOptions.Site.SITE_EU)
}
val customDomain = preferences.getString(CUSTOM_DOMAIN_PROXY_URL, null)
if (!UAStringUtil.isEmpty(customDomain)) {
if (!customDomain.isNullOrEmpty()) {
optionsBuilder.setInitialConfigUrl(customDomain).setUrlAllowList(arrayOf(customDomain))
}
return optionsBuilder.build()
}

override fun onAirshipReady(airship: UAirship) {
override fun onAirshipReady(context: Context) {
val preferences =
UAirship
.getApplicationContext()
Airship.application.applicationContext
.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
if (preferences.getBoolean(FIRST_RUN_KEY, true)) {
preferences.edit().putBoolean(FIRST_RUN_KEY, false).apply()
airship.pushManager.userNotificationsEnabled = true
preferences.edit { putBoolean(FIRST_RUN_KEY, false) }
Airship.push.userNotificationsEnabled = true
}

// Restore the last registration token
val token = airship.pushManager.pushToken
val token = Airship.push.pushToken
MParticlePushProvider.instance.setRegistrationToken(token)
airship.channel.addChannelListener { callChannelIdListener() }
Airship.channel.addChannelListener { callChannelIdListener() }

callChannelIdListener()
}
Expand Down Expand Up @@ -96,41 +95,43 @@ class MParticleAutopilot : Autopilot() {
context: Context,
configuration: UrbanAirshipConfiguration,
) {
val editor =
context
.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
.edit()
.putString(APP_KEY, configuration.applicationKey)
.putString(APP_SECRET, configuration.applicationSecret)
.putString(DOMAIN, configuration.domain)
.putString(CUSTOM_DOMAIN_PROXY_URL, configuration.customDomainProxyUrl)
context
.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
.edit {
putString(APP_KEY, configuration.applicationKey)
.putString(APP_SECRET, configuration.applicationSecret)
.putString(DOMAIN, configuration.domain)
.putString(CUSTOM_DOMAIN_PROXY_URL, configuration.customDomainProxyUrl)

// Convert accent color hex string to an int
val accentColor = configuration.notificationColor
if (!UAStringUtil.isEmpty(accentColor)) {
try {
editor.putInt(NOTIFICATION_COLOR, Color.parseColor(accentColor))
} catch (e: IllegalArgumentException) {
Logger.warning(e, "Unable to parse notification accent color: $accentColor")
}
}
// Convert accent color hex string to an int
val accentColor = configuration.notificationColor
if (!accentColor.isNullOrEmpty()) {
try {
putInt(NOTIFICATION_COLOR, accentColor.toColorInt())
} catch (e: IllegalArgumentException) {
Logger.warning(
e,
"Unable to parse notification accent color: $accentColor",
)
}
}

// Convert notification name to a drawable resource ID
val notificationIconName = configuration.notificationIconName
if (!UAStringUtil.isEmpty(notificationIconName)) {
val id =
context.resources.getIdentifier(
notificationIconName,
"drawable",
context.packageName,
)
if (id != 0) {
editor.putInt(NOTIFICATION_ICON_NAME, id)
} else {
Logger.error("Unable to find notification icon with name: $notificationIconName")
// Convert notification name to a drawable resource ID
val notificationIconName = configuration.notificationIconName
if (!notificationIconName.isNullOrEmpty()) {
val id =
context.resources.getIdentifier(
notificationIconName,
"drawable",
context.packageName,
)
if (id != 0) {
putInt(NOTIFICATION_ICON_NAME, id)
} else {
Logger.error("Unable to find notification icon with name: $notificationIconName")
}
}
}
}
editor.apply()
}
}
}
6 changes: 3 additions & 3 deletions src/main/kotlin/com/mparticle/kits/MParticlePushProvider.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mparticle.kits

import android.content.Context
import com.urbanairship.UAirship
import com.urbanairship.Platform
import com.urbanairship.push.PushProvider

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

override fun getPlatform(): Int = UAirship.ANDROID_PLATFORM
override val platform: Platform = Platform.ANDROID

override fun getDeliveryType(): String = PushProvider.FCM_DELIVERY_TYPE
override val deliveryType: PushProvider.DeliveryType = PushProvider.DeliveryType.FCM

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

Expand Down
Loading