This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dummy analytics event tracker that logs the events to Logcat | |
object EventTracker { | |
private const val TAG = "EventTracker" | |
fun logEvent(name: String, params: Bundle) { | |
Log.d(TAG, "Logging event name: $name; params: $params") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set Target as class since we want this annotation to be added to a class element | |
@Target(AnnotationTarget.CLASS) | |
// Set retention as Source since we only need this annotation | |
// during annotation processing process and | |
// we don't need this class at runtime. | |
@Retention(AnnotationRetention.SOURCE) | |
annotation class AnalyticsEvent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'kotlin' | |
apply plugin: 'kotlin-kapt' | |
dependencies { | |
// Add dependency to your module that has the annotation class. | |
compileOnly project(':annotation') | |
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | |
// To easily register your custom annotation processor to the annotation process flow. | |
implementation "com.google.auto.service:auto-service:1.0-rc4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AnalyticsEvent | |
sealed class MyEvent { | |
data class ShareImage(val imageName: String, val fullString: String) : MyEvent() | |
object ButtonTapped : MyEvent() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AutoService(Processor::class) | |
class AnalyticsEventProcessor : KotlinAbstractProcessor(), KotlinMetadataUtils { | |
companion object { | |
private val ANNOTATION = AnalyticsEvent::class.java | |
} | |
override fun getSupportedAnnotationTypes() = setOf(ANNOTATION.canonicalName) | |
override fun getSupportedSourceVersion(): SourceVersion = SourceVersion.latestSupported() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AutoService(Processor::class) | |
class AnalyticsEventProcessor : KotlinAbstractProcessor(), KotlinMetadataUtils { | |
companion object { | |
private val ANNOTATION = AnalyticsEvent::class.java | |
} | |
... | |
override fun process( | |
annotations: Set<TypeElement>, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AutoService(Processor::class) | |
class AnalyticsEventProcessor : KotlinAbstractProcessor(), KotlinMetadataUtils { | |
companion object { | |
private val ANNOTATION = AnalyticsEvent::class.java | |
private const val EVENT_PARAMETER_NAME = "event" | |
private const val EVENT_NAME_PARAMETER_NAME = "name" | |
private const val EVENT_PARAM_PARAMETER_NAME = "params" | |
private const val LOG_EVENT_FUNCTION_NAME = "logEvent" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
apply plugin: 'kotlin-kapt' | |
android { | |
... | |
} | |
dependencies { | |
implementation project(':tracker') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> Flow<T>.mergeWith(other: Flow<T>): Flow<T> = flow { | |
coroutineScope { | |
launch { | |
collect { emit(it) } | |
} | |
launch { | |
other.collect { emit(it) } | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"eventType": "VIEW_CLICKED", | |
"timestamp": 1561810695346, | |
"replacementText": "", | |
"actionCode": -1, | |
"delayTime": 0, | |
"canScrollTo": false, | |
"elementDescriptors": [ | |
{ |
OlderNewer