Skip to content

Commit

Permalink
Show hide stops by clicking on it
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz committed Oct 24, 2024
1 parent c822492 commit 5b3e4de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ fun JourneyCard(
)

else -> JourneyCardContent(
isExpanded = cardState == JourneyCardState.EXPANDED,
timeToDeparture = timeToDeparture,
themeColor = themeColor,
platformNumber = platformNumber,
Expand All @@ -157,7 +156,6 @@ fun JourneyCard(
@OptIn(ExperimentalLayoutApi::class)
@Composable
fun ColumnScope.JourneyCardContent(
isExpanded: Boolean,
timeToDeparture: String,
themeColor: Color,
platformNumber: Char?,
Expand Down Expand Up @@ -285,7 +283,6 @@ fun ColumnScope.JourneyCardContent(
routeText = leg.displayText,
transportModeLine = leg.transportModeLine,
stops = leg.stops,
isExpanded = isExpanded,
modifier = Modifier,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -43,15 +52,16 @@ fun LegView(
routeText: String, // AVC via XYZ
transportModeLine: TransportModeLine,
stops: ImmutableList<TimeTableState.JourneyCardInfo.Stop>,
isExpanded: Boolean = false,
modifier: Modifier = Modifier,
) {
val circleRadius = 8.dp
val strokeWidth = 4.dp
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
Expand Down Expand Up @@ -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 {
Expand All @@ -135,8 +155,7 @@ fun LegView(
}
}

if (isExpanded) {

if (displayNonProminentStops) {
stops.drop(1).dropLast(1).forEach { stop ->
StopInfo(
time = stop.time,
Expand Down
4 changes: 4 additions & 0 deletions feature/trip-planner/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<string name="from_text_field_placeholder">From</string>
<string name="to_text_field_placeholder">To</string>
<string name="time_table_screen_title">Time Table</string>
<plurals name="stops">
<item quantity="one">Show %d stop</item>
<item quantity="other">Show %d stops</item>
</plurals>
</resources>

0 comments on commit 5b3e4de

Please sign in to comment.