-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: view refactor & cleanup * feat: refactoring views for better reuse, easier config and more general purpose features * feat: in progressing setting up basics for car play * Apply automatic changes * feat: in progressing setting up basics for car play * feat: improved android view config and setup, current road name and showcase route: * feat: improved android view config and setup, current road name and showcase route: * feat: improved android view config and setup, current road name and showcase route: * feat: improved android view config and setup, current road name and showcase route: --------- Co-authored-by: Archdoog <[email protected]>
- Loading branch information
Showing
41 changed files
with
620 additions
and
444 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
...src/main/java/com/stadiamaps/ferrostar/composeui/config/NavigationViewComponentBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.stadiamaps.ferrostar.composeui.config | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.BoxScope | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.stadiamaps.ferrostar.composeui.models.CameraControlState | ||
import com.stadiamaps.ferrostar.composeui.theme.DefaultNavigationUITheme | ||
import com.stadiamaps.ferrostar.composeui.theme.NavigationUITheme | ||
import com.stadiamaps.ferrostar.composeui.views.components.CurrentRoadNameView | ||
import com.stadiamaps.ferrostar.composeui.views.components.InstructionsView | ||
import com.stadiamaps.ferrostar.composeui.views.components.TripProgressView | ||
import com.stadiamaps.ferrostar.core.NavigationUiState | ||
|
||
data class NavigationViewComponentBuilder( | ||
val instructionsView: @Composable (modifier: Modifier, uiState: NavigationUiState) -> Unit, | ||
val progressView: | ||
@Composable | ||
(modifier: Modifier, uiState: NavigationUiState, onTapExit: (() -> Unit)?) -> Unit, | ||
val streetNameView: | ||
@Composable | ||
(modifier: Modifier, roadName: String?, cameraControlState: CameraControlState) -> Unit, | ||
val customOverlayView: @Composable (BoxScope.(Modifier) -> Unit)? = null, | ||
// TODO: We may reasonably be able to add the NavigationMapView here. But not sure how much | ||
// value that would add | ||
// since most of the hard config already exists within the overlay views which are not | ||
// maplibre specific. | ||
) { | ||
companion object { | ||
fun Default(theme: NavigationUITheme = DefaultNavigationUITheme) = | ||
NavigationViewComponentBuilder( | ||
instructionsView = { modifier, uiState -> | ||
uiState.visualInstruction?.let { instructions -> | ||
InstructionsView( | ||
modifier = modifier, | ||
instructions = instructions, | ||
theme = theme.instructionRowTheme, | ||
remainingSteps = uiState.remainingSteps, | ||
distanceToNextManeuver = uiState.progress?.distanceToNextManeuver) | ||
} | ||
}, | ||
progressView = { modifier, uiState, onTapExit -> | ||
uiState.progress?.let { progress -> | ||
TripProgressView( | ||
modifier = modifier, | ||
theme = theme.tripProgressViewTheme, | ||
progress = progress, | ||
onTapExit = onTapExit) | ||
} | ||
}, | ||
streetNameView = { modifier, roadName, cameraControlState -> | ||
if (cameraControlState is CameraControlState.ShowRouteOverview) { | ||
roadName?.let { roadName -> | ||
Row( | ||
modifier.fillMaxWidth(), | ||
verticalAlignment = Alignment.Bottom, | ||
horizontalArrangement = Arrangement.Center) { | ||
CurrentRoadNameView( | ||
modifier = modifier, | ||
theme = theme.roadNameViewTheme, | ||
currentRoadName = roadName) | ||
|
||
Spacer(modifier = Modifier.height(8.dp)) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
fun NavigationViewComponentBuilder.withInstructionsView( | ||
instructionsView: @Composable (modifier: Modifier, uiState: NavigationUiState) -> Unit | ||
): NavigationViewComponentBuilder { | ||
return copy(instructionsView = instructionsView) | ||
} | ||
|
||
fun NavigationViewComponentBuilder.withProgressView( | ||
progressView: | ||
@Composable | ||
(modifier: Modifier, uiState: NavigationUiState, onTapExit: (() -> Unit)?) -> Unit | ||
): NavigationViewComponentBuilder { | ||
return copy(progressView = progressView) | ||
} | ||
|
||
fun NavigationViewComponentBuilder.withStreetNameView( | ||
streetNameView: | ||
@Composable | ||
(modifier: Modifier, roadName: String?, cameraControlState: CameraControlState) -> Unit | ||
): NavigationViewComponentBuilder { | ||
return copy(streetNameView = streetNameView) | ||
} | ||
|
||
fun NavigationViewComponentBuilder.withCustomOverlayView( | ||
customOverlayView: @Composable (BoxScope.(Modifier) -> Unit) | ||
): NavigationViewComponentBuilder { | ||
return copy(customOverlayView = customOverlayView) | ||
} |
37 changes: 13 additions & 24 deletions
37
...eui/src/main/java/com/stadiamaps/ferrostar/composeui/config/VisualNavigationViewConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,29 @@ | ||
package com.stadiamaps.ferrostar.composeui.config | ||
|
||
import androidx.compose.ui.unit.DpSize | ||
import androidx.compose.ui.unit.dp | ||
|
||
sealed class CameraControlState { | ||
data object Hidden : CameraControlState() | ||
|
||
data class ShowRecenter(val updateCamera: () -> Unit) : CameraControlState() | ||
|
||
data class ShowRouteOverview(val updateCamera: () -> Unit) : CameraControlState() | ||
} | ||
|
||
data class VisualNavigationViewConfig( | ||
// Mute | ||
var showMute: Boolean = false, | ||
var onMute: (() -> Unit)? = null, | ||
|
||
// Zoom | ||
var showZoom: Boolean = false, | ||
var buttonSize: DpSize = DpSize(56.dp, 56.dp) | ||
var onZoomIn: (() -> Unit)? = null, | ||
var onZoomOut: (() -> Unit)? = null, | ||
) { | ||
companion object { | ||
fun Default() = VisualNavigationViewConfig(showMute = true, showZoom = true) | ||
} | ||
} | ||
|
||
/** Enables the mute button in the navigation view. */ | ||
fun VisualNavigationViewConfig.useMuteButton(): VisualNavigationViewConfig { | ||
showMute = true | ||
return this | ||
fun VisualNavigationViewConfig.useMuteButton(onMute: () -> Unit): VisualNavigationViewConfig { | ||
return copy(showMute = true, onMute = onMute) | ||
} | ||
|
||
/** Enables the zoom button in the navigation view. */ | ||
fun VisualNavigationViewConfig.useZoomButton(): VisualNavigationViewConfig { | ||
showZoom = true | ||
return this | ||
} | ||
|
||
/** Changes the size of navigation buttons. */ | ||
fun VisualNavigationViewConfig.buttonSize(size: DpSize): VisualNavigationViewConfig { | ||
buttonSize = size | ||
return this | ||
fun VisualNavigationViewConfig.useZoomButton( | ||
onZoomIn: () -> Unit, | ||
onZoomOut: () -> Unit | ||
): VisualNavigationViewConfig { | ||
return copy(showZoom = true, onZoomIn = onZoomIn, onZoomOut = onZoomOut) | ||
} |
9 changes: 9 additions & 0 deletions
9
...d/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/models/CameraControlState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.stadiamaps.ferrostar.composeui.models | ||
|
||
sealed class CameraControlState { | ||
data object Hidden : CameraControlState() | ||
|
||
data class ShowRecenter(val updateCamera: () -> Unit) : CameraControlState() | ||
|
||
data class ShowRouteOverview(val updateCamera: () -> Unit) : CameraControlState() | ||
} |
36 changes: 36 additions & 0 deletions
36
...omposeui/src/main/java/com/stadiamaps/ferrostar/composeui/models/NavigationViewMetrics.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.stadiamaps.ferrostar.composeui.models | ||
|
||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.DpSize | ||
import androidx.compose.ui.unit.dp | ||
|
||
data class NavigationViewMetrics( | ||
val progressViewSize: DpSize = DpSize(0.dp, 0.dp), | ||
val instructionsViewSize: DpSize = DpSize(0.dp, 0.dp), | ||
val buttonSize: DpSize, | ||
) { | ||
|
||
/** | ||
* Returns the MapView's safe insets. | ||
* | ||
* @param start Optional additional start padding. Default is 0.dp. | ||
* @param top Optional additional top padding. Default is instructionsViewSize.height. | ||
* @param end Optional additional end padding. Default is 0.dp. | ||
* @param bottom Optional additional bottom padding. Default is progressViewSize.height. | ||
* @return The calculated padding insets. | ||
*/ | ||
fun mapViewInsets( | ||
start: Dp = 0.dp, | ||
top: Dp = 0.dp, | ||
end: Dp = 0.dp, | ||
bottom: Dp = 0.dp, | ||
): PaddingValues { | ||
return PaddingValues( | ||
start = start, | ||
top = instructionsViewSize.height + top, | ||
end = end, | ||
bottom = progressViewSize.height + buttonSize.height + bottom, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...oid/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/theme/NavigationUITheme.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.stadiamaps.ferrostar.composeui.theme | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.unit.DpSize | ||
import androidx.compose.ui.unit.dp | ||
|
||
interface NavigationUITheme { | ||
@get:Composable val instructionRowTheme: InstructionRowTheme | ||
@get:Composable val roadNameViewTheme: RoadNameViewTheme | ||
@get:Composable val tripProgressViewTheme: TripProgressViewTheme | ||
@get:Composable val buttonSize: DpSize | ||
} | ||
|
||
object DefaultNavigationUITheme : NavigationUITheme { | ||
override val instructionRowTheme: InstructionRowTheme | ||
@Composable get() = DefaultInstructionRowTheme | ||
|
||
override val roadNameViewTheme: RoadNameViewTheme | ||
@Composable get() = DefaultRoadNameViewTheme | ||
|
||
override val tripProgressViewTheme: TripProgressViewTheme | ||
@Composable get() = DefaultTripProgressViewTheme | ||
|
||
override val buttonSize: DpSize | ||
@Composable get() = DpSize(56.dp, 56.dp) | ||
} |
2 changes: 1 addition & 1 deletion
2
...rostar/composeui/views/CurrentRoadView.kt → ...oseui/views/components/CurrentRoadView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ostar/composeui/views/TripProgressView.kt → ...seui/views/components/TripProgressView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...seui/views/controls/NavigationUIButton.kt → ...components/controls/NavigationUIButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../views/controls/NavigationUIZoomButton.kt → ...onents/controls/NavigationUIZoomButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...omposeui/views/gridviews/InnerGridView.kt → ...ews/components/gridviews/InnerGridView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.