Skip to content

Commit

Permalink
Add logic to build platofrm text
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz committed Oct 21, 2024
1 parent ea999aa commit 82b675c
Showing 1 changed file with 36 additions and 22 deletions.
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 @@ -51,27 +52,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 @@ -87,15 +90,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 @@ -216,6 +221,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

0 comments on commit 82b675c

Please sign in to comment.