Skip to content

Commit fb96059

Browse files
authored
Merge pull request #184 from cuappdev/omar/service-alerts
Codable
2 parents 217374d + d3e0992 commit fb96059

22 files changed

Lines changed: 749 additions & 711 deletions

TCAT.xcodeproj/project.pbxproj

Lines changed: 20 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
222BDE16215C1CEE0040DD93 /* WhatsNewHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 222BDE15215C1CEE0040DD93 /* WhatsNewHeaderView.swift */; };
1212
224EB5A5214F2F01008232C2 /* AppShortcuts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 224EB5A4214F2F01008232C2 /* AppShortcuts.swift */; };
1313
226C8D762173AF69009985E3 /* VersionStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 226C8D752173AF69009985E3 /* VersionStore.swift */; };
14+
2292486921B891A30004279C /* Network+Endpoints.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2292486721B891A30004279C /* Network+Endpoints.swift */; };
15+
2292486A21B891A30004279C /* Network+Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2292486821B891A30004279C /* Network+Models.swift */; };
16+
2292486C21B8ECB90004279C /* ServiceAlertsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2292486B21B8ECB90004279C /* ServiceAlertsViewController.swift */; };
1417
4036E23543D87A22BF6B0023 /* Pods_TCATUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E08977D7DB800C37CAF625E1 /* Pods_TCATUITests.framework */; };
1518
449A7C791D80D0E80019300C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 449A7C781D80D0E80019300C /* AppDelegate.swift */; };
1619
449A7C7E1D80D0E80019300C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 449A7C7C1D80D0E80019300C /* Main.storyboard */; };
@@ -24,7 +27,6 @@
2427
503EC37B1E969ACD00B3D4D4 /* BusStopCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503EC37A1E969ACD00B3D4D4 /* BusStopCell.swift */; };
2528
503EC37D1E969ADF00B3D4D4 /* SearchResultsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503EC37C1E969ADF00B3D4D4 /* SearchResultsCell.swift */; };
2629
503EC37F1E969B2100B3D4D4 /* SearchResultsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503EC37E1E969B2100B3D4D4 /* SearchResultsTableViewController.swift */; };
27-
503EC38D1E96B85B00B3D4D4 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 503EC38C1E96B85B00B3D4D4 /* Network.swift */; };
2830
50A19BAE1E4C214000AD6768 /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A19BAD1E4C214000AD6768 /* HomeViewController.swift */; };
2931
7E14AEDD2177E884006A344D /* IntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E14AEDC2177E884006A344D /* IntentHandler.swift */; };
3032
7E14AEF12177E884006A344D /* Siri.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 7E14AEDA2177E884006A344D /* Siri.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
@@ -143,6 +145,9 @@
143145
222BDE15215C1CEE0040DD93 /* WhatsNewHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = WhatsNewHeaderView.swift; path = Views/WhatsNewHeaderView.swift; sourceTree = "<group>"; };
144146
224EB5A4214F2F01008232C2 /* AppShortcuts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppShortcuts.swift; path = Utilities/AppShortcuts.swift; sourceTree = "<group>"; };
145147
226C8D752173AF69009985E3 /* VersionStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = VersionStore.swift; path = Utilities/VersionStore.swift; sourceTree = "<group>"; };
148+
2292486721B891A30004279C /* Network+Endpoints.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Network+Endpoints.swift"; path = "Utilities/Network+Endpoints.swift"; sourceTree = "<group>"; };
149+
2292486821B891A30004279C /* Network+Models.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Network+Models.swift"; path = "Utilities/Network+Models.swift"; sourceTree = "<group>"; };
150+
2292486B21B8ECB90004279C /* ServiceAlertsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceAlertsViewController.swift; sourceTree = "<group>"; };
146151
449A7C751D80D0E80019300C /* TCAT.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TCAT.app; sourceTree = BUILT_PRODUCTS_DIR; };
147152
449A7C781D80D0E80019300C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
148153
449A7C7D1D80D0E80019300C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
@@ -161,7 +166,6 @@
161166
503EC37A1E969ACD00B3D4D4 /* BusStopCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BusStopCell.swift; path = Cells/BusStopCell.swift; sourceTree = "<group>"; };
162167
503EC37C1E969ADF00B3D4D4 /* SearchResultsCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SearchResultsCell.swift; path = Cells/SearchResultsCell.swift; sourceTree = "<group>"; };
163168
503EC37E1E969B2100B3D4D4 /* SearchResultsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = SearchResultsTableViewController.swift; path = Controllers/SearchResultsTableViewController.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
164-
503EC38C1E96B85B00B3D4D4 /* Network.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Network.swift; path = Utilities/Network.swift; sourceTree = "<group>"; };
165169
50A19BAD1E4C214000AD6768 /* HomeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = HomeViewController.swift; path = Controllers/HomeViewController.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
166170
7E14AEB12177E661006A344D /* TCAT.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TCAT.entitlements; sourceTree = "<group>"; };
167171
7E14AEC02177E846006A344D /* IntentsUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IntentsUI.framework; path = System/Library/Frameworks/IntentsUI.framework; sourceTree = SDKROOT; };
@@ -307,6 +311,15 @@
307311
name = Pods;
308312
sourceTree = "<group>";
309313
};
314+
2292486621B891790004279C /* Network */ = {
315+
isa = PBXGroup;
316+
children = (
317+
2292486721B891A30004279C /* Network+Endpoints.swift */,
318+
2292486821B891A30004279C /* Network+Models.swift */,
319+
);
320+
name = Network;
321+
sourceTree = "<group>";
322+
};
310323
449A7C6C1D80D0E80019300C = {
311324
isa = PBXGroup;
312325
children = (
@@ -454,7 +467,7 @@
454467
D183AA011E6CB092006A9A15 /* Extensions.swift */,
455468
DD04B1AC208CC5E4006C1C23 /* JSONFileManager.swift */,
456469
DD87F2091E878CB5000C244B /* Loader.swift */,
457-
503EC38C1E96B85B00B3D4D4 /* Network.swift */,
470+
2292486621B891790004279C /* Network */,
458471
BF18AE112083B9B8000C3D82 /* Phrases.swift */,
459472
DD3D9C201F94297100B164D4 /* Reachability.swift */,
460473
5006F7B91EC0F59A005ACAF2 /* SearchTableViewHelpers.swift */,
@@ -504,6 +517,7 @@
504517
BF5CBAD01FCE6CCE00478C6F /* RouteDetail+DrawerViewController.swift */,
505518
DD2F98A21E5150990005F6BC /* RouteOptionsViewController.swift */,
506519
503EC37E1E969B2100B3D4D4 /* SearchResultsTableViewController.swift */,
520+
2292486B21B8ECB90004279C /* ServiceAlertsViewController.swift */,
507521
);
508522
name = Controllers;
509523
sourceTree = "<group>";
@@ -543,8 +557,6 @@
543557
449A7C851D80D0E80019300C /* Sources */,
544558
449A7C861D80D0E80019300C /* Frameworks */,
545559
449A7C871D80D0E80019300C /* Resources */,
546-
F5AE6EDEDD605D60D69EDD4E /* [CP] Embed Pods Frameworks */,
547-
E6D86036BFF0AA2106834829 /* [CP] Copy Pods Resources */,
548560
);
549561
buildRules = (
550562
);
@@ -564,8 +576,6 @@
564576
449A7C901D80D0E80019300C /* Sources */,
565577
449A7C911D80D0E80019300C /* Frameworks */,
566578
449A7C921D80D0E80019300C /* Resources */,
567-
571E7972F0DE03752FFCD2AD /* [CP] Embed Pods Frameworks */,
568-
AD68E49A861102013B0F14E6 /* [CP] Copy Pods Resources */,
569579
);
570580
buildRules = (
571581
);
@@ -774,21 +784,6 @@
774784
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
775785
showEnvVarsInLog = 0;
776786
};
777-
571E7972F0DE03752FFCD2AD /* [CP] Embed Pods Frameworks */ = {
778-
isa = PBXShellScriptBuildPhase;
779-
buildActionMask = 2147483647;
780-
files = (
781-
);
782-
inputPaths = (
783-
);
784-
name = "[CP] Embed Pods Frameworks";
785-
outputPaths = (
786-
);
787-
runOnlyForDeploymentPostprocessing = 0;
788-
shellPath = /bin/sh;
789-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TCATUITests/Pods-TCATUITests-frameworks.sh\"\n";
790-
showEnvVarsInLog = 0;
791-
};
792787
7C01627F386C89E7F1995831 /* [CP] Embed Pods Frameworks */ = {
793788
isa = PBXShellScriptBuildPhase;
794789
buildActionMask = 2147483647;
@@ -851,21 +846,6 @@
851846
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
852847
showEnvVarsInLog = 0;
853848
};
854-
AD68E49A861102013B0F14E6 /* [CP] Copy Pods Resources */ = {
855-
isa = PBXShellScriptBuildPhase;
856-
buildActionMask = 2147483647;
857-
files = (
858-
);
859-
inputPaths = (
860-
);
861-
name = "[CP] Copy Pods Resources";
862-
outputPaths = (
863-
);
864-
runOnlyForDeploymentPostprocessing = 0;
865-
shellPath = /bin/sh;
866-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TCATUITests/Pods-TCATUITests-resources.sh\"\n";
867-
showEnvVarsInLog = 0;
868-
};
869849
E3FCA3C71FAA5AFB0069BD0F /* Fabric Configuration */ = {
870850
isa = PBXShellScriptBuildPhase;
871851
buildActionMask = 12;
@@ -880,36 +860,6 @@
880860
shellPath = /bin/sh;
881861
shellScript = "\"${SRCROOT}/TCAT/Supporting Files/fabric-config.sh\"\n\n";
882862
};
883-
E6D86036BFF0AA2106834829 /* [CP] Copy Pods Resources */ = {
884-
isa = PBXShellScriptBuildPhase;
885-
buildActionMask = 2147483647;
886-
files = (
887-
);
888-
inputPaths = (
889-
);
890-
name = "[CP] Copy Pods Resources";
891-
outputPaths = (
892-
);
893-
runOnlyForDeploymentPostprocessing = 0;
894-
shellPath = /bin/sh;
895-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TCATTests/Pods-TCATTests-resources.sh\"\n";
896-
showEnvVarsInLog = 0;
897-
};
898-
F5AE6EDEDD605D60D69EDD4E /* [CP] Embed Pods Frameworks */ = {
899-
isa = PBXShellScriptBuildPhase;
900-
buildActionMask = 2147483647;
901-
files = (
902-
);
903-
inputPaths = (
904-
);
905-
name = "[CP] Embed Pods Frameworks";
906-
outputPaths = (
907-
);
908-
runOnlyForDeploymentPostprocessing = 0;
909-
shellPath = /bin/sh;
910-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TCATTests/Pods-TCATTests-frameworks.sh\"\n";
911-
showEnvVarsInLog = 0;
912-
};
913863
/* End PBXShellScriptBuildPhase section */
914864

915865
/* Begin PBXSourcesBuildPhase section */
@@ -923,7 +873,7 @@
923873
5006F7BA1EC0F59A005ACAF2 /* SearchTableViewHelpers.swift in Sources */,
924874
BFCA712D206AC69000E4CCE5 /* Keys.swift in Sources */,
925875
5006F7B81EBFC7DE005ACAF2 /* CornellDestinationCell.swift in Sources */,
926-
503EC38D1E96B85B00B3D4D4 /* Network.swift in Sources */,
876+
2292486921B891A30004279C /* Network+Endpoints.swift in Sources */,
927877
DDB49C9D1E8857FC00A99C35 /* BusPath.swift in Sources */,
928878
DD659C8A20508E1B00506BAC /* WalkWithDistanceIcon.swift in Sources */,
929879
DD36A7001F66378C00E4789E /* PlaceResult.swift in Sources */,
@@ -943,6 +893,7 @@
943893
DD2F989B1E50F99A0005F6BC /* Route.swift in Sources */,
944894
DD87F20A1E878CB5000C244B /* Loader.swift in Sources */,
945895
DD3D9C341F942CF000B164D4 /* CoordinateVisitor.swift in Sources */,
896+
2292486A21B891A30004279C /* Network+Models.swift in Sources */,
946897
DD3D9C211F94297100B164D4 /* Reachability.swift in Sources */,
947898
DDBFEAA11E787008002BBD96 /* RouteSelectionView.swift in Sources */,
948899
222BDE16215C1CEE0040DD93 /* WhatsNewHeaderView.swift in Sources */,
@@ -979,6 +930,7 @@
979930
DDB49C941E8857D000A99C35 /* RouteDetail+ContentViewController.swift in Sources */,
980931
BFD5B4E41FAADFAE00955C37 /* WalkPath.swift in Sources */,
981932
BF1209FB1F7759C200A7C930 /* BusLocationView.swift in Sources */,
933+
2292486C21B8ECB90004279C /* ServiceAlertsViewController.swift in Sources */,
982934
DD3D9C361F945F2A00B164D4 /* RPCircularProgress.swift in Sources */,
983935
BFC367F321B66E9A00ABD9AC /* Intents.intentdefinition in Sources */,
984936
DD2F98A31E5150990005F6BC /* RouteOptionsViewController.swift in Sources */,

TCAT/AppDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
136136

137137
/* Get all bus stops and store in userDefaults */
138138
func getBusStops() {
139-
Network.getAllStops().perform(withSuccess: { stops in
140-
let allBusStops = stops.allStops
139+
Network.getAllStops().perform(withSuccess: { allBusStopsRequest in
140+
let allBusStops = allBusStopsRequest.data
141141
if allBusStops.isEmpty {
142142
self.handleGetAllStopsError()
143143
} else {

TCAT/Cells/RouteTableViewCell.swift

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//
88

99
import UIKit
10+
import SwiftyJSON
11+
import TRON
1012

1113
protocol TravelDistanceDelegate: NSObjectProtocol {
1214
func travelDistanceUpdated(withDistance distance: Double)
@@ -336,12 +338,12 @@ class RouteTableViewCell: UITableViewCell {
336338
if let route = route,
337339
let direction = route.getFirstDepartRawDirection(),
338340
let tripId = direction.tripIdentifiers?.first,
339-
let stopId = direction.stops.first?.id {
340-
341-
Network.getDelay(tripId: tripId, stopId: stopId).perform(withSuccess: { (json) in
342-
343-
if json["success"].boolValue {
344-
guard let delay = json["data"]["delay"].int else {
341+
let stopId = direction.stops.first?.id {
342+
343+
Network.getDelay(tripId: tripId, stopId: stopId).performCollectingTimeline { (response) in
344+
switch response.result {
345+
case .success(let delayResponse):
346+
guard (delayResponse.data != nil), let delay = delayResponse.data else {
345347
self.setDepartureTimeAndLiveElements(withRoute: route)
346348
return
347349
}
@@ -350,7 +352,14 @@ class RouteTableViewCell: UITableViewCell {
350352
if isNewDelayValue {
351353
JSONFileManager.shared.logDelayParemeters(timestamp: Date(), stopId: stopId, tripId: tripId)
352354
JSONFileManager.shared.logURL(timestamp: Date(), urlName: "Delay requestUrl", url: Network.getDelayUrl(tripId: tripId, stopId: stopId))
353-
JSONFileManager.shared.saveJSON(json, type: .delayJSON(rowNum: self.rowNum ?? -1))
355+
if let data = response.data {
356+
do { try JSONFileManager.shared.saveJSON(JSON.init(data: data), type: .delayJSON(rowNum: self.rowNum ?? -1)) }
357+
catch (let error) {
358+
let fileName = "RouteTableViewCell"
359+
let line = "\(fileName) \(#function): \(error.localizedDescription)"
360+
print(line)
361+
}
362+
}
354363
}
355364

356365
let departTime = direction.startTime
@@ -369,16 +378,15 @@ class RouteTableViewCell: UITableViewCell {
369378
}
370379

371380
route.getFirstDepartRawDirection()?.delay = delay
381+
382+
case .failure(let networkError):
383+
if let error = networkError as? APIError<Error> {
384+
print("\(self.fileName) \(#function) error: \(error.errorDescription ?? "") Request url: \(error.request?.url?.absoluteString ?? "")")
385+
self.setDepartureTimeAndLiveElements(withRoute: route)
386+
}
372387
}
373-
else {
374-
self.setDepartureTimeAndLiveElements(withRoute: route)
375-
}
376-
}, failure: { (error) in
377-
print("\(self.fileName) \(#function) error: \(error.errorDescription ?? "") Request url: \(error.request?.url?.absoluteString ?? "")")
378-
self.setDepartureTimeAndLiveElements(withRoute: route)
379-
})
380-
}
381-
else {
388+
}
389+
} else {
382390
if let route = route {
383391
self.setDepartureTimeAndLiveElements(withRoute: route)
384392
}

TCAT/Controllers/AllStopsTableViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ extension AllStopsTableViewController: DZNEmptyDataSetSource, DZNEmptyDataSetDel
239239
}
240240

241241
func retryNetwork(completion: @escaping () -> Void) {
242-
Network.getAllStops().perform(withSuccess: { stops in
243-
let allBusStops = stops.allStops
242+
Network.getAllStops().perform(withSuccess: { allStopsRequest in
243+
let allBusStops = allStopsRequest.data
244244
if !allBusStops.isEmpty {
245245
// Only updating user defaults if retriving from network is successful
246246
let data = NSKeyedArchiver.archivedData(withRootObject: allBusStops)

TCAT/Controllers/InformationViewController.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ class InformationViewController: UIViewController, UITableViewDataSource, UITabl
2727

2828
var content: [[(name: String, action: Selector)]] = [
2929

30-
[ // Section 0
30+
31+
[ // Seciton 0
32+
(name: Constants.InformationView.serviceAlerts, action: #selector(showServiceAlerts))
33+
],
34+
35+
[ // Section 1
3136
(name: Constants.InformationView.onboarding, action: #selector(presentOnboarding)),
3237
(name: Constants.InformationView.sendFeedback, action: #selector(sendFeedback))
3338
],
3439

35-
[ // Section 1
40+
[ // Section 2
3641
(name: Constants.InformationView.moreApps, action: #selector(showMoreApps)),
3742
(name: Constants.InformationView.website, action: #selector(openTeamWebsite))
3843
]
@@ -286,6 +291,11 @@ class InformationViewController: UIViewController, UITableViewDataSource, UITabl
286291
let homePage = "http://www.cornellappdev.com"
287292
open(homePage)
288293
}
294+
295+
@objc func showServiceAlerts() {
296+
let serviceAlertsVC = ServiceAlertsViewController()
297+
present(serviceAlertsVC, animated: true)
298+
}
289299

290300
func open(_ url: String, inApp: Bool = true) {
291301

0 commit comments

Comments
 (0)