Skip to content

Commit

Permalink
Update dependencies, fix code style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DeKaN committed Mar 20, 2024
1 parent 38e1a13 commit 616386d
Show file tree
Hide file tree
Showing 22 changed files with 283 additions and 299 deletions.
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Piano DMP & Content SDK for Android

## v2.5.1-SNAPSHOT
* 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
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-SNAPSHOT
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
94 changes: 44 additions & 50 deletions sdk/src/main/java/io/piano/android/cxense/EventRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ class EventRepository(

fun putEventRecordInDatabase(eventRecord: EventRecord): Long = databaseHelper.save(eventRecord)

fun deleteOutdatedEvents(outdatePeriod: Long): Int =
databaseHelper.delete(
"${EventRecord.TIME} < ?",
(System.currentTimeMillis() - outdatePeriod).toString()
)
fun deleteOutdatedEvents(outdatePeriod: Long): Int = databaseHelper.delete(
"${EventRecord.TIME} < ?",
(System.currentTimeMillis() - outdatePeriod).toString()
)

fun getNotSubmittedPvEvents() = getEvents(
"$NOT_SENT_FILTER AND ${EventRecord.TYPE} = ?",
Expand All @@ -60,32 +59,29 @@ class EventRepository(
selection: String?,
selectionArgs: Array<out String?>?,
limit: String? = null,
): List<EventRecord> =
databaseHelper.query(
selection = selection,
selectionArgs = selectionArgs,
orderBy = "${EventRecord.TIME} ASC",
limit = limit
).map { it.toEventRecord() }
): List<EventRecord> = databaseHelper.query(
selection = selection,
selectionArgs = selectionArgs,
orderBy = "${EventRecord.TIME} ASC",
limit = limit
).map { it.toEventRecord() }

fun getPvEventFromDatabase(eventId: String): EventRecord? =
databaseHelper.query(
selection = "${EventRecord.CUSTOM_ID} = ? AND ${EventRecord.TYPE} = ?",
selectionArgs = arrayOf(eventId, PageViewEvent.EVENT_TYPE),
orderBy = "${EventRecord.TIME} DESC",
limit = "1"
).firstOrNull()?.toEventRecord()
fun getPvEventFromDatabase(eventId: String): EventRecord? = databaseHelper.query(
selection = "${EventRecord.CUSTOM_ID} = ? AND ${EventRecord.TYPE} = ?",
selectionArgs = arrayOf(eventId, PageViewEvent.EVENT_TYPE),
orderBy = "${EventRecord.TIME} DESC",
limit = "1"
).firstOrNull()?.toEventRecord()

fun getEventStatuses(): List<EventStatus> =
databaseHelper.query(
columns = arrayOf(EventRecord.CUSTOM_ID, EventRecord.IS_SENT),
orderBy = "${EventRecord.TIME} ASC"
).map {
EventStatus(
it.getAsString(EventRecord.CUSTOM_ID),
it.getAsBoolean(EventRecord.IS_SENT)
)
}
fun getEventStatuses(): List<EventStatus> = databaseHelper.query(
columns = arrayOf(EventRecord.CUSTOM_ID, EventRecord.IS_SENT),
orderBy = "${EventRecord.TIME} ASC"
).map {
EventStatus(
it.getAsString(EventRecord.CUSTOM_ID),
it.getAsBoolean(EventRecord.IS_SENT)
)
}

fun putEventTime(eventId: String, activeTime: Long) {
try {
Expand All @@ -107,28 +103,26 @@ class EventRepository(
}
}

private fun EventConverter.buildEventRecord(e: Event): EventRecord? =
getEvents(
"$NOT_SENT_FILTER AND ${EventRecord.MERGE_KEY} = ? AND ${EventRecord.TIME} > ?",
arrayOf(e.mergeKey.toString(), (System.currentTimeMillis() - configuration.eventsMergePeriod).toString()),
limit = "1"
).firstOrNull()?.let {
update(it, e)
} ?: toEventRecord(e)
private fun EventConverter.buildEventRecord(e: Event): EventRecord? = getEvents(
"$NOT_SENT_FILTER AND ${EventRecord.MERGE_KEY} = ? AND ${EventRecord.TIME} > ?",
arrayOf(e.mergeKey.toString(), (System.currentTimeMillis() - configuration.eventsMergePeriod).toString()),
limit = "1"
).firstOrNull()?.let {
update(it, e)
} ?: toEventRecord(e)

private fun ContentValues.toEventRecord(): EventRecord =
EventRecord(
getAsString(EventRecord.TYPE),
getAsString(EventRecord.CUSTOM_ID),
getAsString(EventRecord.DATA),
getAsString(EventRecord.CKP),
getAsString(EventRecord.RND),
getAsLong(EventRecord.TIME),
getAsLong(EventRecord.SPENT_TIME),
getAsInteger(EventRecord.MERGE_KEY),
getAsLong(BaseColumns._ID),
getAsBoolean(EventRecord.IS_SENT)
)
private fun ContentValues.toEventRecord(): EventRecord = EventRecord(
getAsString(EventRecord.TYPE),
getAsString(EventRecord.CUSTOM_ID),
getAsString(EventRecord.DATA),
getAsString(EventRecord.CKP),
getAsString(EventRecord.RND),
getAsLong(EventRecord.TIME),
getAsLong(EventRecord.SPENT_TIME),
getAsInteger(EventRecord.MERGE_KEY),
getAsLong(BaseColumns._ID),
getAsBoolean(EventRecord.IS_SENT)
)

companion object {
private const val NOT_SENT_FILTER = "${EventRecord.IS_SENT} = 0"
Expand Down
Loading

0 comments on commit 616386d

Please sign in to comment.