61 lines
No EOL
1.8 KiB
Kotlin
61 lines
No EOL
1.8 KiB
Kotlin
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 var maneuverCache: Maneuver? = null
|
|
private var locationCache: LocationMatcherResult? = null
|
|
private var session: NavigationSessionState? = null
|
|
private var eta: Arrival? = 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
|
|
}
|
|
|
|
// eta
|
|
fun hasChanged(eta: Arrival): Boolean {
|
|
return this.eta.let { it == null || it != eta }
|
|
}
|
|
|
|
fun update(eta: Arrival) {
|
|
this.eta = eta
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
} |