Skip to content

Commit

Permalink
Merge pull request #491 from skedgo/task/23022-tripkitui-refactor-phase2
Browse files Browse the repository at this point in the history
[23022] TripKitUI refactor phase2
  • Loading branch information
MichaelReyes authored Feb 25, 2025
2 parents fdd9a96 + df97d0c commit f9256c5
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 73 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.skedgo.tripkit.common.agenda

/**
* Signifies a class is able to fetch timetable information
*/
interface IRealTimeElement {
var startStopCode: String?
var endStopCode: String?
val serviceTripId: String?
val operator: String?
val startTimeInSeconds: Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ScheduledStop : Location {
var services: String? = null

@SerializedName("children")
var children: ArrayList<ScheduledStop>? = null
var children: List<ScheduledStop>? = null

@SerializedName("shortName")
var shortName: String? = null
Expand Down Expand Up @@ -105,7 +105,7 @@ class ScheduledStop : Location {

val embarkationStopCode: List<String>
get() {
val list = ArrayList<String?>()
val list = mutableListOf<String?>()
list.add(this.code)
return list.filterNotNull()
}
Expand Down
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 @@ -69,16 +69,16 @@ class RoutingResponse {
if (CollectionUtils.isNotEmpty(alerts)) {
alertCache = HashMap(alerts!!.size)
for (alert in alerts) {
alertCache!![alert!!.remoteHashCode()] = alert
alertCache?.put(alert.remoteHashCode(), alert)
}
}
for (tripGroup in tripGroups!!) {
val trips: ArrayList<Trip>? = tripGroup!!.trips
val trips: ArrayList<Trip>? = tripGroup.trips
if (CollectionUtils.isEmpty(trips)) {
continue
}
for (trip in trips!!) {
trip!!.group = tripGroup
trip.group = tripGroup

val rawSegments: ArrayList<JsonObject>? = trip.rawSegmentList
trip.rawSegmentList = null
Expand Down 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)
?.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: ArrayList<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 @@ -119,7 +119,7 @@ class TripSegment : IRealTimeElement, ITimeRange {
var frequency: Int = 0

@SerializedName("serviceTripID")
private var mServiceTripId: String? = null
override var serviceTripId: String? = null

@SerializedName("serviceName")
var serviceName: String? = null
Expand All @@ -132,12 +132,14 @@ class TripSegment : IRealTimeElement, ITimeRange {

@SerializedName("serviceOperator")
var serviceOperator: String? = null
override val operator: String?
get() = serviceOperator

@SerializedName("stopCode")
private var mStartStopCode: String? = null
override var startStopCode: String? = null

@SerializedName("endStopCode")
private var mEndStopCode: String? = null
override var endStopCode: String? = null

@SerializedName("streets")
private var mStreets: ArrayList<Street>? = null
Expand Down Expand Up @@ -191,9 +193,8 @@ class TripSegment : IRealTimeElement, ITimeRange {
return millis
}

override fun getStartTimeInSeconds(): Long {
return startTimeInSecs
}
override val startTimeInSeconds: Long
get() = startTimeInSecs

override var endTimeInSecs: Long = 0
get() {
Expand Down Expand Up @@ -344,27 +345,6 @@ class TripSegment : IRealTimeElement, ITimeRange {
this.isFrequencyBased = isFrequencyBased
}

override fun getStartStopCode(): String? = mStartStopCode

override fun setStartStopCode(startStopCode: String?) {
mStartStopCode = startStopCode
}

override fun getEndStopCode(): String? = mEndStopCode

override fun setEndStopCode(endStopCode: String?) {
mEndStopCode = endStopCode
}

fun setServiceTripId(id: String?) {
mServiceTripId = id
}
override fun getServiceTripId(): String? = mServiceTripId

override fun getOperator(): String {
return serviceOperator.orEmpty()
}

val wheelchairFriendliness: Int
get() = Math.round(metresSafe / metres.toFloat() * 100)

Expand All @@ -374,8 +354,8 @@ class TripSegment : IRealTimeElement, ITimeRange {
val pairIdentifier: String
get() = String.format(
StyleManager.FORMAT_PAIR_IDENTIFIER,
mStartStopCode,
mEndStopCode
startStopCode,
endStopCode
)

val isStationary: Boolean
Expand Down Expand Up @@ -502,7 +482,7 @@ class TripSegment : IRealTimeElement, ITimeRange {
)

fun hasTimeTable(): Boolean {
return getType() == SCHEDULED && mServiceTripId != null && !(isContinuation || isPlane)
return getType() == SCHEDULED && serviceTripId != null && !(isContinuation || isPlane)
}


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 f9256c5

Please sign in to comment.