From d2c8b79546fa738b6a08899c575fe80061d18f71 Mon Sep 17 00:00:00 2001 From: Karan Sharma <55722391+ksharma-xyz@users.noreply.github.com> Date: Thu, 24 Oct 2024 00:18:27 +1100 Subject: [PATCH] Show hide stops by clicking on it --- .../trip/planner/ui/components/JourneyCard.kt | 3 -- .../trip/planner/ui/components/LegView.kt | 29 +++++++++++++++---- .../ui/src/main/res/values/strings.xml | 4 +++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/feature/trip-planner/ui/src/main/kotlin/xyz/ksharma/krail/trip/planner/ui/components/JourneyCard.kt b/feature/trip-planner/ui/src/main/kotlin/xyz/ksharma/krail/trip/planner/ui/components/JourneyCard.kt index 0f139976..9c2c75db 100644 --- a/feature/trip-planner/ui/src/main/kotlin/xyz/ksharma/krail/trip/planner/ui/components/JourneyCard.kt +++ b/feature/trip-planner/ui/src/main/kotlin/xyz/ksharma/krail/trip/planner/ui/components/JourneyCard.kt @@ -142,7 +142,6 @@ fun JourneyCard( ) else -> JourneyCardContent( - isExpanded = cardState == JourneyCardState.EXPANDED, timeToDeparture = timeToDeparture, themeColor = themeColor, platformNumber = platformNumber, @@ -157,7 +156,6 @@ fun JourneyCard( @OptIn(ExperimentalLayoutApi::class) @Composable fun ColumnScope.JourneyCardContent( - isExpanded: Boolean, timeToDeparture: String, themeColor: Color, platformNumber: Char?, @@ -285,7 +283,6 @@ fun ColumnScope.JourneyCardContent( routeText = leg.displayText, transportModeLine = leg.transportModeLine, stops = leg.stops, - isExpanded = isExpanded, modifier = Modifier, ) } diff --git a/feature/trip-planner/ui/src/main/kotlin/xyz/ksharma/krail/trip/planner/ui/components/LegView.kt b/feature/trip-planner/ui/src/main/kotlin/xyz/ksharma/krail/trip/planner/ui/components/LegView.kt index 5dc12749..c9895f80 100644 --- a/feature/trip-planner/ui/src/main/kotlin/xyz/ksharma/krail/trip/planner/ui/components/LegView.kt +++ b/feature/trip-planner/ui/src/main/kotlin/xyz/ksharma/krail/trip/planner/ui/components/LegView.kt @@ -2,6 +2,8 @@ package xyz.ksharma.krail.trip.planner.ui.components import androidx.compose.foundation.Image import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -15,13 +17,20 @@ 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.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.Role import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewLightDark @@ -43,7 +52,6 @@ fun LegView( routeText: String, // AVC via XYZ transportModeLine: TransportModeLine, stops: ImmutableList, - isExpanded: Boolean = false, modifier: Modifier = Modifier, ) { val circleRadius = 8.dp @@ -51,7 +59,9 @@ fun LegView( val density = LocalDensity.current // todo can be reusable logic for consistent icon size val iconSize = with(density) { 14.sp.toDp() } - val timelineColor = remember(transportModeLine) { transportModeLine.lineColorCode.hexToComposeColor() } + val timelineColor = + remember(transportModeLine) { transportModeLine.lineColorCode.hexToComposeColor() } + var displayNonProminentStops by rememberSaveable { mutableStateOf(false) } Column( modifier = modifier @@ -118,11 +128,21 @@ fun LegView( color = timelineColor, strokeWidth = strokeWidth, ) + .clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = null, + onClick = { displayNonProminentStops = !displayNonProminentStops }, + role = Role.Button, + ) .padding(start = 16.dp, top = 12.dp), ) { if (stops.size > 2) { + val context = LocalContext.current StopsRow( - stops = "${stops.size - 2} stops", + // Need to pass count twice - https://developer.android.com/guide/topics/resources/string-resource#Plurals + stops = if (displayNonProminentStops) "Hide stops" else context.resources.getQuantityString( + R.plurals.stops, stops.size - 2, stops.size - 2 + ), line = transportModeLine, ) } else { @@ -135,8 +155,7 @@ fun LegView( } } - if (isExpanded) { - + if (displayNonProminentStops) { stops.drop(1).dropLast(1).forEach { stop -> StopInfo( time = stop.time, diff --git a/feature/trip-planner/ui/src/main/res/values/strings.xml b/feature/trip-planner/ui/src/main/res/values/strings.xml index 4d1884e8..fee50701 100644 --- a/feature/trip-planner/ui/src/main/res/values/strings.xml +++ b/feature/trip-planner/ui/src/main/res/values/strings.xml @@ -4,4 +4,8 @@ From To Time Table + + Show %d stop + Show %d stops +