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,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.wootric'
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.wootric"/>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"/>
60 changes: 40 additions & 20 deletions src/main/kotlin/com/mparticle/kits/WootricKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.mparticle.MParticle.IdentityType
import com.mparticle.kits.KitIntegration.AttributeListener
import com.wootric.androidsdk.Wootric

class WootricKit : KitIntegration(), AttributeListener {
class WootricKit :
KitIntegration(),
AttributeListener {
private var endUserEmail: String? = null
private var endUserCustomerId: String? = null
private var endUserProperties: HashMap<String, String?>? = null
Expand All @@ -16,11 +18,12 @@ class WootricKit : KitIntegration(), AttributeListener {
if (activityWeakReference != null) {
val activity = activityWeakReference.get()
if (activity != null) {
wootric = Wootric.init(
activity,
settings[CLIENT_ID],
settings[ACCOUNT_TOKEN]
)
wootric =
Wootric.init(
activity,
settings[CLIENT_ID],
settings[ACCOUNT_TOKEN],
)
wootric?.setProperties(endUserProperties)
setWootricIdentity(wootric)
}
Expand All @@ -33,21 +36,26 @@ class WootricKit : KitIntegration(), AttributeListener {

override fun onKitCreate(
settings: Map<String, String>,
context: Context
context: Context,
): List<ReportingMessage> {
//it's important the Wootric is not initialized until the hosting app calls getInstance, with
//the correct Activity
// it's important the Wootric is not initialized until the hosting app calls getInstance, with
// the correct Activity
require(
!(KitUtils.isEmpty(settings[CLIENT_ID]) ||
!(
KitUtils.isEmpty(settings[CLIENT_ID]) ||
KitUtils.isEmpty(CLIENT_SECRET) ||
KitUtils.isEmpty(ACCOUNT_TOKEN))
KitUtils.isEmpty(ACCOUNT_TOKEN)
),
) { WOOTRIC_MISSING_REQUIRED_SETTINGS_MESSAGE }
return emptyList()
}

override fun setOptOut(optedOut: Boolean): List<ReportingMessage> = emptyList()

override fun setUserIdentity(identityType: IdentityType, id: String) {
override fun setUserIdentity(
identityType: IdentityType,
id: String,
) {
if (IdentityType.Email == identityType) {
endUserEmail = id
} else if (IdentityType.CustomerId == identityType) {
Expand Down Expand Up @@ -77,19 +85,26 @@ class WootricKit : KitIntegration(), AttributeListener {
wootric?.setEndUserEmail(endUserIdentifier)
}

override fun setUserAttribute(key: String, value: String) {
override fun setUserAttribute(
key: String,
value: String,
) {
prepareEndUserProperties(key, value)
if (wootric != null) {
wootric?.setProperties(endUserProperties)
}
}

override fun setUserAttributeList(s: String, list: List<String>) {}
override fun setUserAttributeList(
s: String,
list: List<String>,
) {}

override fun supportsAttributeLists(): Boolean = false

override fun setAllUserAttributes(
attributes: Map<String, String>,
attributeLists: Map<String, List<String>>
attributeLists: Map<String, List<String>>,
) {
endUserProperties = HashMap()
for ((key, value) in attributes) {
Expand All @@ -101,17 +116,22 @@ class WootricKit : KitIntegration(), AttributeListener {
}

override fun removeUserAttribute(key: String) {
if (wootric != null && endUserProperties != null && endUserProperties?.remove(
if (wootric != null &&
endUserProperties != null &&
endUserProperties?.remove(
KitUtils.sanitizeAttributeKey(
key
)
key,
),
) != null
) {
wootric?.setProperties(endUserProperties)
}
}

private fun prepareEndUserProperties(key: String, value: String) {
private fun prepareEndUserProperties(
key: String,
value: String,
) {
endUserProperties?.let { it[KitUtils.sanitizeAttributeKey(key)] = value }
if (endUserProperties == null) {
endUserProperties = HashMap()
Expand All @@ -126,4 +146,4 @@ class WootricKit : KitIntegration(), AttributeListener {
private const val WOOTRIC_MISSING_REQUIRED_SETTINGS_MESSAGE =
"Wootric missing required settings and will not start."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.mockito.Mockito

class WootricKitTests {
private val kit: KitIntegration
get() = WootricKit()
get() = WootricKit()

@Test
@Throws(Exception::class)
Expand Down Expand Up @@ -50,4 +50,4 @@ class WootricKitTests {
}
Assert.fail("$className not found as a known integration.")
}
}
}