Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2.5.1 #57

Merged
merged 3 commits into from
Mar 20, 2024
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
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ ij_groovy_while_on_new_line = false
ij_groovy_wrap_long_lines = false

[*.{kt,kts}]
ktlint_code_style = android_studio
ktlint_standard_import-ordering = disabled
insert_final_newline = true
ij_kotlin_align_in_columns_case_branch = false
Expand All @@ -407,6 +408,7 @@ ij_kotlin_align_multiline_extends_list = false
ij_kotlin_align_multiline_method_parentheses = false
ij_kotlin_align_multiline_parameters = true
ij_kotlin_align_multiline_parameters_in_calls = false
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = false
ij_kotlin_assignment_wrap = normal
ij_kotlin_blank_lines_after_class_header = 0
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Piano DMP & Content SDK for Android

## v2.5.1
* Add storing for `fallback user id`
* Updated dependencies:
- org.jetbrains.kotlinx:kotlinx-coroutines-core [1.7.3 -> 1.8.0]
https://github.com/Kotlin/kotlinx.coroutines

## v2.5.0
* Android 14 compatibility
* Fix `sdkv=unspecified` issue
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ org.gradle.caching=true
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=false
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
org.gradle.configuration-cache=true
20 changes: 10 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[versions]
# Plugins
kotlin = "1.8.21"
android = "8.1.1"
versionUpdater = "0.47.0"
ktlint = "11.5.1"
android = "8.3.1"
versionUpdater = "0.51.0"
ktlint = "12.1.0"
dokka = "1.8.10"
mavenRelease = "0.25.3"
mavenRelease = "0.28.0"
moshiIR = "0.22.1"
secrets = "2.0.1"

# AndroidX libraries
compatLibrary = "1.6.1"
annotationsLibrary = "1.6.0"
materialLibrary = "1.9.0"
annotationsLibrary = "1.7.1"
materialLibrary = "1.11.0"
startupLibrary = "1.1.1"
recyclerView = "1.3.1"
recyclerView = "1.3.2"

# Third party Libraries
googleAdsId = "18.0.1"
Expand All @@ -23,12 +23,12 @@ okhttp = "4.11.0"
moshi = "1.15.0"
timber = "5.0.1"
viewBindingProperty = "1.5.9"
coroutines = "1.7.3"
coroutines = "1.8.0"

# Test Libraries
junit = "4.13.2"
mockitoKotlin = "5.1.0"
mockitoCore = "5.5.0"
mockitoKotlin = "5.2.1"
mockitoCore = "5.11.0"

[plugins]
android-library = { id = "com.android.library", version.ref = "android" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
1 change: 1 addition & 0 deletions sdk-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ android {
}
}
buildFeatures {
buildConfig = true
viewBinding = true
}

Expand Down
28 changes: 16 additions & 12 deletions sdk-sample/src/main/java/com/example/cxensesdk/AnimalActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,23 @@ class AnimalActivity : AppCompatActivity(R.layout.activity_animal) {
WidgetContext.Builder("https://cxense.com").build(),
callback = object : LoadCallback<List<WidgetItem>> {
override fun onSuccess(data: List<WidgetItem>) {
CxenseSdk.getInstance().reportWidgetVisibilities(
object : LoadCallback<Any> {
override fun onSuccess(data: Any) {
Timber.d("Success")
}
val impressions = data.mapIndexed() { index, item ->
Impression(item.clickUrl ?: "", index + 1)
}
if (impressions.isNotEmpty()) {
CxenseSdk.getInstance().reportWidgetVisibilities(
object : LoadCallback<Any> {
override fun onSuccess(data: Any) {
Timber.d("Success")
}

override fun onError(throwable: Throwable) {
Timber.e(throwable)
}
},
Impression(data[0].clickUrl ?: "", 1),
Impression(data[1].clickUrl ?: "", 2)
)
override fun onError(throwable: Throwable) {
Timber.e(throwable)
}
},
*impressions.toTypedArray()
)
}
}

override fun onError(throwable: Throwable) {
Expand Down
11 changes: 9 additions & 2 deletions sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ plugins {
alias(libs.plugins.moshiIR)
}

@Suppress("PropertyName")
val GROUP: String by project

@Suppress("PropertyName")
val VERSION_NAME: String by project

group = GROUP
version = VERSION_NAME

Expand All @@ -20,13 +24,16 @@ android {
buildConfigField("String", "SDK_VERSION", """"$version"""")
buildConfigField("String", "SDK_NAME", """"cxense"""")
buildConfigField("String", "SDK_ENDPOINT", """"https://api.cxense.com"""")
buildConfigField("String", "AUTHORITY", """LIBRARY_PACKAGE_NAME + ".$authority"""")
buildConfigField("String", "AUTHORITY", """"io.piano.android.cxense.$authority"""")

manifestPlaceholders += "authority" to authority

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("cxensesdk.pro")
}
buildFeatures {
buildConfig = true
}

buildTypes {
named("release") {
Expand All @@ -53,7 +60,7 @@ kotlin {
}

ktlint {
version.set("0.50.0")
version.set("1.2.1")
android.set(true)
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=2.5.0
VERSION_NAME=2.5.1
GROUP=io.piano.android
POM_NAME=Piano DMP & Piano Content
POM_ARTIFACT_ID=cxense
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,29 @@ class ConversionEventConverter(
) : EventConverter() {
override fun canConvert(event: Event): Boolean = event is ConversionEvent

override fun toEventRecord(event: Event): EventRecord? =
(event as? ConversionEvent)?.run {
EventRecord(
ConversionEvent.EVENT_TYPE,
eventId,
jsonAdapter.toJson(this),
mergeKey = mergeKey
)
}
override fun toEventRecord(event: Event): EventRecord? = (event as? ConversionEvent)?.run {
EventRecord(
ConversionEvent.EVENT_TYPE,
eventId,
jsonAdapter.toJson(this),
mergeKey = mergeKey
)
}

override fun update(oldRecord: EventRecord, event: Event): EventRecord =
with(event as ConversionEvent) {
jsonAdapter.fromJson(oldRecord.data)?.let { old ->
toEventRecord(
ConversionEvent(
identities.takeUnless { it.isEmpty() } ?: old.identities,
siteId,
consentOptions.takeUnless { it.isEmpty() } ?: old.consentOptions,
productId,
funnelStep,
price ?: old.price,
renewalFrequency ?: old.renewalFrequency,
eventType
)
override fun update(oldRecord: EventRecord, event: Event): EventRecord = with(event as ConversionEvent) {
jsonAdapter.fromJson(oldRecord.data)?.let { old ->
toEventRecord(
ConversionEvent(
identities.takeUnless { it.isEmpty() } ?: old.identities,
siteId,
consentOptions.takeUnless { it.isEmpty() } ?: old.consentOptions,
productId,
funnelStep,
price ?: old.price,
renewalFrequency ?: old.renewalFrequency,
eventType
)
} ?: oldRecord
}
)
} ?: oldRecord
}
}
11 changes: 2 additions & 9 deletions sdk/src/main/java/io/piano/android/cxense/CxApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,8 @@ interface CxApi {
fun trackUrlClick(@Url url: String): Call<Unit>

@GET
fun getPersisted(
@Url url: String,
@Query("persisted") persistentId: String,
): Call<ResponseBody>
fun getPersisted(@Url url: String, @Query("persisted") persistentId: String): Call<ResponseBody>

@POST
fun postPersisted(
@Url url: String,
@Query("persisted") persistentId: String,
@Body data: Any,
): Call<ResponseBody>
fun postPersisted(@Url url: String, @Query("persisted") persistentId: String, @Body data: Any): Call<ResponseBody>
}
37 changes: 18 additions & 19 deletions sdk/src/main/java/io/piano/android/cxense/CxenseSdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import java.util.concurrent.TimeUnit
@Suppress("unused", "MemberVisibilityCanBePrivate") // Public API.
class CxenseSdk(
private val executor: ScheduledExecutorService,
@Suppress("unused", "MemberVisibilityCanBePrivate") // Public API.
// Public API.
@Suppress("unused", "MemberVisibilityCanBePrivate")
val configuration: CxenseConfiguration,
private val advertisingIdProvider: AdvertisingIdProvider,
private val userProvider: UserProvider,
Expand Down Expand Up @@ -98,13 +99,12 @@ class CxenseSdk(
* @param events the events that should be pushed.
*/
@Suppress("unused", "MemberVisibilityCanBePrivate") // Public API.
fun pushEvents(vararg events: Event) =
executor.execute {
eventRepository.putEventsInDatabase(events)
if (configuration.sendEventsAtPush) {
flushEventQueue()
}
fun pushEvents(vararg events: Event) = executor.execute {
eventRepository.putEventsInDatabase(events)
if (configuration.sendEventsAtPush) {
flushEventQueue()
}
}

/**
* Tracks active time for the given page view event.
Expand Down Expand Up @@ -435,18 +435,17 @@ class CxenseSdk(
private fun <T : Any> LoadCallback<T>.transform() = ApiCallback(this, errorParser)

private fun <T : Any> createGenericCallback(callback: LoadCallback<T>) = object : LoadCallback<ResponseBody> {
override fun onSuccess(data: ResponseBody) =
try {
val callbackClazz = callback::class.java.genericInterfaces.first() as ParameterizedType

@Suppress("UNCHECKED_CAST")
val clazz = callbackClazz.actualTypeArguments.first() as Class<T>
val jsonAdapter = moshi.adapter(clazz)
val reader = JsonReader.of(data.source())
callback.onSuccess(requireNotNull(jsonAdapter.fromJson(reader)))
} catch (e: Exception) {
callback.onError(e)
}
override fun onSuccess(data: ResponseBody) = try {
val callbackClazz = callback::class.java.genericInterfaces.first() as ParameterizedType

@Suppress("UNCHECKED_CAST")
val clazz = callbackClazz.actualTypeArguments.first() as Class<T>
val jsonAdapter = moshi.adapter(clazz)
val reader = JsonReader.of(data.source())
callback.onSuccess(requireNotNull(jsonAdapter.fromJson(reader)))
} catch (e: Exception) {
callback.onError(e)
}

override fun onError(throwable: Throwable) = callback.onError(throwable)
}.transform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ internal class DependenciesProvider private constructor(
private val userAgentProvider: UserAgentProvider by lazy { UserAgentProvider(BuildConfig.SDK_VERSION, context) }
private val deviceInfoProvider: DeviceInfoProvider by lazy { DeviceInfoProvider(context) }
private val advertisingIdProvider: AdvertisingIdProvider = AdvertisingIdProvider(context, executor)
internal val userProvider: UserProvider by lazy { UserProvider(advertisingIdProvider) }
private var prefsStorage: PrefsStorage = PrefsStorage(context)
internal val userProvider: UserProvider by lazy { UserProvider(advertisingIdProvider, prefsStorage) }
internal val cxenseConfiguration: CxenseConfiguration by lazy { CxenseConfiguration() }

private val okHttpClient: OkHttpClient by lazy {
Expand Down
Loading