diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 916ea66..4aa5f40 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -6,7 +6,7 @@ plugins { android { defaultConfig { minSdk = 21 - compileSdk = 33 + compileSdk = 34 targetSdk = 34 applicationId = "com.example.piano_analytics_android" versionCode = 1 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ef5819b..9a0d687 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,9 +10,8 @@ moshiIR = "0.22.1" # AndroidX libraries compatLibrary = "1.6.1" -annotationsLibrary = "1.6.0" lifecycle = "2.6.2" -materialLibrary = "1.9.0" +materialLibrary = "1.10.0" # Third party Libraries googleAdsId = "18.0.1" @@ -27,7 +26,7 @@ viewBindingProperty = "1.5.9" junit = "4.13.2" androidxTestCore = "1.5.0" mockitoKotlin = "2.2.0" -mockitoCore = "5.5.0" +mockitoCore = "5.6.0" [plugins] android-library = { id = "com.android.library", version.ref = "android" } @@ -40,7 +39,6 @@ moshiIR = { id = "dev.zacsweers.moshix", version.ref = "moshiIR"} versionUpdater = { id = "com.github.ben-manes.versions", version.ref = "versionUpdater" } [libraries] -annotations = { module = "androidx.annotation:annotation", version.ref = "annotationsLibrary" } appcompat = { module = "androidx.appcompat:appcompat", version.ref = "compatLibrary" } lifecycleProcess = { module = "androidx.lifecycle:lifecycle-process", version.ref = "lifecycle"} material = { module = "com.google.android.material:material", version.ref = "materialLibrary" } diff --git a/piano-analytics/build.gradle.kts b/piano-analytics/build.gradle.kts index f18dd9f..4303d46 100644 --- a/piano-analytics/build.gradle.kts +++ b/piano-analytics/build.gradle.kts @@ -18,7 +18,7 @@ version = VERSION_NAME android { defaultConfig { minSdk = 21 - compileSdk = 33 + compileSdk = 34 buildConfigField("String", "SDK_VERSION", """"${project.version}"""") testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/EventPropertiesJsonAdapter.kt b/piano-analytics/src/main/java/io/piano/android/analytics/EventPropertiesJsonAdapter.kt index 5b19b21..3806c91 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/EventPropertiesJsonAdapter.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/EventPropertiesJsonAdapter.kt @@ -20,7 +20,17 @@ internal class EventPropertiesJsonAdapter( is Double, is Boolean, is Array<*>, - -> Property(PropertyName(entry.key), entry.value) + -> { + val delimiterIndex = entry.key.lastIndexOf(DELIMITER) + val key = entry.key.substring(delimiterIndex + 1) + val type = if (delimiterIndex != -1) { + val prefix = entry.key.substring(0, delimiterIndex) + Property.Type.values().firstOrNull { it.prefix == prefix } + } else { + null + } + Property(PropertyName(key), entry.value, type) + } else -> null } @@ -29,6 +39,15 @@ internal class EventPropertiesJsonAdapter( override fun toJson(writer: JsonWriter, value: Set?) { requireNotNull(value) - mapAdapter.toJson(writer, value.associate { it.name.key.lowercase() to it.value }) + mapAdapter.toJson( + writer, + value.associate { + it.forceType?.prefix?.plus(DELIMITER).orEmpty() + it.name.key.lowercase() to it.value + } + ) + } + + companion object { + private const val DELIMITER = ":" } } diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/model/Property.kt b/piano-analytics/src/main/java/io/piano/android/analytics/model/Property.kt index 7fba801..07ce45d 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/model/Property.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/model/Property.kt @@ -8,6 +8,7 @@ import java.util.Date class Property { val name: PropertyName val value: Any + val forceType: Type? override fun equals(other: Any?): Boolean { if (this === other) return true @@ -17,10 +18,11 @@ class Property { override fun hashCode(): Int = name.key.lowercase().hashCode() - internal constructor(name: PropertyName, value: Any) { + internal constructor(name: PropertyName, value: Any, forceType: Type? = null) { require(name != PropertyName.ANY_PROPERTY) this.name = name this.value = value + this.forceType = forceType } /** @@ -29,10 +31,11 @@ class Property { * @param name property name * @param value property value */ - constructor(name: PropertyName, value: String) { + constructor(name: PropertyName, value: String, forceType: Type? = null) { require(name != PropertyName.ANY_PROPERTY) this.name = name this.value = value + this.forceType = forceType } /** @@ -41,10 +44,11 @@ class Property { * @param name property name * @param value property value */ - constructor(name: PropertyName, value: Int) { + constructor(name: PropertyName, value: Int, forceType: Type? = null) { require(name != PropertyName.ANY_PROPERTY) this.name = name this.value = value + this.forceType = forceType } /** @@ -53,10 +57,11 @@ class Property { * @param name property name * @param value property value */ - constructor(name: PropertyName, value: Long) { + constructor(name: PropertyName, value: Long, forceType: Type? = null) { require(name != PropertyName.ANY_PROPERTY) this.name = name this.value = value + this.forceType = forceType } /** @@ -65,10 +70,11 @@ class Property { * @param name property name * @param value property value */ - constructor(name: PropertyName, value: Double) { + constructor(name: PropertyName, value: Double, forceType: Type? = null) { require(name != PropertyName.ANY_PROPERTY) this.name = name this.value = value + this.forceType = forceType } /** @@ -77,7 +83,7 @@ class Property { * @param name property name * @param value property value */ - constructor(name: PropertyName, value: Date) : this(name, value.time / 1000) + constructor(name: PropertyName, value: Date) : this(name, value.time / 1000, Type.DATE) /** * Creates a new property @@ -85,10 +91,11 @@ class Property { * @param name property name * @param value property value */ - constructor(name: PropertyName, value: Boolean) { + constructor(name: PropertyName, value: Boolean, forceType: Type? = null) { require(name != PropertyName.ANY_PROPERTY) this.name = name this.value = value + this.forceType = forceType } /** @@ -97,10 +104,11 @@ class Property { * @param name property name * @param value property value */ - constructor(name: PropertyName, value: Array) { + constructor(name: PropertyName, value: Array, forceType: Type? = null) { require(name != PropertyName.ANY_PROPERTY) this.name = name this.value = value + this.forceType = forceType } /** @@ -109,10 +117,11 @@ class Property { * @param name property name * @param value property value */ - constructor(name: PropertyName, value: Array) { + constructor(name: PropertyName, value: Array, forceType: Type? = null) { require(name != PropertyName.ANY_PROPERTY) this.name = name this.value = value + this.forceType = forceType } /** @@ -121,9 +130,21 @@ class Property { * @param name property name * @param value property value */ - constructor(name: PropertyName, value: Array) { + constructor(name: PropertyName, value: Array, forceType: Type? = null) { require(name != PropertyName.ANY_PROPERTY) this.name = name this.value = value + this.forceType = forceType + } + + enum class Type(val prefix: String) { + STRING("s"), + INTEGER("n"), + FLOAT("f"), + DATE("d"), + BOOLEAN("b"), + STRING_ARRAY("a:s"), + INTEGER_ARRAY("a:n"), + FLOAT_ARRAY("a:f"), } }