88 lines
No EOL
2.6 KiB
Kotlin
88 lines
No EOL
2.6 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.Maneuver
|
|
|
|
class DataCache {
|
|
|
|
private val stateCache: State = State()
|
|
private var maneuverCache: Maneuver? = null
|
|
private var locationCache: LocationMatcherResult? = null
|
|
private var session: NavigationSessionState? = null
|
|
|
|
// state
|
|
fun hasChanged(lanes: Lanes?): Boolean {
|
|
return stateCache.lineArrows == null || stateCache.lineArrows != lanes
|
|
}
|
|
|
|
fun hasChanged(outlines: Outlines?): Boolean {
|
|
return stateCache.lineOutlines == null || stateCache.lineOutlines != outlines
|
|
}
|
|
|
|
fun hasChanged(distance: Distance?): Boolean {
|
|
return stateCache.distance == null || stateCache.distance != distance
|
|
}
|
|
|
|
fun hasChanged(direction: Direction?): Boolean {
|
|
return stateCache.direction == null || stateCache.direction != direction
|
|
}
|
|
|
|
fun hasChanged(speed: Speed?): Boolean {
|
|
return stateCache.speed == null || stateCache.speed != speed
|
|
}
|
|
|
|
fun hasChanged(arrival: Arrival?): Boolean {
|
|
return stateCache.arrival == null || stateCache.arrival != arrival
|
|
}
|
|
|
|
// Merge states
|
|
fun update(state: State) {
|
|
if (state.lineArrows != null) {
|
|
stateCache.lineArrows = state.lineArrows
|
|
}
|
|
if (state.lineOutlines != null) {
|
|
state.lineOutlines = state.lineOutlines
|
|
}
|
|
if (state.direction != null) {
|
|
stateCache.direction = state.direction
|
|
}
|
|
if (state.distance != null) {
|
|
stateCache.distance = state.distance
|
|
}
|
|
if (state.speed != null) {
|
|
stateCache.speed = state.speed
|
|
}
|
|
if (state.arrival != null) {
|
|
stateCache.arrival = state.arrival
|
|
}
|
|
}
|
|
|
|
// maneuver
|
|
fun hasChanged(maneuver: Maneuver): Boolean {
|
|
return maneuverCache == null || maneuverCache!! != maneuver
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
} |