1 package com.android.onboarding.nodes 2 3 import java.time.Instant 4 5 /** 6 * A target for onboarding logs which can register observers to store those logs. 7 * 8 * Note that this will only include part of the overall graph, and must be linked with the graph 9 * from other onboarding components to see a complete view. 10 */ 11 interface OnboardingGraphLog { 12 13 /** Add an observer for future graph changes. */ addObservernull14 fun addObserver(observer: Observer) 15 16 /** Remove the observer so it stops receiving updates. */ 17 fun removeObserver(observer: Observer) 18 19 /** 20 * Log an Onboarding event. 21 * 22 * This will be propagated to all observers. 23 */ 24 fun log(event: OnboardingEvent) 25 26 /** Interface to implement to observe [OnboardingEvent] instances. */ 27 interface Observer { 28 /** Called when an [OnboardingEvent] occurs. */ 29 fun onEvent(event: OnboardingEvent) 30 } 31 32 /** Common data applicable to all onboarding events. */ 33 interface OnboardingEventData : Comparable<Instant> { 34 val nodeName: String? 35 val nodeComponent: String? 36 val nodeId: Long 37 val timestamp: Instant 38 compareTonull39 override fun compareTo(other: Instant): Int = timestamp.compareTo(other) 40 41 operator fun compareTo(other: OnboardingEventData): Int = timestamp.compareTo(other.timestamp) 42 } 43 44 /** A wrapper over an actual onboarding event. */ 45 interface OnboardingEventDelegate : OnboardingEventData { 46 /** The actual [OnboardingEvent] this delegates to. */ 47 val source: OnboardingEvent 48 49 /** Compares this delegate with [other] delegate for [source] property equality. */ 50 infix fun eq(other: OnboardingEventDelegate): Boolean = source == other.source 51 52 override val nodeName: String? 53 get() = source.nodeName 54 55 override val nodeComponent: String? 56 get() = source.nodeComponent 57 58 override val nodeId: Long 59 get() = source.nodeId 60 61 override val timestamp: Instant 62 get() = source.timestamp 63 } 64 } 65