Skip to content

Instantly share code, notes, and snippets.

@AnalyticsEvent
sealed class MyEvent {
data class ShareImage(val imageName: String, val fullString: String) : MyEvent()
object ButtonTapped : MyEvent()
}
@malvinstn
malvinstn / processor_module_build.gradle
Last active July 9, 2019 05:19
build.gradle for your processor module
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"
// 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
// 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")
}
}