Skip to content

Commit

Permalink
Handle 0 items in stopSequence case.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz committed Oct 17, 2024
1 parent 3d4e09f commit 09f1054
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
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.res.stringResource
Expand Down Expand Up @@ -61,7 +57,6 @@ fun TimeTableScreen(
}
} else if (timeTableState.journeyList.isNotEmpty()) {
items(timeTableState.journeyList) { journey ->
var isFirstTime by rememberSaveable { mutableStateOf(true) }

AnimatedVisibility(
visible = expandedJourneyId == journey.journeyId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.ksharma.krail.trip_planner.ui.timetable.business

import androidx.compose.foundation.layout.size
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import timber.log.Timber
Expand Down Expand Up @@ -32,8 +33,10 @@ internal fun TripResponse.buildJourneyList(): ImmutableList<TimeTableState.Journ
val legs = journey.legs?.filter {
it.transportation != null && it.stopSequence != null
}
// Sometimes there are no legs, so we need to handle that case, can happen when, the train is Now.
val totalStops = legs?.sumOf { leg -> leg.stopSequence?.size ?: 0 } ?: 0

if (legs != null && originTimeUTC != null && arrivalTimeUTC != null && firstPublicTransportLeg != null) {
if (legs != null && originTimeUTC != null && arrivalTimeUTC != null && firstPublicTransportLeg != null && totalStops > 0) {
TimeTableState.JourneyCardInfo(
timeText = originTimeUTC.let {
Timber.d("originTime: $it :- ${calculateTimeDifferenceFromNow(utcDateString = it)}")
Expand Down

0 comments on commit 09f1054

Please sign in to comment.