RouteCarModel
This commit is contained in:
@@ -346,7 +346,6 @@ class NavigationSession : CarSession(), NavigationListener, NavigationObserverCa
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
textToSpeechManager = TextToSpeechManager(carContext)
|
||||
repository.guidanceAudioFlow.asLiveData().observe(this, Observer {
|
||||
guidanceAudio = it
|
||||
@@ -534,29 +533,16 @@ class NavigationSession : CarSession(), NavigationListener, NavigationObserverCa
|
||||
) {
|
||||
return
|
||||
}
|
||||
val travelEstimateTrip = routeModel.travelEstimateTrip(carContext, distanceMode)
|
||||
val travelEstimateStep = routeModel.travelEstimateStep(carContext, distanceMode)
|
||||
val steps = mutableListOf<Step>()
|
||||
val destination = Destination.Builder()
|
||||
.setName(routeModel.navState.destination.name)
|
||||
.setAddress(routeModel.navState.destination.street)
|
||||
.build()
|
||||
val distance =
|
||||
formattedDistance(0, routeModel.routeCalculator.leftStepDistance())
|
||||
steps.add(routeModel.currentStep(carContext))
|
||||
if (routeModel.navState.nextStep) {
|
||||
steps.add(routeModel.nextStep(carContext = carContext))
|
||||
|
||||
}
|
||||
navigationScreen.updateTrip(
|
||||
isNavigating = routeModel.isNavigating(),
|
||||
isRerouting = false,
|
||||
hasArrived = routeModel.isArrival(),
|
||||
destinationTravelEstimate = travelEstimateTrip,
|
||||
stepTravelEstimate = travelEstimateStep,
|
||||
destinations = mutableListOf(destination),
|
||||
steps = steps,
|
||||
stepRemainingDistance = Distance.create(distance.first, distance.second),
|
||||
destinationTravelEstimate = routeModel.getTravelEstimateTrip(carContext),
|
||||
stepTravelEstimate = routeModel.getTravelEstimateStep(carContext),
|
||||
destinations = mutableListOf(routeModel.getDestination()),
|
||||
steps = routeModel.getSteps(carContext),
|
||||
stepRemainingDistance = routeModel.getDistance(),
|
||||
shouldShowNextStep = false,
|
||||
shouldShowLanes = true,
|
||||
junctionImage = null,
|
||||
@@ -570,12 +556,12 @@ class NavigationSession : CarSession(), NavigationListener, NavigationObserverCa
|
||||
|
||||
val tripBuilder = Trip.Builder()
|
||||
tripBuilder.addDestination(
|
||||
destination,
|
||||
travelEstimateTrip
|
||||
routeModel.getDestination(),
|
||||
routeModel.getTravelEstimateTrip(carContext)
|
||||
)
|
||||
tripBuilder.setLoading(false)
|
||||
tripBuilder.setCurrentRoad(destination.name.toString())
|
||||
tripBuilder.addStep(steps.first(), travelEstimateStep)
|
||||
tripBuilder.setCurrentRoad( routeModel.getDestination().name.toString())
|
||||
tripBuilder.addStep(routeModel.getSteps(carContext).first(), routeModel.getTravelEstimateStep(carContext))
|
||||
updateTrip(tripBuilder.build())
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.car.app.model.DateTimeWithZone
|
||||
import androidx.car.app.model.Distance
|
||||
import androidx.car.app.model.DurationSpan
|
||||
import androidx.car.app.model.ForegroundCarColorSpan
|
||||
import androidx.car.app.navigation.model.Destination
|
||||
import androidx.car.app.navigation.model.Lane
|
||||
import androidx.car.app.navigation.model.LaneDirection
|
||||
import androidx.car.app.navigation.model.Maneuver
|
||||
@@ -99,7 +100,6 @@ class RouteCarModel : RouteModel() {
|
||||
}
|
||||
|
||||
fun travelEstimate(carContext: CarContext, timeLeft: Double, distanceMode: Int): TravelEstimate {
|
||||
|
||||
val timeToDestinationMillis =
|
||||
TimeUnit.SECONDS.toMillis(timeLeft.toLong())
|
||||
val distance = formattedDistance(distanceMode, routeCalculator.travelLeftDistance())
|
||||
@@ -134,6 +134,37 @@ class RouteCarModel : RouteModel() {
|
||||
}
|
||||
return travelBuilder.build()
|
||||
}
|
||||
|
||||
fun getSteps(carContext: CarContext): MutableList<Step> {
|
||||
val steps = mutableListOf<Step>()
|
||||
steps.add(currentStep(carContext))
|
||||
if (navState.nextStep) {
|
||||
steps.add(nextStep(carContext = carContext))
|
||||
}
|
||||
return steps
|
||||
}
|
||||
|
||||
fun getDistance(): Distance {
|
||||
val distance =
|
||||
formattedDistance(0, routeCalculator.leftStepDistance())
|
||||
return Distance.create(distance.first, distance.second)
|
||||
}
|
||||
|
||||
fun getTravelEstimateTrip(carContext: CarContext): TravelEstimate {
|
||||
return travelEstimateTrip(carContext, 0)
|
||||
}
|
||||
|
||||
fun getTravelEstimateStep(carContext: CarContext): TravelEstimate {
|
||||
return travelEstimateStep(carContext, 0)
|
||||
}
|
||||
|
||||
fun getDestination(): Destination {
|
||||
return Destination.Builder()
|
||||
.setName(navState.destination.name)
|
||||
.setAddress(navState.destination.street)
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun createDelay(delay: Int): CarText {
|
||||
val delayBuilder = SpannableStringBuilder()
|
||||
delayBuilder.append(
|
||||
|
||||
Reference in New Issue
Block a user