Skip to content

Commit

Permalink
feat: Update to Partner latest version 18.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mansi-mParticle committed Jul 26, 2024
1 parent a1ba7a4 commit 1ef6041
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
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:17.7.1'
api 'com.urbanairship.android:urbanairship-core:18.1.2'
testImplementation 'junit:junit:4.13.2'
testImplementation files('libs/java-json.jar')
}
30 changes: 18 additions & 12 deletions src/main/kotlin/com/mparticle/kits/MParticleAutopilot.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.mparticle.kits

import android.R
import android.content.Context
import android.graphics.Color
import android.util.TypedValue
import com.mparticle.MParticle
import com.mparticle.internal.Logger
import com.mparticle.kits.UrbanAirshipKit.ChannelIdListener
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

/**
Expand Down Expand Up @@ -37,8 +37,7 @@ class MParticleAutopilot : Autopilot() {
}
val customDomain = preferences.getString(CUSTOM_DOMAIN_PROXY_URL, null)
if (!UAStringUtil.isEmpty(customDomain)) {
optionsBuilder.setInitialConfigUrl(customDomain)
.setUrlAllowList(arrayOf(customDomain))
optionsBuilder.setInitialConfigUrl(customDomain).setUrlAllowList(arrayOf(customDomain))
}
return optionsBuilder.build()
}
Expand All @@ -60,8 +59,8 @@ class MParticleAutopilot : Autopilot() {
}

fun callChannelIdListener() {
val channelIdListener = MParticle.getInstance()
?.getKitInstance(MParticle.ServiceProviders.URBAN_AIRSHIP)
val channelIdListener =
MParticle.getInstance()?.getKitInstance(MParticle.ServiceProviders.URBAN_AIRSHIP)
if (channelIdListener != null) {
(channelIdListener as ChannelIdListener).channelIdUpdated()
}
Expand Down Expand Up @@ -91,8 +90,7 @@ class MParticleAutopilot : Autopilot() {
* @param configuration UrbanAirshipKit configuration.
*/
fun updateConfig(context: Context, configuration: UrbanAirshipConfiguration) {
val editor = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
.edit()
val editor = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE).edit()
.putString(APP_KEY, configuration.applicationKey)
.putString(APP_SECRET, configuration.applicationSecret)
.putString(DOMAIN, configuration.domain)
Expand All @@ -102,7 +100,17 @@ class MParticleAutopilot : Autopilot() {
val accentColor = configuration.notificationColor
if (!UAStringUtil.isEmpty(accentColor)) {
try {
editor.putInt(NOTIFICATION_COLOR, Color.parseColor(accentColor))
val colorValue = when {
accentColor.equals("System default") -> {
val typedValue = TypedValue()
val theme = context.theme
theme.resolveAttribute(R.attr.windowBackground, typedValue, true)
typedValue.data
}

else -> Color.parseColor(accentColor)
}
editor.putInt(NOTIFICATION_COLOR, colorValue)
} catch (e: IllegalArgumentException) {
Logger.warning(e, "Unable to parse notification accent color: $accentColor")
}
Expand All @@ -112,9 +120,7 @@ class MParticleAutopilot : Autopilot() {
val notificationIconName = configuration.notificationIconName
if (!UAStringUtil.isEmpty(notificationIconName)) {
val id = context.resources.getIdentifier(
notificationIconName,
"drawable",
context.packageName
notificationIconName, "drawable", context.packageName
)
if (id != 0) {
editor.putInt(NOTIFICATION_ICON_NAME, id)
Expand Down
15 changes: 11 additions & 4 deletions src/main/kotlin/com/mparticle/kits/UrbanAirshipKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Product
import com.mparticle.kits.KitIntegration.CommerceListener
import com.urbanairship.Autopilot
import com.urbanairship.PrivacyManager
import com.urbanairship.UAirship
import com.urbanairship.analytics.CustomEvent
import com.urbanairship.analytics.InstallReceiver
Expand Down Expand Up @@ -61,7 +62,9 @@ class UrbanAirshipKit : KitIntegration(), KitIntegration.PushListener, KitIntegr
}

override fun setOptOut(optedOut: Boolean): List<ReportingMessage> {
UAirship.shared().isDataCollectionEnabled = !optedOut
UAirship.shared().privacyManager.setEnabledFeatures(
if (optedOut) PrivacyManager.Feature.ALL else PrivacyManager.Feature.NONE
)
val message = ReportingMessage(
this,
ReportingMessage.MessageType.OPT_OUT,
Expand Down Expand Up @@ -94,7 +97,11 @@ class UrbanAirshipKit : KitIntegration(), KitIntegration.PushListener, KitIntegr

override fun onPushRegistration(instanceId: String, senderId: String): Boolean {
MParticlePushProvider.instance.setRegistrationToken(instanceId)
PushProviderBridge.requestRegistrationUpdate(context)
PushProviderBridge.requestRegistrationUpdate(
context,
MParticlePushProvider.instance::class.java,
instanceId
)
return true
}

Expand Down Expand Up @@ -150,7 +157,7 @@ class UrbanAirshipKit : KitIntegration(), KitIntegration.PushListener, KitIntegr
val customEvent = CustomEvent.Builder(eventName)
.setEventValue(valueIncreased)
.build()
UAirship.shared().analytics.addEvent(customEvent)
UAirship.shared().analytics.recordCustomEvent(customEvent)
val message = ReportingMessage(
this,
ReportingMessage.MessageType.EVENT,
Expand Down Expand Up @@ -340,7 +347,7 @@ class UrbanAirshipKit : KitIntegration(), KitIntegration.PushListener, KitIntegr
if (event.customAttributeStrings != null) {
eventBuilder.setProperties(JsonValue.wrapOpt(event.customAttributeStrings).optMap())
}
UAirship.shared().analytics.addEvent(eventBuilder.build())
UAirship.shared().analytics.recordCustomEvent(eventBuilder.build())
}

fun extractTags(event: MPEvent): Set<String> {
Expand Down

0 comments on commit 1ef6041

Please sign in to comment.