From 756b0b1f866f21d6884a03f0e7d5a1af67021e33 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Mon, 23 Oct 2023 19:01:20 +0400 Subject: [PATCH] Update to new ktlint --- .editorconfig | 6 +- piano-analytics/build.gradle.kts | 8 +- .../piano/android/analytics/DatabaseHelper.kt | 110 +++++++-------- .../io/piano/android/analytics/Delegates.kt | 33 +---- .../android/analytics/EventRepository.kt | 9 +- .../io/piano/android/analytics/MediaHelper.kt | 128 ++++++++---------- .../piano/android/analytics/PianoAnalytics.kt | 13 +- .../piano/android/analytics/PrefsStorage.kt | 17 ++- .../java/io/piano/android/analytics/Utils.kt | 15 +- .../eventprocessors/GroupEventProcessor.kt | 7 +- .../eventprocessors/PrivacyEventProcessor.kt | 11 +- .../eventprocessors/UserEventProcessor.kt | 25 ++-- .../analytics/idproviders/UuidIdProvider.kt | 9 +- 13 files changed, 175 insertions(+), 216 deletions(-) diff --git a/.editorconfig b/.editorconfig index d6e7126..225962c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -244,7 +244,7 @@ ij_editorconfig_space_before_colon = false ij_editorconfig_space_before_comma = false ij_editorconfig_spaces_around_assignment_operators = true -[{*.gradle, *.groovy, *.gant, *.gdsl, *.gy}] +[{*.gradle,*.groovy,*.gant,*.gdsl,*.gy}] ij_groovy_align_group_field_declarations = false ij_groovy_align_multiline_array_initializer_expression = false ij_groovy_align_multiline_assignment = false @@ -398,7 +398,8 @@ ij_groovy_while_brace_force = never ij_groovy_while_on_new_line = false ij_groovy_wrap_long_lines = false -[*.{kt, kts}] +[*.{kt,kts}] +ktlint_code_style = android_studio ktlint_standard_import-ordering = disabled ij_kotlin_align_in_columns_case_branch = false ij_kotlin_align_multiline_binary_operation = false @@ -406,6 +407,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 diff --git a/piano-analytics/build.gradle.kts b/piano-analytics/build.gradle.kts index 21d2456..f18dd9f 100644 --- a/piano-analytics/build.gradle.kts +++ b/piano-analytics/build.gradle.kts @@ -6,8 +6,12 @@ plugins { alias(libs.plugins.mavenRelease) } +@Suppress("PropertyName") val GROUP: String by project + +@Suppress("PropertyName") val VERSION_NAME: String by project + group = GROUP version = VERSION_NAME @@ -43,8 +47,8 @@ kotlin { } ktlint { - version.set("0.50.0") - android.set(true) + android = true + version = "1.0.1" } dependencies { diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/DatabaseHelper.kt b/piano-analytics/src/main/java/io/piano/android/analytics/DatabaseHelper.kt index bcc4743..6ce232a 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/DatabaseHelper.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/DatabaseHelper.kt @@ -42,39 +42,35 @@ internal class DatabaseHelper( } } - internal fun EventRecord.toContentValues(): ContentValues = - ContentValues().apply { - put(EventRecord.DATA, dataEncoder.encode(data)) - put(EventRecord.TIME, timestamp) - put(EventRecord.IS_SENT, isSent) - } + internal fun EventRecord.toContentValues(): ContentValues = ContentValues().apply { + put(EventRecord.DATA, dataEncoder.encode(data)) + put(EventRecord.TIME, timestamp) + put(EventRecord.IS_SENT, isSent) + } - fun ContentValues.toEventRecord(): EventRecord = - EventRecord( - dataEncoder.decode(getAsString(EventRecord.DATA)), - getAsLong(EventRecord.TIME), - getAsLong(EventRecord.ID), - getAsBoolean(EventRecord.IS_SENT) - ) + fun ContentValues.toEventRecord(): EventRecord = EventRecord( + dataEncoder.decode(getAsString(EventRecord.DATA)), + getAsLong(EventRecord.TIME), + getAsLong(EventRecord.ID), + getAsBoolean(EventRecord.IS_SENT) + ) - fun save(eventRecord: EventRecord): Long = - eventRecord.id?.let { id -> - writableDatabase.update( - EventRecord.TABLE_NAME, - eventRecord.toContentValues(), - "${EventRecord.ID} = ?", - arrayOf(id.toString()) - ).toLong() - } ?: writableDatabase.insert( + fun save(eventRecord: EventRecord): Long = eventRecord.id?.let { id -> + writableDatabase.update( EventRecord.TABLE_NAME, - null, - eventRecord.toContentValues() - ) + eventRecord.toContentValues(), + "${EventRecord.ID} = ?", + arrayOf(id.toString()) + ).toLong() + } ?: writableDatabase.insert( + EventRecord.TABLE_NAME, + null, + eventRecord.toContentValues() + ) - fun delete(eventRecord: EventRecord): Int = - eventRecord.id?.let { id -> - delete("${EventRecord.ID} = ?", id.toString()) - } ?: -1 + fun delete(eventRecord: EventRecord): Int = eventRecord.id?.let { id -> + delete("${EventRecord.ID} = ?", id.toString()) + } ?: -1 fun delete(whereClause: String?, vararg whereArgs: String): Int = writableDatabase.delete(EventRecord.TABLE_NAME, whereClause, whereArgs) @@ -87,42 +83,40 @@ internal class DatabaseHelper( having: String? = null, orderBy: String? = "${EventRecord.TIME} ASC", limit: String? = null, - ): List = - readableDatabase.query( - EventRecord.TABLE_NAME, - columns, - selection, - selectionArgs, - groupBy, - having, - orderBy, - limit - ).use { c -> - generateSequence { if (c.moveToNext()) c else null } - .map(Companion::cursorRowToContentValues) - .map { - it.toEventRecord() - }.filter { - it.isValid - }.toList() - } + ): List = readableDatabase.query( + EventRecord.TABLE_NAME, + columns, + selection, + selectionArgs, + groupBy, + having, + orderBy, + limit + ).use { c -> + generateSequence { if (c.moveToNext()) c else null } + .map(Companion::cursorRowToContentValues) + .map { + it.toEventRecord() + }.filter { + it.isValid + }.toList() + } companion object { const val DATABASE_VERSION = 1 private const val DATABASE_NAME = "events.db" @JvmStatic - private fun cursorRowToContentValues(c: Cursor): ContentValues = - ContentValues().apply { - for (i in 0 until c.columnCount) { - val name = c.columnNames[i] - when (c.getType(i)) { - Cursor.FIELD_TYPE_BLOB -> put(name, c.getBlob(i)) - Cursor.FIELD_TYPE_FLOAT -> put(name, c.getFloat(i)) - Cursor.FIELD_TYPE_INTEGER -> put(name, c.getLong(i)) - else -> put(name, c.getString(i)) - } + private fun cursorRowToContentValues(c: Cursor): ContentValues = ContentValues().apply { + for (i in 0 until c.columnCount) { + val name = c.columnNames[i] + when (c.getType(i)) { + Cursor.FIELD_TYPE_BLOB -> put(name, c.getBlob(i)) + Cursor.FIELD_TYPE_FLOAT -> put(name, c.getFloat(i)) + Cursor.FIELD_TYPE_INTEGER -> put(name, c.getLong(i)) + else -> put(name, c.getString(i)) } } + } } } diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/Delegates.kt b/piano-analytics/src/main/java/io/piano/android/analytics/Delegates.kt index 35dbcc0..b050ca4 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/Delegates.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/Delegates.kt @@ -19,10 +19,7 @@ internal inline fun delegatedPropertyWithDefaultValue( } } -internal fun resettableProperty( - resetValue: T, - initializer: () -> T, -) = ResettableProperty(resetValue, initializer) +internal fun resettableProperty(resetValue: T, initializer: () -> T) = ResettableProperty(resetValue, initializer) internal class ResettableProperty( private val resetValue: T, @@ -48,29 +45,25 @@ internal class SharedPreferenceDelegates(private val prefs: SharedPreferences) { default: Boolean = false, key: String? = null, canBeSaved: (key: String) -> Boolean = DEFAULT_SAVE_FILTER, - ): ReadWriteProperty = - create(default, key, canBeSaved, prefs::getBoolean, prefs.edit()::putBoolean) + ): ReadWriteProperty = create(default, key, canBeSaved, prefs::getBoolean, prefs.edit()::putBoolean) fun int( default: Int = 0, key: String? = null, canBeSaved: (key: String) -> Boolean = DEFAULT_SAVE_FILTER, - ): ReadWriteProperty = - create(default, key, canBeSaved, prefs::getInt, prefs.edit()::putInt) + ): ReadWriteProperty = create(default, key, canBeSaved, prefs::getInt, prefs.edit()::putInt) fun float( default: Float = 0f, key: String? = null, canBeSaved: (key: String) -> Boolean = DEFAULT_SAVE_FILTER, - ): ReadWriteProperty = - create(default, key, canBeSaved, prefs::getFloat, prefs.edit()::putFloat) + ): ReadWriteProperty = create(default, key, canBeSaved, prefs::getFloat, prefs.edit()::putFloat) fun long( default: Long = 0L, key: String? = null, canBeSaved: (key: String) -> Boolean = DEFAULT_SAVE_FILTER, - ): ReadWriteProperty = - create(default, key, canBeSaved, prefs::getLong, prefs.edit()::putLong) + ): ReadWriteProperty = create(default, key, canBeSaved, prefs::getLong, prefs.edit()::putLong) fun string( default: String = "", @@ -86,19 +79,6 @@ internal class SharedPreferenceDelegates(private val prefs: SharedPreferences) { ): ReadWriteProperty = create(default, key, canBeSaved, { k, d -> prefs.getString(k, d) }, prefs.edit()::putString) - fun stringSet( - default: Set = emptySet(), - key: String? = null, - canBeSaved: (key: String) -> Boolean = DEFAULT_SAVE_FILTER, - ): ReadWriteProperty> = - create( - default, - key, - canBeSaved, - { k, d -> prefs.getStringSet(k, d) as Set }, - prefs.edit()::putStringSet - ) - private fun create( default: T, key: String? = null, @@ -108,8 +88,7 @@ internal class SharedPreferenceDelegates(private val prefs: SharedPreferences) { ) = object : ReadWriteProperty { private fun key(property: KProperty<*>) = key ?: property.name - override fun getValue(thisRef: Any, property: KProperty<*>): T = - getter(key(property), default) + override fun getValue(thisRef: Any, property: KProperty<*>): T = getter(key(property), default) override fun setValue(thisRef: Any, property: KProperty<*>, value: T) { val propertyKey = key(property) diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/EventRepository.kt b/piano-analytics/src/main/java/io/piano/android/analytics/EventRepository.kt index c0b850f..d7aeda4 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/EventRepository.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/EventRepository.kt @@ -22,11 +22,10 @@ internal class EventRepository( ) } - fun getNotSentEvents(): List = - databaseHelper.query( - selection = "${EventRecord.IS_SENT} = 0", - orderBy = "${EventRecord.TIME} ASC" - ) + fun getNotSentEvents(): List = databaseHelper.query( + selection = "${EventRecord.IS_SENT} = 0", + orderBy = "${EventRecord.TIME} ASC" + ) fun markEventsAsSent(events: Collection) { events.forEach { e -> diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/MediaHelper.kt b/piano-analytics/src/main/java/io/piano/android/analytics/MediaHelper.kt index b590f49..1f256ce 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/MediaHelper.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/MediaHelper.kt @@ -141,8 +141,7 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun bufferHeartbeat(vararg properties: Property) = - processBufferHeartbeat(false, *properties) + fun bufferHeartbeat(vararg properties: Property) = processBufferHeartbeat(false, *properties) /** * Generate heartbeat during rebuffering. @@ -150,8 +149,7 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun rebufferHeartbeat(vararg properties: Property) = - processRebufferHeartbeat(false, *properties) + fun rebufferHeartbeat(vararg properties: Property) = processRebufferHeartbeat(false, *properties) /** * Generate play event (play attempt). @@ -210,25 +208,24 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun playbackStart(cursorPosition: Int, vararg properties: Property) = - processEvent(AV_START, properties) { - previousCursorPositionMillis = cursorPosition.coerceAtLeast(0) - currentCursorPositionMillis = previousCursorPositionMillis - bufferTimeMillis = 0 - isPlaying = true - isPlaybackActivated = true + fun playbackStart(cursorPosition: Int, vararg properties: Property) = processEvent(AV_START, properties) { + previousCursorPositionMillis = cursorPosition.coerceAtLeast(0) + currentCursorPositionMillis = previousCursorPositionMillis + bufferTimeMillis = 0 + isPlaying = true + isPlaybackActivated = true - restartHeartbeatExecutor() - if (autoHeartbeat) { - previousHeartbeatDelay = rescheduleRunnable( - previousHeartbeatDelay, - startSessionTimeMillis, - MIN_HEARTBEAT_DURATION, - heartbeatDurations, - heartbeatRunnable - ) - } + restartHeartbeatExecutor() + if (autoHeartbeat) { + previousHeartbeatDelay = rescheduleRunnable( + previousHeartbeatDelay, + startSessionTimeMillis, + MIN_HEARTBEAT_DURATION, + heartbeatDurations, + heartbeatRunnable + ) } + } /** * Media playback paused. @@ -237,15 +234,14 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun playbackPaused(cursorPosition: Int, vararg properties: Property) = - processEvent(AV_PAUSE, properties) { - previousCursorPositionMillis = currentCursorPositionMillis - currentCursorPositionMillis = cursorPosition.coerceAtLeast(0) - bufferTimeMillis = 0 - isPlaying = false - isPlaybackActivated = true - restartHeartbeatExecutor() - } + fun playbackPaused(cursorPosition: Int, vararg properties: Property) = processEvent(AV_PAUSE, properties) { + previousCursorPositionMillis = currentCursorPositionMillis + currentCursorPositionMillis = cursorPosition.coerceAtLeast(0) + bufferTimeMillis = 0 + isPlaying = false + isPlaybackActivated = true + restartHeartbeatExecutor() + } /** * Media playback restarted manually after a pause. @@ -254,25 +250,24 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun playbackResumed(cursorPosition: Int, vararg properties: Property) = - processEvent(AV_RESUME, properties) { - previousCursorPositionMillis = currentCursorPositionMillis - currentCursorPositionMillis = cursorPosition.coerceAtLeast(0) - bufferTimeMillis = 0 - isPlaying = true - isPlaybackActivated = true + fun playbackResumed(cursorPosition: Int, vararg properties: Property) = processEvent(AV_RESUME, properties) { + previousCursorPositionMillis = currentCursorPositionMillis + currentCursorPositionMillis = cursorPosition.coerceAtLeast(0) + bufferTimeMillis = 0 + isPlaying = true + isPlaybackActivated = true - restartHeartbeatExecutor() - if (autoHeartbeat) { - previousHeartbeatDelay = rescheduleRunnable( - previousHeartbeatDelay, - startSessionTimeMillis, - MIN_HEARTBEAT_DURATION, - heartbeatDurations, - heartbeatRunnable - ) - } + restartHeartbeatExecutor() + if (autoHeartbeat) { + previousHeartbeatDelay = rescheduleRunnable( + previousHeartbeatDelay, + startSessionTimeMillis, + MIN_HEARTBEAT_DURATION, + heartbeatDurations, + heartbeatRunnable + ) } + } /** * Media playback stopped. @@ -356,8 +351,7 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun adClick(vararg properties: Property) = - pianoAnalytics.sendEvents(buildEvent(AV_AD_CLICK, false, *properties)) + fun adClick(vararg properties: Property) = pianoAnalytics.sendEvents(buildEvent(AV_AD_CLICK, false, *properties)) /** * Measuring media skip (especially for ads). @@ -365,8 +359,7 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun adSkip(vararg properties: Property) = - pianoAnalytics.sendEvents(buildEvent(AV_AD_SKIP, false, *properties)) + fun adSkip(vararg properties: Property) = pianoAnalytics.sendEvents(buildEvent(AV_AD_SKIP, false, *properties)) /** * Measuring reco or Ad display. @@ -374,8 +367,7 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun display(vararg properties: Property) = - pianoAnalytics.sendEvents(buildEvent(AV_DISPLAY, false, *properties)) + fun display(vararg properties: Property) = pianoAnalytics.sendEvents(buildEvent(AV_DISPLAY, false, *properties)) /** * Measuring close action. @@ -383,8 +375,7 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun close(vararg properties: Property) = - pianoAnalytics.sendEvents(buildEvent(AV_CLOSE, false, *properties)) + fun close(vararg properties: Property) = pianoAnalytics.sendEvents(buildEvent(AV_CLOSE, false, *properties)) /** * Measurement of a volume change action. @@ -392,8 +383,7 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun volume(vararg properties: Property) = - pianoAnalytics.sendEvents(buildEvent(AV_VOLUME, false, *properties)) + fun volume(vararg properties: Property) = pianoAnalytics.sendEvents(buildEvent(AV_VOLUME, false, *properties)) /** * Measurement of activated subtitles. @@ -437,8 +427,7 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun quality(vararg properties: Property) = - pianoAnalytics.sendEvents(buildEvent(AV_QUALITY, false, *properties)) + fun quality(vararg properties: Property) = pianoAnalytics.sendEvents(buildEvent(AV_QUALITY, false, *properties)) /** * Measurement of a speed change action. @@ -446,8 +435,7 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun speed(vararg properties: Property) = - pianoAnalytics.sendEvents(buildEvent(AV_SPEED, false, *properties)) + fun speed(vararg properties: Property) = pianoAnalytics.sendEvents(buildEvent(AV_SPEED, false, *properties)) /** * Measurement of a sharing action. @@ -455,8 +443,7 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun share(vararg properties: Property) = - pianoAnalytics.sendEvents(buildEvent(AV_SHARE, false, *properties)) + fun share(vararg properties: Property) = pianoAnalytics.sendEvents(buildEvent(AV_SHARE, false, *properties)) /** * Error measurement preventing reading from continuing. @@ -465,15 +452,14 @@ class MediaHelper internal constructor( * @param properties extra properties for event */ @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. - fun error(message: String, vararg properties: Property) = - pianoAnalytics.sendEvents( - buildEvent( - AV_ERROR, - false, - Property(PropertyName("av_player_error"), message), - *properties - ) + fun error(message: String, vararg properties: Property) = pianoAnalytics.sendEvents( + buildEvent( + AV_ERROR, + false, + Property(PropertyName("av_player_error"), message), + *properties ) + ) /** * Track custom event, don't use it for built-in events. diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/PianoAnalytics.kt b/piano-analytics/src/main/java/io/piano/android/analytics/PianoAnalytics.kt index 2aa0ea5..cac6453 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/PianoAnalytics.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/PianoAnalytics.kt @@ -31,11 +31,14 @@ class PianoAnalytics internal constructor( private val visitorIdProvider: VisitorIdProvider, private val customIdProvider: CustomIdProvider, customEventProcessorsGroup: GroupEventProcessor, - @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. + // Public API. + @Suppress("unused", "MemberVisibilityCanBePrivate") val privacyModesStorage: PrivacyModesStorage, - @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. + // Public API. + @Suppress("unused", "MemberVisibilityCanBePrivate") val contextPropertiesStorage: ContextPropertiesStorage, - @Suppress("unused", "MemberVisibilityCanBePrivate") // Public API. + // Public API. + @Suppress("unused", "MemberVisibilityCanBePrivate") val userStorage: UserStorage, ) { private val executor: ScheduledExecutorService = executorProvider() @@ -116,9 +119,7 @@ class PianoAnalytics internal constructor( * @param events a custom event list */ @Suppress("unused") // Public API. - fun sendEvents( - vararg events: Event, - ) { + fun sendEvents(vararg events: Event) { // delay is required, see androidx.lifecycle.ProcessLifecycleOwner.TIMEOUT_MS executor.schedule( { diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/PrefsStorage.kt b/piano-analytics/src/main/java/io/piano/android/analytics/PrefsStorage.kt index c1ac752..d62dd49 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/PrefsStorage.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/PrefsStorage.kt @@ -17,16 +17,15 @@ internal class PrefsStorage( internal fun clear() = prefs.edit().clear().apply() - internal fun cleanStorageFeature(privacyStorageFeature: PrivacyStorageFeature) = - prefs.edit().apply { - if (privacyStorageFeature != PrivacyStorageFeature.ALL) { - keysByPrivacyStorageFeature[privacyStorageFeature]?.forEach { - remove(it) - } - } else { - clear() + internal fun cleanStorageFeature(privacyStorageFeature: PrivacyStorageFeature) = prefs.edit().apply { + if (privacyStorageFeature != PrivacyStorageFeature.ALL) { + keysByPrivacyStorageFeature[privacyStorageFeature]?.forEach { + remove(it) } - }.apply() + } else { + clear() + } + }.apply() init { if (REMOVED_KEYS.any { prefs.contains(it) }) { diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/Utils.kt b/piano-analytics/src/main/java/io/piano/android/analytics/Utils.kt index b3bba9d..e098773 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/Utils.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/Utils.kt @@ -12,13 +12,12 @@ internal fun isLogHttpSet(): Boolean = getProperty(LOG_HTTP_KEY) == "true" @SuppressLint("PrivateApi") @Suppress("SameParameterValue") -private fun getProperty(key: String): String? = - runCatching { - Class.forName("android.os.SystemProperties") - .getMethod("get", String::class.java, String::class.java) - .invoke(null, key, null) as? String - }.onFailure { - Timber.w(it, "can't get value %s from SystemProperties", key) - }.getOrNull() +private fun getProperty(key: String): String? = runCatching { + Class.forName("android.os.SystemProperties") + .getMethod("get", String::class.java, String::class.java) + .invoke(null, key, null) as? String +}.onFailure { + Timber.w(it, "can't get value %s from SystemProperties", key) +}.getOrNull() private const val LOG_HTTP_KEY = "debug.piano.sdk" diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/eventprocessors/GroupEventProcessor.kt b/piano-analytics/src/main/java/io/piano/android/analytics/eventprocessors/GroupEventProcessor.kt index 934e86e..342e47a 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/eventprocessors/GroupEventProcessor.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/eventprocessors/GroupEventProcessor.kt @@ -5,8 +5,7 @@ import io.piano.android.analytics.model.Event internal class GroupEventProcessor internal constructor( private val processors: MutableList = mutableListOf(), ) : EventProcessor, MutableList by processors { - override fun process(events: List): List = - processors.fold(events) { acc, eventProcessor -> - eventProcessor.process(acc) - } + override fun process(events: List): List = processors.fold(events) { acc, eventProcessor -> + eventProcessor.process(acc) + } } diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/eventprocessors/PrivacyEventProcessor.kt b/piano-analytics/src/main/java/io/piano/android/analytics/eventprocessors/PrivacyEventProcessor.kt index 7dcf7cd..61a4c75 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/eventprocessors/PrivacyEventProcessor.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/eventprocessors/PrivacyEventProcessor.kt @@ -47,12 +47,11 @@ internal class PrivacyEventProcessor( } @Suppress("NOTHING_TO_INLINE") - private inline fun Set.simplify(): Set = - if (contains(WILDCARD)) { - setOf(WILDCARD) - } else { - toSet() - } + private inline fun Set.simplify(): Set = if (contains(WILDCARD)) { + setOf(WILDCARD) + } else { + toSet() + } @Suppress("NOTHING_TO_INLINE") private inline fun Map>.simplify(): Map> = mapValues { diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/eventprocessors/UserEventProcessor.kt b/piano-analytics/src/main/java/io/piano/android/analytics/eventprocessors/UserEventProcessor.kt index 16113c2..18d95e8 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/eventprocessors/UserEventProcessor.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/eventprocessors/UserEventProcessor.kt @@ -8,17 +8,16 @@ import io.piano.android.analytics.model.PropertyName internal class UserEventProcessor( private val userStorage: UserStorage, ) : EventProcessor { - override fun process(events: List): List = - userStorage.currentUser?.let { - val properties = mutableListOf( - Property(PropertyName.USER_ID, it.id), - Property(PropertyName.USER_RECOGNITION, userStorage.userRecognized) - ) - if (it.category != null) { - properties.add(Property(PropertyName.USER_CATEGORY, it.category)) - } - events.map { event -> - event.newBuilder().properties(properties).build() - } - } ?: events + override fun process(events: List): List = userStorage.currentUser?.let { + val properties = mutableListOf( + Property(PropertyName.USER_ID, it.id), + Property(PropertyName.USER_RECOGNITION, userStorage.userRecognized) + ) + if (it.category != null) { + properties.add(Property(PropertyName.USER_CATEGORY, it.category)) + } + events.map { event -> + event.newBuilder().properties(properties).build() + } + } ?: events } diff --git a/piano-analytics/src/main/java/io/piano/android/analytics/idproviders/UuidIdProvider.kt b/piano-analytics/src/main/java/io/piano/android/analytics/idproviders/UuidIdProvider.kt index 5fe4eb2..8478b70 100644 --- a/piano-analytics/src/main/java/io/piano/android/analytics/idproviders/UuidIdProvider.kt +++ b/piano-analytics/src/main/java/io/piano/android/analytics/idproviders/UuidIdProvider.kt @@ -33,11 +33,10 @@ internal class UuidIdProvider( } override val isLimitAdTrackingEnabled: Boolean = false - internal fun createNewUuid() = - UUID.randomUUID().toString().also { - prefsStorage.visitorUuid = it - prefsStorage.visitorUuidGenerateTimestamp = getGenerationTimestamp() - } + internal fun createNewUuid() = UUID.randomUUID().toString().also { + prefsStorage.visitorUuid = it + prefsStorage.visitorUuidGenerateTimestamp = getGenerationTimestamp() + } // for mocking in tests internal fun getGenerationTimestamp() = System.currentTimeMillis()