fix: Threading & optimizations
This commit is contained in:
parent
6d71245d9f
commit
f5ec500343
4 changed files with 142 additions and 142 deletions
|
@ -2,7 +2,10 @@ 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 {
|
||||
|
||||
|
@ -11,38 +14,17 @@ class DataCache {
|
|||
private var locationCache: LocationMatcherResult? = null
|
||||
private var session: NavigationSessionState? = null
|
||||
|
||||
// state
|
||||
fun hasChanged(lanes: Lanes): Boolean {
|
||||
return garminManeuver.lanes != lanes
|
||||
}
|
||||
|
||||
fun hasChanged(distance: Distance): Boolean {
|
||||
return garminManeuver.distance != distance
|
||||
}
|
||||
|
||||
fun hasChanged(direction: Direction): Boolean {
|
||||
return garminManeuver.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(item: GarminModelItem) {
|
||||
when(item) {
|
||||
is GarminManeuver -> garminManeuver.merge(item)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// maneuver
|
||||
fun hasChanged(maneuver: Maneuver): Boolean {
|
||||
return maneuverCache == null || maneuverCache!! != 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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue