package eu.ztsh.garmin.data import com.mapbox.navigation.core.trip.session.LocationMatcherResult import com.mapbox.navigation.core.trip.session.NavigationSessionState import com.mapbox.navigation.tripdata.maneuver.model.Lane import com.mapbox.navigation.tripdata.maneuver.model.Maneuver import com.mapbox.navigation.tripdata.maneuver.model.PrimaryManeuver import com.mapbox.navigation.tripdata.maneuver.model.StepDistance class DataCache { private val garminManeuver: GarminManeuver = GarminManeuver.empty() private var maneuverCache: Maneuver? = null private var locationCache: LocationMatcherResult? = null private var session: NavigationSessionState? = null // maneuver fun hasChanged(guidance: Lane?): Boolean { return guidance != null && maneuverCache.let { it == null || it.laneGuidance != guidance } } fun hasChanged(distance: StepDistance): Boolean { return maneuverCache.let { it == null || it.stepDistance != distance } } fun hasChanged(primaryManeuver: PrimaryManeuver): Boolean { return maneuverCache.let { it == null || it.primary != primaryManeuver } } fun update(maneuver: Maneuver) { maneuverCache = maneuver } // location fun hasChanged(locationMatcherResult: LocationMatcherResult): Boolean { return locationCache == null || locationCache!! != locationMatcherResult } fun update(locationMatcherResult: LocationMatcherResult) { locationCache = locationMatcherResult } // session fun isActive(): Boolean { return session != null && session is NavigationSessionState.ActiveGuidance } fun update(sessionState: NavigationSessionState) { session = sessionState } }