Skip to content

Commit

Permalink
Merge branch 'main' into pr/323
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie committed Oct 31, 2024
2 parents 90db21d + 4b883ae commit fbd0016
Show file tree
Hide file tree
Showing 90 changed files with 914 additions and 408 deletions.
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "7b0bbbae90c41f848f90ac7b4df6c4f50068256d",
"version" : "1.17.5"
"revision" : "42a086182681cf661f5c47c9b7dc3931de18c6d7",
"version" : "1.17.6"
}
},
{
Expand All @@ -50,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/maplibre/swiftui-dsl",
"state" : {
"revision" : "c39688db3aac50b523ea062b286c584123022093",
"version" : "0.3.0"
"revision" : "a6e079ce382e7860bc9105a05534f967a2f9ef65",
"version" : "0.3.1"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let package = Package(
name: "FerrostarCore",
defaultLocalization: "en",
platforms: [
.iOS(.v15),
.iOS(.v16),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.stadiamaps.ferrostar.composeui.theme

import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle

/** Themes for progress view components */
interface RoadNameViewTheme {
/** The text style for the measurement/value. */
@get:Composable val textStyle: TextStyle
/** The background color for the view. */
@get:Composable val backgroundColor: Color
/** The border color for the view. */
@get:Composable val borderColor: Color
}

/**
* A default theme for the road name view.
*
* The text style comes from your material theme. The background properties are hard-coded based on
* the default polyline styling, as this doesn't have any clear analog in the material theme.
*/
object DefaultRoadNameViewTheme : RoadNameViewTheme {
override val textStyle: TextStyle
@Composable
get() =
MaterialTheme.typography.labelSmall.copy(color = MaterialTheme.colorScheme.inverseOnSurface)

override val backgroundColor: Color
@Composable get() = Color(0x35, 0x83, 0xdd)

override val borderColor: Color
@Composable get() = Color.White
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight

enum class ArrivalViewStyle {
/** A simple arrival view with only values. */
enum class TripProgressViewStyle {
/** A simple progress view with only values. */
SIMPLIFIED,
/** An arrival view with label captions in addition to values. */
/** An progress view with label captions in addition to values. */
INFORMATIONAL
}

/** Themes for arrival view components */
interface ArrivalViewTheme {
/** Themes for progress view components */
interface TripProgressViewTheme {
/** The text style for the step distance (or distance to step). */
@get:Composable val style: ArrivalViewStyle
@get:Composable val style: TripProgressViewStyle
/** The text style for the measurement/value. */
@get:Composable val measurementTextStyle: TextStyle
/** The text style for the secondary content (label caption). */
Expand All @@ -29,9 +29,9 @@ interface ArrivalViewTheme {
@get:Composable val backgroundColor: Color
}

object DefaultArrivalViewTheme : ArrivalViewTheme {
override val style: ArrivalViewStyle
@Composable get() = ArrivalViewStyle.SIMPLIFIED
object DefaultTripProgressViewTheme : TripProgressViewTheme {
override val style: TripProgressViewStyle
@Composable get() = TripProgressViewStyle.SIMPLIFIED

override val measurementTextStyle: TextStyle
@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.stadiamaps.ferrostar.composeui.views

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.stadiamaps.ferrostar.composeui.theme.DefaultRoadNameViewTheme
import com.stadiamaps.ferrostar.composeui.theme.RoadNameViewTheme

/**
* A view that displays the estimated arrival time, the remaining distance, and the remaining
* duration of a trip.
*
* @param currentRoadName The name of the current road.
* @param modifier The modifier to apply to this layout.
* @param theme The theme to use for this view.
* @param borderStroke The stroke to draw for the border (defaults to 1dp using the theme's
* borderColor).
* @param shape The shape of the view (defaults to a 50% rounded corner).
* @param paddingValues Padding to apply around the name label to increase the shape size (defaults
* to 12dp in all directions).
*/
@Composable
fun CurrentRoadNameView(
currentRoadName: String,
modifier: Modifier = Modifier,
theme: RoadNameViewTheme = DefaultRoadNameViewTheme,
borderStroke: BorderStroke = BorderStroke(1.dp, theme.borderColor),
shape: Shape = RoundedCornerShape(50),
paddingValues: PaddingValues = PaddingValues(12.dp),
) {
Box(
modifier =
modifier
.shadow(12.dp, shape = shape)
.background(color = theme.backgroundColor, shape = shape)
.border(borderStroke, shape = shape)
.padding(paddingValues = paddingValues)) {
Text(currentRoadName, style = theme.textStyle)
}
}

@Preview
@Composable
fun CurrentRoadNameViewPreview() {
CurrentRoadNameView("Sesame Street")
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import com.stadiamaps.ferrostar.composeui.formatting.DurationFormatter
import com.stadiamaps.ferrostar.composeui.formatting.EstimatedArrivalDateTimeFormatter
import com.stadiamaps.ferrostar.composeui.formatting.LocalizedDistanceFormatter
import com.stadiamaps.ferrostar.composeui.formatting.LocalizedDurationFormatter
import com.stadiamaps.ferrostar.composeui.theme.ArrivalViewStyle
import com.stadiamaps.ferrostar.composeui.theme.ArrivalViewTheme
import com.stadiamaps.ferrostar.composeui.theme.DefaultArrivalViewTheme
import com.stadiamaps.ferrostar.composeui.theme.DefaultTripProgressViewTheme
import com.stadiamaps.ferrostar.composeui.theme.TripProgressViewStyle
import com.stadiamaps.ferrostar.composeui.theme.TripProgressViewTheme
import com.stadiamaps.ferrostar.core.extensions.estimatedArrivalTime
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
Expand All @@ -60,9 +60,9 @@ import uniffi.ferrostar.TripProgress
* button is not displayed.
*/
@Composable
fun ArrivalView(
fun TripProgressView(
modifier: Modifier = Modifier,
theme: ArrivalViewTheme = DefaultArrivalViewTheme,
theme: TripProgressViewTheme = DefaultTripProgressViewTheme,
estimatedArrivalFormatter: DateTimeFormatter = EstimatedArrivalDateTimeFormatter(),
distanceFormatter: DistanceFormatter = LocalizedDistanceFormatter(),
durationFormatter: DurationFormatter = LocalizedDurationFormatter(),
Expand All @@ -72,74 +72,79 @@ fun ArrivalView(
onTapExit: (() -> Unit)? = null
) {
Box(modifier) {
Row(
modifier =
Modifier.shadow(12.dp, shape = RoundedCornerShape(50))
.background(color = theme.backgroundColor, shape = RoundedCornerShape(50))
.padding(start = 32.dp, end = 12.dp, top = 12.dp, bottom = 12.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically) {
Column(
modifier = Modifier.weight(1f), horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text =
estimatedArrivalFormatter.format(
progress.estimatedArrivalTime(fromDate, timeZone)),
style = theme.measurementTextStyle)
if (theme.style == ArrivalViewStyle.INFORMATIONAL) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Row(
modifier =
Modifier.shadow(12.dp, shape = RoundedCornerShape(50))
.background(color = theme.backgroundColor, shape = RoundedCornerShape(50))
.padding(start = 12.dp, end = 12.dp, top = 12.dp, bottom = 12.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically) {
Column(
modifier = Modifier.weight(1f),
horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = stringResource(id = R.string.arrival),
style = theme.secondaryTextStyle)
text =
estimatedArrivalFormatter.format(
progress.estimatedArrivalTime(fromDate, timeZone)),
style = theme.measurementTextStyle)
if (theme.style == TripProgressViewStyle.INFORMATIONAL) {
Text(
text = stringResource(id = R.string.arrival),
style = theme.secondaryTextStyle)
}
}
}

Column(
modifier = Modifier.weight(1f), horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = durationFormatter.format(progress.durationRemaining),
style = theme.measurementTextStyle)
if (theme.style == ArrivalViewStyle.INFORMATIONAL) {

Column(
modifier = Modifier.weight(1f),
horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = stringResource(id = R.string.duration),
style = theme.secondaryTextStyle)
text = durationFormatter.format(progress.durationRemaining),
style = theme.measurementTextStyle)
if (theme.style == TripProgressViewStyle.INFORMATIONAL) {
Text(
text = stringResource(id = R.string.duration),
style = theme.secondaryTextStyle)
}
}
}

Column(
modifier = Modifier.weight(1f), horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = distanceFormatter.format(progress.distanceRemaining),
style = theme.measurementTextStyle)
if (theme.style == ArrivalViewStyle.INFORMATIONAL) {

Column(
modifier = Modifier.weight(1f),
horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = stringResource(id = R.string.distance),
style = theme.secondaryTextStyle)
}
}

// The optional exit button
if (onTapExit != null) {
Button(
onClick = { onTapExit() },
modifier = Modifier.size(50.dp),
shape = CircleShape,
colors =
ButtonDefaults.buttonColors(containerColor = theme.exitButtonBackgroundColor),
contentPadding = PaddingValues(0.dp)) {
Icon(
imageVector = Icons.Filled.Close,
contentDescription = stringResource(id = R.string.end_navigation),
tint = theme.exitIconColor)
text = distanceFormatter.format(progress.distanceRemaining),
style = theme.measurementTextStyle)
if (theme.style == TripProgressViewStyle.INFORMATIONAL) {
Text(
text = stringResource(id = R.string.distance),
style = theme.secondaryTextStyle)
}
}

// The optional exit button
if (onTapExit != null) {
Button(
onClick = { onTapExit() },
modifier = Modifier.size(50.dp),
shape = CircleShape,
colors =
ButtonDefaults.buttonColors(containerColor = theme.exitButtonBackgroundColor),
contentPadding = PaddingValues(0.dp)) {
Icon(
imageVector = Icons.Filled.Close,
contentDescription = stringResource(id = R.string.end_navigation),
tint = theme.exitIconColor)
}
}
}
}
}
}
}

@Preview
@Composable
fun ArrivalViewPreview() {
ArrivalView(
fun ProgressViewPreview() {
TripProgressView(
progress =
TripProgress(
distanceRemaining = 124252.0,
Expand All @@ -151,15 +156,15 @@ fun ArrivalViewPreview() {

@Preview
@Composable
fun ArrivalViewInformationalPreview() {
fun ProgressViewInformationalPreview() {
val progress =
TripProgress(
distanceRemaining = 1000.0, durationRemaining = 1000.0, distanceToNextManeuver = 500.0)

val theme =
object : ArrivalViewTheme {
override val style: ArrivalViewStyle
@Composable get() = ArrivalViewStyle.INFORMATIONAL
object : TripProgressViewTheme {
override val style: TripProgressViewStyle
@Composable get() = TripProgressViewStyle.INFORMATIONAL

override val measurementTextStyle: TextStyle
@Composable
Expand All @@ -183,7 +188,7 @@ fun ArrivalViewInformationalPreview() {
@Composable get() = MaterialTheme.colorScheme.background
}

ArrivalView(
TripProgressView(
progress = progress,
theme = theme,
fromDate = Instant.fromEpochSeconds(1720283624),
Expand All @@ -192,14 +197,14 @@ fun ArrivalViewInformationalPreview() {

@Preview
@Composable
fun ArrivalViewWithExitPreview() {
fun ProgressViewWithExitPreview() {
val progress =
TripProgress(
distanceRemaining = 2442522.0,
durationRemaining = 52012.0,
distanceToNextManeuver = 500.0)

ArrivalView(
TripProgressView(
progress = progress,
fromDate = Instant.fromEpochSeconds(1720283624),
timeZone = TimeZone.of("America/Los_Angeles"),
Expand All @@ -208,7 +213,7 @@ fun ArrivalViewWithExitPreview() {

@Preview(locale = "de_DE")
@Composable
fun ArrivalView24HourPreview() {
fun ProgressView24HourPreview() {
val estimatedArrivalFormatter =
EstimatedArrivalDateTimeFormatter(localeOverride = ULocale.GERMANY)

Expand All @@ -218,7 +223,7 @@ fun ArrivalView24HourPreview() {
durationRemaining = 52012.0,
distanceToNextManeuver = 500.0)

ArrivalView(
TripProgressView(
progress = progress,
estimatedArrivalFormatter = estimatedArrivalFormatter,
fromDate = Instant.fromEpochSeconds(1720283624),
Expand Down
Loading

0 comments on commit fbd0016

Please sign in to comment.