Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.mapbox.dash.sdk.base.device.DashDeviceType
import com.mapbox.dash.sdk.base.domain.model.AutoAddChargingStrategy
import com.mapbox.dash.sdk.base.domain.model.BatteryComfortLevel
import com.mapbox.dash.sdk.base.units.Gb
import com.mapbox.dash.sdk.config.api.CustomKeys.ECO_ROUTES_ENABLED
import com.mapbox.dash.sdk.config.api.DEFAULT_3D_STYLE
import com.mapbox.dash.sdk.config.api.DEFAULT_DAY_STYLE
import com.mapbox.dash.sdk.config.api.DEFAULT_NIGHT_STYLE
Expand Down Expand Up @@ -60,6 +61,8 @@ class MainApplication : Application() {
context = applicationContext,
accessToken = getString(R.string.mapbox_access_token),
) {
engineType = EngineType.PETROL
customValues[ECO_ROUTES_ENABLED] = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a good idea to use CustomKeys in a public sample app

theme {
// Example of providing a custom theme to change the look-and-feel of Dash's UI components.
themeFactory = CustomThemeFactory
Expand Down Expand Up @@ -166,7 +169,6 @@ class MainApplication : Application() {
}
}

engineType = EngineType.ELECTRIC
device = DashDeviceType.Automobile
}
configureEvProvider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,19 @@ fun SampleRouteCalloutView(state: RouteCalloutUiState) {
else -> null
}.orEmpty()

state.isEcoRoute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary line


val prefix = if (state.hasTollRoad) "$ " else ""
val label = "$prefix $type".trim()

SampleRouteCalloutViewAnnotation(duration, label, state.layerId, state.callout.isPrimary, state.onClick)
SampleRouteCalloutViewAnnotation(
duration,
label,
state.layerId,
state.callout.isPrimary,
state.isEcoRoute,
state.onClick,
)
}

@Composable
Expand All @@ -89,13 +98,15 @@ private fun SampleRouteCalloutViewAnnotation(
label: String,
layerId: String,
isPrimary: Boolean,
isEcoRoute: Boolean,
onClick: () -> Unit,
) {
// key prevents annotation contents from mixing
key(
duration,
label,
layerId,
isEcoRoute,
isPrimary,
) {
val anchorState = remember { mutableStateOf(value = ViewAnnotationAnchor.TOP_LEFT) }
Expand All @@ -120,6 +131,7 @@ private fun SampleRouteCalloutViewAnnotation(
anchor = anchorState.value,
duration = duration,
primary = isPrimary,
eco = isEcoRoute,
label = label,
onClick = onClick,
)
Expand Down Expand Up @@ -177,6 +189,7 @@ private fun SampleRouteCalloutViewContent(
anchor: ViewAnnotationAnchor,
duration: Duration,
label: String = "",
eco: Boolean = false,
primary: Boolean = false,
onClick: () -> Unit = {},
) {
Expand All @@ -196,9 +209,14 @@ private fun SampleRouteCalloutViewContent(
color = if (primary) Color.White else Color.Black
)

if (label.isNotEmpty()) {
if (label.isNotEmpty() || eco) {
val text = buildString {
append(label)
if (label.isNotEmpty() && eco) append(" – ")
if (eco) append("eco")
}
Text(
label,
text,
color = if (primary) Color.White else Color.Black,
)
}
Expand All @@ -214,6 +232,7 @@ internal fun Preview_DefaultRouteCalloutView() {
SampleRouteCalloutViewContent(
anchor = ViewAnnotationAnchor.TOP_LEFT,
duration = 5.minutes + 30.seconds,
eco = true,
label = "Fastest",
)
SampleRouteCalloutViewContent(
Expand All @@ -223,12 +242,13 @@ internal fun Preview_DefaultRouteCalloutView() {
)
SampleRouteCalloutViewContent(
anchor = ViewAnnotationAnchor.BOTTOM_RIGHT,
eco = true,
duration = -1.hours,
)
SampleRouteCalloutViewContent(
anchor = ViewAnnotationAnchor.BOTTOM_LEFT,
duration = 3.hours + 25.minutes + 30.seconds,
label = "$ Fastest",
label = "Fastest",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@ private fun SampleRoutesOverviewItem(
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
SampleRoutesOverviewItemPrimaryInfo(item)
val secondRowText = buildString {
append("${item.distance.roundToLong()} m")
if (item.isEcoRoute && item.energyConsumptionSaving != null) {
append(" – eco – ${item.energyConsumptionSaving} lower emission")
}
}
Text(
text = "${item.distance.roundToLong()} m",
text = secondRowText,
color = Color.White,
fontSize = 32.sp,
lineHeight = 40.sp,
Expand Down