Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Display non prominent stops if present #246

Merged
merged 1 commit into from
Oct 24, 2024
Merged
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 @@ -96,9 +96,10 @@ fun LegView(
}
Spacer(modifier = Modifier.height(12.dp))
Column(modifier = Modifier.fillMaxWidth()) {
ProminentStopInfo(
StopInfo(
time = stops.first().time,
name = stops.first().name,
isProminent = true,
modifier = Modifier
.timeLineTop(
color = transportModeLine.transportMode.colorCode.hexToComposeColor(),
Expand All @@ -114,55 +115,75 @@ fun LegView(
color = transportModeLine.transportMode.colorCode.hexToComposeColor(),
strokeWidth = strokeWidth,
)
.padding(start = 16.dp),
.padding(start = 16.dp, top = 12.dp),
) {
if (stops.size > 2) {
StopsRow(
stops = "${stops.size - 2} stops",
line = transportModeLine,
modifier = Modifier.padding(vertical = 8.dp),
)
} else {
TransportModeInfo(
letter = transportModeLine.transportMode.name.first(),
backgroundColor = transportModeLine.transportMode.colorCode.hexToComposeColor(),
badgeText = transportModeLine.lineName,
badgeColor = transportModeLine.lineColorCode.hexToComposeColor(),
modifier = Modifier.padding(vertical = 8.dp),
)
}
}

ProminentStopInfo(
stops.drop(1).dropLast(1).forEach { stop ->
StopInfo(
time = stop.time,
name = stop.name,
isProminent = false,
modifier = Modifier
.timeLineCenterWithStop(
color = transportModeLine.transportMode.colorCode.hexToComposeColor(),
strokeWidth = strokeWidth,
circleRadius = circleRadius,
)
.timeLineTop(
color = transportModeLine.transportMode.colorCode.hexToComposeColor(),
strokeWidth = strokeWidth,
circleRadius = circleRadius,
)
.padding(start = 16.dp, top = 12.dp),
)
}

StopInfo(
time = stops.last().time,
name = stops.last().name,
isProminent = true,
modifier = Modifier
.timeLineBottom(
color = transportModeLine.transportMode.colorCode.hexToComposeColor(),
strokeWidth = strokeWidth,
circleRadius = circleRadius,
)
.padding(start = 16.dp),
.padding(start = 16.dp, top = 12.dp),
)
}
}
}

@Composable
fun ProminentStopInfo(
fun StopInfo(
time: String,
name: String,
isProminent: Boolean,
modifier: Modifier = Modifier,
) {
Column(modifier = modifier) {
Text(
text = time,
style = KrailTheme.typography.bodyMedium,
style = if (isProminent) KrailTheme.typography.bodyMedium else KrailTheme.typography.bodySmall,
color = KrailTheme.colors.onSurface,
)
Text(
text = name,
style = KrailTheme.typography.titleSmall,
style = if (isProminent) KrailTheme.typography.titleSmall else KrailTheme.typography.bodySmall,
color = KrailTheme.colors.onSurface,
)
}
Expand Down Expand Up @@ -279,9 +300,10 @@ private fun PreviewStopsRow() {
@Composable
private fun PreviewProminentStopInfo() {
KrailTheme {
ProminentStopInfo(
StopInfo(
time = "12:00",
name = "XYZ Station, Platform 1",
isProminent = true,
modifier = Modifier.background(KrailTheme.colors.background),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ internal fun Modifier.timeLineCenter(color: Color, strokeWidth: Dp): Modifier {
}
}

internal fun Modifier.timeLineCenterWithStop(color: Color, strokeWidth: Dp, circleRadius: Dp): Modifier {
return this.drawBehind {
drawLine(
color = color,
start = Offset(x = 0f, y = 0f),
end = Offset(x = 0f, y = this.size.height),
strokeWidth = strokeWidth.toPx(),
cap = StrokeCap.Round,
)
drawCircle(
color = color,
radius = circleRadius.toPx(),
center = Offset(0f, this.size.height / 2),
)
}
}

/**
* Draws a vertical line and a circle at the bottom start of the composable,
* representing the bottom end of a timeline element.
Expand Down