Skip to content

Commit

Permalink
[23022]
Browse files Browse the repository at this point in the history
- [TripKitUI] update RoutingResponse to change handling of trip group and trip list for resolving the segment list
- [TripKit] update Trip to change TripSegment to mutable list and list default value
- [TripKit] update TripSegmentListResolver to change segmentList handling and update
  • Loading branch information
MichaelFlexAI committed Feb 9, 2025
1 parent 126838e commit 6abc1a3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TripSegmentListResolver(private val resources: Resources) {
}

fun resolve() {
if (!CollectionUtils.isEmpty(tripSegmentList)) {
if (tripSegmentList?.isNotEmpty() == true) {
putDepartureSegment()
putArrivalSegment()

Expand Down Expand Up @@ -122,31 +122,31 @@ class TripSegmentListResolver(private val resources: Resources) {
private fun fillSegmentIdentifiers() {
segmentIdGenerator.set(0L)
var newSegmentId: Long
for (segment in tripSegmentList!!) {
tripSegmentList?.forEach { segment ->
newSegmentId = segmentIdGenerator.incrementAndGet()
segment!!.segmentId = newSegmentId
segment.segmentId = newSegmentId
}
}

/**
* Puts a Departure segment before head
*/
private fun putArrivalSegment() {
val lastSegment = tripSegmentList!![tripSegmentList!!.size - 1]
val lastSegment = tripSegmentList?.last()
if (lastSegment != null) {
val arrivalSegment = createArrivalSegment(lastSegment)
tripSegmentList!!.add(arrivalSegment)
tripSegmentList?.add(arrivalSegment)
}
}

/**
* Puts an Arrival segment after tail
*/
private fun putDepartureSegment() {
val firstSegment = tripSegmentList!![0]
val firstSegment = tripSegmentList?.first()
if (firstSegment != null) {
val departureSegment = createDepartureSegment(firstSegment)
tripSegmentList!!.add(0, departureSegment)
tripSegmentList?.add(0, departureSegment)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ class RoutingResponse {
}

private fun resolveTripGroupList(tripGroupList: ArrayList<TripGroup>?) {
for (tripGroup in tripGroupList.orEmpty()) {
if (CollectionUtils.isNotEmpty(tripGroup.trips)) {
for (trip in tripGroup.trips.orEmpty()) {
mTripSegmentListResolver
?.setOrigin(trip.from)
?.setDestination(trip.to)
?.setTripSegmentList(trip.segmentList.toMutableList())
?.resolve()
}
tripGroupList?.forEach { tripGroup ->
tripGroup.trips?.forEach { trip ->
mTripSegmentListResolver
?.setOrigin(trip.from)
?.setDestination(trip.to)
?.setTripSegmentList(trip.segmentList)
?.resolve()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Trip : ITimeRange {
var tripId: Long = 0
@Transient var group: TripGroup? = null
var isFavourite: Boolean = false
var segmentList: List<TripSegment> = arrayListOf()
var segmentList: MutableList<TripSegment> = mutableListOf()
set(segments) {
field = segments
field.forEach { it.trip = this }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.skedgo.tripkit.a2brouting
import android.content.res.Resources
import com.google.gson.Gson
import com.skedgo.TripKit
import com.skedgo.rxtry.printThrowableStackTrace
import com.skedgo.tripkit.RoutingUserError
import com.skedgo.tripkit.extensions.buildUrlWithQueryParams
import com.skedgo.tripkit.routing.RoutingResponse
Expand Down Expand Up @@ -71,6 +72,7 @@ class FailoverA2bRoutingApi(
groups
}
.onErrorResumeNext { error: Throwable ->
error.printThrowableStackTrace()
if (error is RoutingUserError) Maybe.error(error) else Maybe.empty()
}
.toObservable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ internal object RouteContract {
const val COL_TRIP_ID: String = "tripId"
const val COL_JSON: String = "json"
const val TABLE_SEGMENTS: String = "segments"
const val SELECT_SEGMENTS_ALL: String = "select * from " + TABLE_SEGMENTS
const val SELECT_SEGMENTS: String = "select * from " + TABLE_SEGMENTS + " where tripId = ?"
const val TABLE_TRIPS: String = "trips"
const val SELECT_TRIPS_ALL: String = "select * from " + TABLE_TRIPS
const val SELECT_TRIPS: String =
"select * from " + TABLE_TRIPS + " where " + COL_GROUP_ID + " = ?"
const val TABLE_TRIP_GROUPS: String = "tripGroups"
Expand Down

0 comments on commit 6abc1a3

Please sign in to comment.