11package com.mparticle.kits
22
33import android.content.Context
4- import android.graphics.Color
4+ import androidx.core.content.edit
5+ import androidx.core.graphics.toColorInt
56import com.mparticle.MParticle
67import com.mparticle.internal.Logger
78import com.mparticle.kits.UrbanAirshipKit.ChannelIdListener
9+ import com.urbanairship.Airship
810import com.urbanairship.AirshipConfigOptions
911import 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}
0 commit comments