Data cache
This commit is contained in:
parent
89e16fb805
commit
b5cc580cf8
5 changed files with 178 additions and 40 deletions
66
app/src/main/java/eu/ztsh/garmin/data/DataCache.kt
Normal file
66
app/src/main/java/eu/ztsh/garmin/data/DataCache.kt
Normal file
|
@ -0,0 +1,66 @@
|
|||
package eu.ztsh.garmin.data
|
||||
|
||||
import com.mapbox.navigation.ui.maneuver.model.Maneuver
|
||||
|
||||
class DataCache {
|
||||
|
||||
private val stateCache: State = State()
|
||||
private var maneuverCache: Maneuver? = 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
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue