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

Customize platform text based on transport mode #235

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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 @@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand Down Expand Up @@ -52,27 +53,29 @@ fun JourneyDetailCard(
// todo can be reusable logic for consistent icon size
val iconSize = with(density) { 14.sp.toDp() }

val firstTransportLeg = remember(legList) {
legList.filterIsInstance<TimeTableState.JourneyCardInfo.Leg.TransportLeg>().first()
}

val transportLegColors = remember(legList) {
legList.filterIsInstance<TimeTableState.JourneyCardInfo.Leg.TransportLeg>()
.map { it.transportModeLine.transportMode.colorCode.hexToComposeColor() }
}

val borderColors = if (transportLegColors.size >= 2) {
transportLegColors
} else {
listOf(transportLegColors.first(), transportLegColors.first())
}

Column(
modifier = modifier
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
.background(KrailTheme.colors.surface)
.border(
width = 2.dp,
brush = Brush.verticalGradient(
colors = if (legList.size >= 2) {
legList
.filterIsInstance<TimeTableState.JourneyCardInfo.Leg.TransportLeg>()
.map {
it.transportModeLine.transportMode.colorCode.hexToComposeColor()
}
} else {
val color =
legList
.filterIsInstance<TimeTableState.JourneyCardInfo.Leg.TransportLeg>()
.first().transportModeLine.transportMode.colorCode.hexToComposeColor()
listOf(color, color)
}),
brush = Brush.verticalGradient(colors = borderColors),
shape = RoundedCornerShape(12.dp)
)
.padding(vertical = 12.dp)
Expand All @@ -88,15 +91,17 @@ fun JourneyDetailCard(
Text(
text = timeToDeparture,
style = KrailTheme.typography.titleLarge,
color = legList.filterIsInstance<TimeTableState.JourneyCardInfo.Leg.TransportLeg>()
.first().transportModeLine.transportMode.colorCode.hexToComposeColor()
)
Text(
text = "Platform $platformNumber",
style = KrailTheme.typography.titleLarge,
color = legList.filterIsInstance<TimeTableState.JourneyCardInfo.Leg.TransportLeg>()
.first().transportModeLine.transportMode.colorCode.hexToComposeColor()
color = firstTransportLeg.transportModeLine.transportMode.colorCode.hexToComposeColor()
)

firstTransportLeg.transportModeLine.transportMode.buildPlatformText(platformNumber)
?.let { platformText ->
Text(
text = platformText,
style = KrailTheme.typography.titleLarge,
color = firstTransportLeg.transportModeLine.transportMode.colorCode.hexToComposeColor()
)
}
}

FlowRow(
Expand Down Expand Up @@ -217,6 +222,15 @@ fun JourneyDetailCard(
}
}

private fun TransportMode.buildPlatformText(platformNumber: Char): String? {
return when (this) {
is TransportMode.Train, is TransportMode.Metro -> "Platform $platformNumber"
is TransportMode.Bus -> "Stand $platformNumber"
is TransportMode.Ferry -> "Wharf $platformNumber"
else -> null
}
}

@Preview(showBackground = true)
@Composable
private fun PreviewJourneyDetailCard() {
Expand Down