Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/gradle/ktorClientCore-2.3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaSimon authored Mar 22, 2024
2 parents 9de2260 + 73e8a4d commit a489b74
Show file tree
Hide file tree
Showing 14 changed files with 368 additions and 32 deletions.
3 changes: 2 additions & 1 deletion iosApp/iosApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ struct ContentView: View {
nearbyFetcher: nearbyFetcher,
scheduleFetcher: scheduleFetcher,
predictionsFetcher: predictionsFetcher,
viewportProvider: viewportProvider
viewportProvider: viewportProvider,
alertsFetcher: alertsFetcher
)
}
}
Expand Down
2 changes: 2 additions & 0 deletions iosApp/iosApp/Fetchers/NearbyFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ class NearbyFetcher: ObservableObject {
func withRealtimeInfo(
schedules: ScheduleResponse?,
predictions: PredictionsStreamDataResponse?,
alerts: AlertsStreamDataResponse?,
filterAtTime: Instant
) -> [StopAssociatedRoute]? {
guard let loadedLocation else { return nil }
return nearbyByRouteAndStop?.withRealtimeInfo(
sortByDistanceFrom: .init(longitude: loadedLocation.longitude, latitude: loadedLocation.latitude),
schedules: schedules,
predictions: predictions,
alerts: alerts,
filterAtTime: filterAtTime
)
}
Expand Down
15 changes: 15 additions & 0 deletions iosApp/iosApp/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
},
"Couldn't load nearby transit, unable to parse response" : {

},
"Detour" : {

},
"Failed to load alerts, could not connect to the server" : {

Expand Down Expand Up @@ -54,12 +57,24 @@
},
"No results found" : {

},
"No Service" : {

},
"Routes" : {

},
"Shuttle" : {

},
"Stop Closed" : {

},
"Stops" : {

},
"Suspension" : {

}
},
"version" : "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ struct NearbyStopRoutePatternView: View {
case loading
case none
case some([TripWithFormat])
case noService(shared.Alert)

static func from(upcomingTrips: [UpcomingTrip]?, now: Instant) -> Self {
static func from(upcomingTrips: [UpcomingTrip]?, alertsHere: [shared.Alert]?, now: Instant) -> Self {
guard let upcomingTrips else { return .loading }
let tripsToShow = upcomingTrips
.map { TripWithFormat($0, now: now) }
.filter { !$0.isHidden() }
.prefix(2)
if tripsToShow.isEmpty {
if let alert = alertsHere?.first {
return .noService(alert)
}
return .none
}
return .some(Array(tripsToShow))
Expand All @@ -56,6 +60,8 @@ struct NearbyStopRoutePatternView: View {
ForEach(predictions) { prediction in
UpcomingTripView(prediction: .some(prediction.format))
}
case let .noService(alert):
UpcomingTripView(prediction: .noService(alert.effect))
case .none:
UpcomingTripView(prediction: .none)
case .loading:
Expand All @@ -64,3 +70,23 @@ struct NearbyStopRoutePatternView: View {
}
}
}

struct NearbyStopRoutePatternView_Previews: PreviewProvider {
static var previews: some View {
VStack(alignment: .trailing) {
let now = Date.now
NearbyStopRoutePatternView(headsign: "Some", predictions: .some([
.init(.init(prediction: ObjectCollectionBuilder.Single.shared.prediction { prediction in
prediction.departureTime = now.addingTimeInterval(5 * 60).toKotlinInstant()
}), now: now.toKotlinInstant()),
]))
NearbyStopRoutePatternView(headsign: "None", predictions: .none)
NearbyStopRoutePatternView(headsign: "Loading", predictions: .loading)
NearbyStopRoutePatternView(headsign: "No Service", predictions: .noService(
ObjectCollectionBuilder.Single.shared.alert { alert in
alert.effect = .suspension
}
))
}
}
}
3 changes: 2 additions & 1 deletion iosApp/iosApp/Pages/NearbyTransit/NearbyStopView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ struct NearbyStopView: View {
ForEach(patternsAtStop.patternsByHeadsign, id: \.headsign) { patternsByHeadsign in
NearbyStopRoutePatternView(
headsign: patternsByHeadsign.headsign,
predictions: .from(upcomingTrips: patternsByHeadsign.upcomingTrips, now: now)
predictions: .from(upcomingTrips: patternsByHeadsign.upcomingTrips,
alertsHere: patternsByHeadsign.alertsHere, now: now)
)
}
}
Expand Down
8 changes: 6 additions & 2 deletions iosApp/iosApp/Pages/NearbyTransit/NearbyTransitPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct NearbyTransitPageView: View {
@ObservedObject var scheduleFetcher: ScheduleFetcher
@ObservedObject var predictionsFetcher: PredictionsFetcher
@ObservedObject var viewportProvider: ViewportProvider
@ObservedObject var alertsFetcher: AlertsFetcher

@State var cancellables: [AnyCancellable]
@State var locationProvider: NearbyTransitLocationProvider
Expand All @@ -28,13 +29,15 @@ struct NearbyTransitPageView: View {
nearbyFetcher: NearbyFetcher,
scheduleFetcher: ScheduleFetcher,
predictionsFetcher: PredictionsFetcher,
viewportProvider: ViewportProvider
viewportProvider: ViewportProvider,
alertsFetcher: AlertsFetcher
) {
self.currentLocation = currentLocation
self.nearbyFetcher = nearbyFetcher
self.scheduleFetcher = scheduleFetcher
self.predictionsFetcher = predictionsFetcher
self.viewportProvider = viewportProvider
self.alertsFetcher = alertsFetcher

cancellables = .init()
locationProvider = .init(
Expand All @@ -49,7 +52,8 @@ struct NearbyTransitPageView: View {
locationProvider: locationProvider,
nearbyFetcher: nearbyFetcher,
scheduleFetcher: scheduleFetcher,
predictionsFetcher: predictionsFetcher
predictionsFetcher: predictionsFetcher,
alertsFetcher: alertsFetcher
)
.onAppear {
cancellables.append(
Expand Down
8 changes: 6 additions & 2 deletions iosApp/iosApp/Pages/NearbyTransit/NearbyTransitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct NearbyTransitView: View {
@ObservedObject var nearbyFetcher: NearbyFetcher
@ObservedObject var scheduleFetcher: ScheduleFetcher
@ObservedObject var predictionsFetcher: PredictionsFetcher
@ObservedObject var alertsFetcher: AlertsFetcher
@State var now = Date.now

let timer = Timer.publish(every: 5, on: .main, in: .common).autoconnect()
Expand All @@ -29,6 +30,7 @@ struct NearbyTransitView: View {
if let nearby = nearbyFetcher.withRealtimeInfo(
schedules: scheduleFetcher.schedules,
predictions: predictionsFetcher.predictions,
alerts: alertsFetcher.alerts,
filterAtTime: now.toKotlinInstant()
) {
List(nearby, id: \.route.id) { nearbyRoute in
Expand Down Expand Up @@ -247,7 +249,8 @@ struct NearbyTransitView_Previews: PreviewProvider {
upcomingTrips: [
UpcomingTrip(prediction: busPrediction1),
UpcomingTrip(prediction: busPrediction2),
]
],
alertsHere: nil
),
]
),
Expand All @@ -268,7 +271,8 @@ struct NearbyTransitView_Previews: PreviewProvider {
upcomingTrips: [
UpcomingTrip(prediction: crPrediction1),
UpcomingTrip(prediction: crPrediction2),
]
],
alertsHere: nil
),
]
),
Expand Down
66 changes: 66 additions & 0 deletions iosApp/iosApp/Pages/NearbyTransit/UpcomingTripView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct UpcomingTripView: View {
enum State: Equatable {
case loading
case none
case noService(shared.Alert.Effect)
case some(UpcomingTrip.Format)
}

Expand Down Expand Up @@ -51,6 +52,8 @@ struct UpcomingTripView: View {
case let .minutes(format):
Text("\(format.minutes, specifier: "%ld") min")
}
case let .noService(alertEffect):
NoServiceView(effect: .from(alertEffect: alertEffect))
case .none:
Text("No Predictions")
case .loading:
Expand All @@ -60,3 +63,66 @@ struct UpcomingTripView: View {
.frame(minWidth: 48, alignment: .trailing)
}
}

struct NoServiceView: View {
let effect: Effect

enum Effect {
case detour
case shuttle
case stopClosed
case suspension
case unknown

static func from(alertEffect: shared.Alert.Effect) -> Self {
switch alertEffect {
case .detour: .detour
case .shuttle: .shuttle
case .stationClosure, .stopClosure: .stopClosed
case .suspension: .suspension
default: .unknown
}
}
}

var body: some View {
HStack {
rawText
.font(.system(size: 12))
.textCase(.uppercase)
rawImage
}
}

var rawText: Text {
switch effect {
case .detour: Text("Detour")
case .shuttle: Text("Shuttle")
case .stopClosed: Text("Stop Closed")
case .suspension: Text("Suspension")
case .unknown: Text("No Service")
}
}

var rawImage: Image {
switch effect {
case .detour: Image(systemName: "circle.fill")
case .shuttle: Image(systemName: "bus")
case .stopClosed: Image(systemName: "xmark.octagon.fill")
case .suspension: Image(systemName: "exclamationmark.triangle.fill")
case .unknown: Image(systemName: "questionmark.circle.fill")
}
}
}

struct UpcomingTripView_Previews: PreviewProvider {
static var previews: some View {
VStack(alignment: .trailing) {
UpcomingTripView(prediction: .noService(.suspension))
UpcomingTripView(prediction: .noService(.shuttle))
UpcomingTripView(prediction: .noService(.stopClosure))
UpcomingTripView(prediction: .noService(.detour))
}
.previewDisplayName("No Service")
}
}
Loading

0 comments on commit a489b74

Please sign in to comment.