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