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
25 changes: 21 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.8.10'
ext.kotlin_version = '2.0.20'
if (!project.hasProperty('version') || project.version.equals('unspecified')) {
project.version = '+'
}
Expand All @@ -9,16 +9,17 @@ buildscript {
mavenLocal()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.4.1'
classpath 'com.android.tools.build:gradle:8.1.4'
classpath 'com.mparticle:android-kit-plugin:' + project.version
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

plugins {
id "org.sonarqube" version "3.5.0.2730"
id "org.jlleitschuh.gradle.ktlint" version "11.2.0"
id "org.jlleitschuh.gradle.ktlint" version "13.0.0"
}

sonarqube {
Expand All @@ -30,14 +31,30 @@ sonarqube {
}

apply plugin: 'org.jlleitschuh.gradle.ktlint'
apply plugin: 'com.mparticle.kit'
apply plugin: 'kotlin-android'
apply plugin: 'com.mparticle.kit'

android {
namespace 'com.mparticle.kits.urbanairship'
compileSdk = 33
buildFeatures {
buildConfig = true
}
defaultConfig {
minSdkVersion 23
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
testOptions {
unitTests.all {
jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED']
}
}
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 1 addition & 2 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest package="com.mparticle.kits.urbanairship"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>

Expand Down
56 changes: 34 additions & 22 deletions src/main/kotlin/com/mparticle/kits/MParticleAutopilot.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
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
Expand All @@ -18,17 +16,21 @@ import com.urbanairship.util.UAStringUtil
class MParticleAutopilot : Autopilot() {
override fun createAirshipConfigOptions(context: Context): AirshipConfigOptions {
val preferences = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
val optionsBuilder = AirshipConfigOptions.Builder()
.setNotificationIcon(preferences.getInt(NOTIFICATION_ICON_NAME, 0))
.setNotificationAccentColor(preferences.getInt(NOTIFICATION_COLOR, 0))
.setCustomPushProvider(MParticlePushProvider.instance)
.setIsPromptForPermissionOnUserNotificationsEnabled(false)
val optionsBuilder =
AirshipConfigOptions
.Builder()
.setNotificationIcon(preferences.getInt(NOTIFICATION_ICON_NAME, 0))
.setNotificationAccentColor(preferences.getInt(NOTIFICATION_COLOR, 0))
.setCustomPushProvider(MParticlePushProvider.instance)
.setIsPromptForPermissionOnUserNotificationsEnabled(false)
if (MParticle.getInstance()?.environment == MParticle.Environment.Development) {
optionsBuilder.setDevelopmentAppKey(preferences.getString(APP_KEY, null))
optionsBuilder
.setDevelopmentAppKey(preferences.getString(APP_KEY, null))
.setDevelopmentAppSecret(preferences.getString(APP_SECRET, null))
.setInProduction(false)
} else {
optionsBuilder.setProductionAppKey(preferences.getString(APP_KEY, null))
optionsBuilder
.setProductionAppKey(preferences.getString(APP_KEY, null))
.setProductionAppSecret(preferences.getString(APP_SECRET, null))
.setInProduction(true)
}
Expand All @@ -43,8 +45,10 @@ class MParticleAutopilot : Autopilot() {
}

override fun onAirshipReady(airship: UAirship) {
val preferences = UAirship.getApplicationContext()
.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
val preferences =
UAirship
.getApplicationContext()
.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
Expand All @@ -68,11 +72,10 @@ class MParticleAutopilot : Autopilot() {

override fun allowEarlyTakeOff(context: Context): Boolean = false


companion object {
private const val PREFERENCE_NAME = "com.mparticle.kits.urbanairship"

//persistence keys
// persistence keys
private const val APP_KEY = "applicationKey"
private const val APP_SECRET = "applicationSecret"
private const val DOMAIN = "domain"
Expand All @@ -89,12 +92,18 @@ class MParticleAutopilot : Autopilot() {
* @param context The application context.
* @param configuration UrbanAirshipKit configuration.
*/
fun updateConfig(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)
fun updateConfig(
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)

// Convert accent color hex string to an int
val accentColor = configuration.notificationColor
Expand All @@ -109,9 +118,12 @@ class MParticleAutopilot : Autopilot() {
// 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
)
val id =
context.resources.getIdentifier(
notificationIconName,
"drawable",
context.packageName,
)
if (id != 0) {
editor.putInt(NOTIFICATION_ICON_NAME, id)
} else {
Expand Down
57 changes: 30 additions & 27 deletions src/main/kotlin/com/mparticle/kits/UrbanAirshipConfiguration.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.mparticle.kits

import com.mparticle.MParticle.IdentityType
import java.util.ArrayList
import org.json.JSONArray
import org.json.JSONException
import java.lang.Exception
import java.util.ArrayList

class UrbanAirshipConfiguration(settings: Map<String, String>) {
class UrbanAirshipConfiguration(
settings: Map<String, String>,
) {
val applicationKey: String?
val applicationSecret: String?
val domain: String?
Expand All @@ -27,7 +29,6 @@ class UrbanAirshipConfiguration(settings: Map<String, String>) {
var notificationIconName: String? = null
var notificationColor: String? = null


private fun parseTagsJson(tagsJson: JSONArray) {
for (i in 0 until tagsJson.length()) {
try {
Expand All @@ -37,22 +38,22 @@ class UrbanAirshipConfiguration(settings: Map<String, String>) {
val hash = tagMap.getInt("map")
val eventMap: MutableMap<Int, ArrayList<String>>? =
when (mapType) {
"EventClass.Id" -> {
eventClass
}
"EventClassDetails.Id" -> {
eventClassDetails
}
"EventAttributeClass.Id" -> {
eventAttributeClass
}
"EventAttributeClassDetails.Id" -> {
eventAttributeClassDetails
"EventClass.Id" -> {
eventClass
}
"EventClassDetails.Id" -> {
eventClassDetails
}
"EventAttributeClass.Id" -> {
eventAttributeClass
}
"EventAttributeClassDetails.Id" -> {
eventAttributeClassDetails
}
else -> {
null
}
}
else -> {
null
}
}
if (eventMap != null) {
if (!eventMap.containsKey(hash)) {
eventMap[hash] = ArrayList()
Expand Down Expand Up @@ -80,17 +81,19 @@ class UrbanAirshipConfiguration(settings: Map<String, String>) {
private const val NAMED_USER_TYPE_CUSTOMER_ID = "customerId"
private const val NAMED_USER_TYPE_EMAIL = "email"
private const val NAMED_USER_TYPE_OTHER = "other"
private fun parseNamedUserIdentityType(config: String?): IdentityType? {
return if (config == null) {

private fun parseNamedUserIdentityType(config: String?): IdentityType? =
if (config == null) {
null
} else when (config) {
NAMED_USER_TYPE_OTHER -> IdentityType.Other
NAMED_USER_TYPE_EMAIL -> IdentityType.Email
NAMED_USER_TYPE_CUSTOMER_ID -> IdentityType.CustomerId
NAMED_USER_TYPE_NONE -> null
else -> null
} else {
when (config) {
NAMED_USER_TYPE_OTHER -> IdentityType.Other
NAMED_USER_TYPE_EMAIL -> IdentityType.Email
NAMED_USER_TYPE_CUSTOMER_ID -> IdentityType.CustomerId
NAMED_USER_TYPE_NONE -> null
else -> null
}
}
}
}

init {
Expand Down
Loading