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
27 changes: 22 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
buildscript {
ext.kotlin_version = '1.8.10'
ext.kotlin_version = '2.0.20'
if (!project.hasProperty('version') || project.version.equals('unspecified')) {
project.version = '+'
}

repositories {
google()
mavenLocal()
mavenCentral()
google()
}

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,13 +31,29 @@ 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.responsys'
buildFeatures {
buildConfig = true
}
defaultConfig {
minSdkVersion 16
}
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
2 changes: 1 addition & 1 deletion src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<manifest package="com.mparticle.kits.responsys"/>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"/>
68 changes: 45 additions & 23 deletions src/main/kotlin/com/mparticle/kits/ResponsysKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,34 @@ import com.mparticle.MParticle.IdentityType
import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Product
import com.mparticle.identity.MParticleUser
import com.mparticle.kits.KitIntegration.*
import com.mparticle.kits.FilteredIdentityApiRequest
import com.mparticle.kits.KitIntegration.CommerceListener
import com.mparticle.kits.KitIntegration.EventListener
import com.mparticle.kits.KitIntegration.IdentityListener
import com.mparticle.kits.KitIntegration.PushListener
import com.mparticle.kits.ReportingMessage
import com.pushio.manager.PIOLogger
import com.pushio.manager.PushIOBroadcastReceiver
import com.pushio.manager.PushIOManager
import com.pushio.manager.exception.ValidationException
import com.pushio.manager.preferences.PushIOPreference
import java.math.BigDecimal
import java.util.ArrayList
import java.util.HashMap

class ResponsysKit : KitIntegration(), PushListener, KitIntegration.EventListener, CommerceListener,
class ResponsysKit :
KitIntegration(),
PushListener,
KitIntegration.EventListener,
CommerceListener,
IdentityListener {

private var mPushIOManager: PushIOManager? = null

override fun getInstance(): PushIOManager? = mPushIOManager

override fun onKitCreate(
settings: Map<String, String>,
context: Context
context: Context,
): List<ReportingMessage> {
PIOLogger.d("Responsys Kit detected")
PIOLogger.v("RK oKC")
Expand Down Expand Up @@ -63,7 +73,7 @@ class ResponsysKit : KitIntegration(), PushListener, KitIntegration.EventListene
bigDecimal: BigDecimal,
bigDecimal1: BigDecimal,
s: String,
map: Map<String, String>
map: Map<String, String>,
): List<ReportingMessage> = emptyList()

override fun logEvent(commerceEvent: CommerceEvent): List<ReportingMessage>? {
Expand Down Expand Up @@ -94,7 +104,8 @@ class ResponsysKit : KitIntegration(), PushListener, KitIntegration.EventListene
if (productAction.equals(Product.PURCHASE, true)) {
mPushIOManager?.trackEngagement(
PushIOManager.PUSHIO_ENGAGEMENT_METRIC_PURCHASE,
customProperties, null
customProperties,
null,
)
}
}
Expand All @@ -108,12 +119,15 @@ class ResponsysKit : KitIntegration(), PushListener, KitIntegration.EventListene

override fun leaveBreadcrumb(s: String): List<ReportingMessage> = emptyList()

override fun logError(s: String, map: Map<String, String>): List<ReportingMessage> = emptyList()
override fun logError(
s: String,
map: Map<String, String>,
): List<ReportingMessage> = emptyList()

override fun logException(
e: Exception,
map: Map<String, String>,
s: String
s: String,
): List<ReportingMessage> = emptyList()

override fun logEvent(mpEvent: MPEvent): List<ReportingMessage>? {
Expand All @@ -135,7 +149,7 @@ class ResponsysKit : KitIntegration(), PushListener, KitIntegration.EventListene
it.declarePreference(
key,
key,
PushIOPreference.Type.STRING
PushIOPreference.Type.STRING,
)
it.setPreference(key, value)
} catch (e: ValidationException) {
Expand All @@ -154,21 +168,29 @@ class ResponsysKit : KitIntegration(), PushListener, KitIntegration.EventListene
return if (reportingMessages.isEmpty()) null else reportingMessages
}

override fun logScreen(s: String, map: Map<String, String>): List<ReportingMessage> =
emptyList()
override fun logScreen(
s: String,
map: Map<String, String>,
): List<ReportingMessage> = emptyList()

override fun willHandlePushMessage(intent: Intent): Boolean {
PIOLogger.v("RK wHPM")
return isResponsysPush(intent)
}

override fun onPushMessageReceived(context: Context, intent: Intent) {
override fun onPushMessageReceived(
context: Context,
intent: Intent,
) {
PIOLogger.v("RK oPMR")
val newIntent = Intent(intent)
PushIOBroadcastReceiver().onReceive(getContext(), newIntent)
}

override fun onPushRegistration(instanceId: String, senderId: String): Boolean {
override fun onPushRegistration(
instanceId: String,
senderId: String,
): Boolean {
PIOLogger.v("RK oPR Instance ID: $instanceId, Sender ID: $senderId")
mPushIOManager?.let {
it.setDeviceToken(instanceId)
Expand All @@ -179,29 +201,29 @@ class ResponsysKit : KitIntegration(), PushListener, KitIntegration.EventListene

override fun onIdentifyCompleted(
mParticleUser: MParticleUser,
filteredIdentityApiRequest: FilteredIdentityApiRequest
filteredIdentityApiRequest: FilteredIdentityApiRequest,
) {
}

override fun onLoginCompleted(
mParticleUser: MParticleUser,
filteredIdentityApiRequest: FilteredIdentityApiRequest
filteredIdentityApiRequest: FilteredIdentityApiRequest,
) {
PIOLogger.v("RK oLiC")
registerUserId(mParticleUser)
}

override fun onLogoutCompleted(
mParticleUser: MParticleUser,
filteredIdentityApiRequest: FilteredIdentityApiRequest
filteredIdentityApiRequest: FilteredIdentityApiRequest,
) {
PIOLogger.v("RK oLoC")
mPushIOManager?.unregisterUserId()
}

override fun onModifyCompleted(
mParticleUser: MParticleUser,
filteredIdentityApiRequest: FilteredIdentityApiRequest
filteredIdentityApiRequest: FilteredIdentityApiRequest,
) {
}

Expand All @@ -224,10 +246,10 @@ class ResponsysKit : KitIntegration(), PushListener, KitIntegration.EventListene
return userId
}

private fun isResponsysPush(intent: Intent?): Boolean {
return intent != null && intent.hasExtra("ei") &&
!KitUtils.isEmpty(intent.getStringExtra("ei"))
}
private fun isResponsysPush(intent: Intent?): Boolean =
intent != null &&
intent.hasExtra("ei") &&
!KitUtils.isEmpty(intent.getStringExtra("ei"))

private fun processCustomFlags(mpEvent: MPEvent): MutableList<ReportingMessage> {
val reportingMessages: MutableList<ReportingMessage> = ArrayList()
Expand All @@ -248,7 +270,7 @@ class ResponsysKit : KitIntegration(), PushListener, KitIntegration.EventListene
PIOLogger.e("Invalid engagement type")
PIOLogger.e(
"Supported engagement types can be accessed from PushIOManager and are of type: " +
"PushIOManager.PUSHIO_ENGAGEMENT_METRIC_***"
"PushIOManager.PUSHIO_ENGAGEMENT_METRIC_***",
)
}
}
Expand All @@ -262,4 +284,4 @@ class ResponsysKit : KitIntegration(), PushListener, KitIntegration.EventListene
const val CUSTOM_FLAG_ENGAGEMENT = "Responsys.Custom.e"
const val KIT_NAME = "Responsys"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package com.mparticle.kits

import android.content.Context
import com.mparticle.MParticleOptions
import com.mparticle.kits.KitIntegration
import com.mparticle.kits.KitIntegrationFactory
import org.junit.Assert
import org.junit.Test
import org.mockito.Mockito
import java.util.HashMap

class KitTests {
private val kit: KitIntegration
Expand All @@ -27,7 +30,7 @@ class KitTests {
var e: Exception? = null
try {
val kit = kit
val settings= HashMap<String,String>()
val settings = HashMap<String, String>()
settings["fake setting"] = "fake"
kit.onKitCreate(settings, Mockito.mock(Context::class.java))
} catch (ex: Exception) {
Expand All @@ -50,4 +53,4 @@ class KitTests {
}
Assert.fail("$className not found as a known integration.")
}
}
}