From 2aa853d6f09e52b640fe11759b3b29933204d7e0 Mon Sep 17 00:00:00 2001 From: Ronan Date: Tue, 18 Feb 2020 18:43:54 -0800 Subject: [PATCH] v1.22 --- Arrival-iOS2.xcodeproj/project.pbxproj | 8 ++++++-- Arrival-iOS2/AppData.swift | 13 ++++++++----- Arrival-iOS2/Helpers.swift | 26 ++++++++++++++++++++++++++ Arrival-iOS2/HomeView.swift | 4 ++-- Arrival-iOS2/TrainComponent.swift | 4 ++-- Arrival-iOS2/TripComponentView.swift | 10 +++++----- Arrival-iOS2/TripDetailView.swift | 19 +++++++++---------- 7 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 Arrival-iOS2/Helpers.swift diff --git a/Arrival-iOS2.xcodeproj/project.pbxproj b/Arrival-iOS2.xcodeproj/project.pbxproj index 60795f0..c182997 100644 --- a/Arrival-iOS2.xcodeproj/project.pbxproj +++ b/Arrival-iOS2.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 3475759823FCCCE3008CF063 /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3475759723FCCCE2008CF063 /* Helpers.swift */; }; 34AF24A823DFD00400E66C34 /* Train.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34AF24A723DFD00400E66C34 /* Train.swift */; }; 34CD87F723EA8A24004F8024 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34CD87F623EA8A24004F8024 /* SettingsView.swift */; }; 34EF38AF23CC23D4000DE4AF /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34EF38AE23CC23D4000DE4AF /* Colors.swift */; }; @@ -42,6 +43,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 3475759723FCCCE2008CF063 /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Helpers.swift; path = "/Users/ronan/Desktop/Dev/IOS/Arrival-IOS/Arrival-iOS2/Helpers.swift"; sourceTree = ""; }; 34AF24A723DFD00400E66C34 /* Train.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Train.swift; sourceTree = ""; }; 34CD87F623EA8A24004F8024 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; 34EF38AE23CC23D4000DE4AF /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = ""; }; @@ -180,6 +182,7 @@ C5B5A53523FA62B00046CCF5 /* TripComponentView.swift */, C5B5A53623FA62B00046CCF5 /* TripDetailView.swift */, C5B5A53923FA642D0046CCF5 /* TripWaitTimeView.swift */, + 3475759723FCCCE2008CF063 /* Helpers.swift */, ); path = "Arrival-iOS2"; sourceTree = ""; @@ -353,6 +356,7 @@ C5166C3923F610AC001F0254 /* TermsOfSeriviceView.swift in Sources */, C58F248423CC1438003882F3 /* SceneDelegate.swift in Sources */, C55640F723CF8439003BCB91 /* AppData.swift in Sources */, + 3475759823FCCCE3008CF063 /* Helpers.swift in Sources */, 34CD87F723EA8A24004F8024 /* SettingsView.swift in Sources */, C5B5A53723FA62B00046CCF5 /* TripComponentView.swift in Sources */, ); @@ -502,7 +506,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.21; + MARKETING_VERSION = 1.22; PRODUCT_BUNDLE_IDENTIFIER = com.ronanfuruta.arrival; PRODUCT_NAME = Arrival; SWIFT_VERSION = 5.0; @@ -525,7 +529,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.21; + MARKETING_VERSION = 1.22; PRODUCT_BUNDLE_IDENTIFIER = com.ronanfuruta.arrival; PRODUCT_NAME = Arrival; SWIFT_VERSION = 5.0; diff --git a/Arrival-iOS2/AppData.swift b/Arrival-iOS2/AppData.swift index bc57688..cde121c 100644 --- a/Arrival-iOS2/AppData.swift +++ b/Arrival-iOS2/AppData.swift @@ -21,7 +21,6 @@ import FirebaseCrashlytics let dateFormate = "hh:mm A" let appDelegate = UIApplication.shared.delegate as! AppDelegate let context = appDelegate.persistentContainer.viewContext -let baseURL = "https://api.arrival.city" var jsContext: JSContext! class AppData: NSObject, ObservableObject,CLLocationManagerDelegate { @Published var screen: String = "home" @@ -83,6 +82,10 @@ class AppData: NSObject, ObservableObject,CLLocationManagerDelegate { remoteConfig.setDefaults(fromPlist: "RemoteConfigDefaults") self.apiUrl = self.remoteConfig["apiurl"].stringValue! self.cycleTimer = Double(self.remoteConfig["cycleTimer"].stringValue!)! + self.aboutText = self.remoteConfig["aboutText"].stringValue! + self.realtimeTripNotice = self.remoteConfig["realtimeTripsNotice"].stringValue! + self.privacyPolicy = self.remoteConfig["privacyPolicyUrl"].stringValue! + self.termsOfService = self.remoteConfig["termsOfServiceUrl"].stringValue! let preferencesEntity = NSEntityDescription.entity(forEntityName: "Preferences", in: context)! let newTestPref = NSManagedObject(entity: preferencesEntity, insertInto: context) newTestPref.setValue(false, forKey: "prioritizeTrain") @@ -562,13 +565,13 @@ class AppData: NSObject, ObservableObject,CLLocationManagerDelegate { if (i != 0) { let lastTrainString = thisTrain["leg"][i - 1]["@destTimeMin"].stringValue let originTimeString = leg["@origTimeMin"].stringValue - let lastTrainTime = moment(lastTrainString, "hh:mm") - let originTime = moment(originTimeString, "hh:mm") + let lastTrainTime = moment(lastTrainString, dateFormate) + let originTime = moment(originTimeString, dateFormate) let difference = originTime.diff(lastTrainTime, "minutes") transferWait = difference.stringValue + " min" print(lastTrainTime.format(), originTime.format(), difference, transferWait, "transfer wait") } - let enrouteTime = moment(leg["@destTimeMin"].stringValue, "hh:mm A").diff(moment(leg["@origTimeMin"].stringValue, "hh:mm"), "minutes") + let enrouteTime = moment(leg["@destTimeMin"].stringValue, dateFormate).diff(moment(leg["@origTimeMin"].stringValue, dateFormate), "minutes") let enrouteTimeString = enrouteTime.stringValue + "min" // print(routeJSON.dictionaryObject, "route for route", routeNum, "color", routeJSON["color"].stringValue) @@ -583,7 +586,7 @@ class AppData: NSObject, ObservableObject,CLLocationManagerDelegate { //let color = thisTrain["color"].stringValue let color = "none" print(eta) - let originTime = moment(thisTrain["@origTimeMin"].stringValue, "hh:mm") + let originTime = moment(thisTrain["@origTimeMin"].stringValue, dateFormate) let now = moment() let difference = originTime.diff(now, "minutes").intValue results.append(Train(id: UUID(), direction: direction, time: etd, unit: "", color: "none", cars: 0, hex: "0", eta: eta)) diff --git a/Arrival-iOS2/Helpers.swift b/Arrival-iOS2/Helpers.swift new file mode 100644 index 0000000..c667991 --- /dev/null +++ b/Arrival-iOS2/Helpers.swift @@ -0,0 +1,26 @@ +// +// Helpers.swift +// +// +// Created by Ronan Furuta on 2/18/20. +// + +import Foundation + +func timeDisplay(time: String) -> String { + return moment(time, dateFormate).format("h:mm a") +} +func stationDisplay(_ station: String) -> String { + switch station.lowercased() { + case "san francisco international airport" : + return "SF Airport" + case "Civic Center/UN Plaza".lowercased() : + return "Civic Center" + case "Oakland International Airport".lowercased() : + return "Oakland Airport" + case "Pleasant Hill/Contra Costa Centre".lowercased() : + return "Pleasant Hill/Contra Costa" + default: + return station + } +} diff --git a/Arrival-iOS2/HomeView.swift b/Arrival-iOS2/HomeView.swift index 45e2295..3c34366 100644 --- a/Arrival-iOS2/HomeView.swift +++ b/Arrival-iOS2/HomeView.swift @@ -54,7 +54,7 @@ struct HomeView: View { if (self.appData.fromStation.id != "loading") { VStack(alignment: .leading) { Text("from").font(.caption) - Text(self.appData.fromStation.name).font(.headline) + Text(stationDisplay(self.appData.fromStation.name)).font(.headline) }.lineLimit(1) } else { VStack(alignment: .leading) { @@ -116,7 +116,7 @@ struct HomeView: View { }) { VStack(alignment: .trailing) { Text("to").font(.caption) - Text(self.appData.toStation.name).font(.headline) + Text(stationDisplay(self.appData.toStation.name)).font(.headline) }.lineLimit(1) }.sheet(isPresented: self.$toModalDisplayed) { VStack(alignment: .leading) { diff --git a/Arrival-iOS2/TrainComponent.swift b/Arrival-iOS2/TrainComponent.swift index 0d04072..202d65e 100644 --- a/Arrival-iOS2/TrainComponent.swift +++ b/Arrival-iOS2/TrainComponent.swift @@ -35,7 +35,7 @@ struct TrainComponent: View { if (type != "skeleton") { if (type == "train") { Text("direction").font(.caption) } - Text(name).font(.headline) + Text(stationDisplay(name)).font(.headline) } else { Rectangle() .fill(Color.skeleton) @@ -72,7 +72,7 @@ struct TrainComponent: View { if (!eta.isEmpty) { VStack(alignment: .trailing) { Text("arrives").font(.caption) - Text(String(eta)).font(.headline) + Text(timeDisplay(time: String(eta))).font(.headline) } } diff --git a/Arrival-iOS2/TripComponentView.swift b/Arrival-iOS2/TripComponentView.swift index 96f791e..e674ce6 100644 --- a/Arrival-iOS2/TripComponentView.swift +++ b/Arrival-iOS2/TripComponentView.swift @@ -26,13 +26,13 @@ struct TripComponentView: View { VStack { HStack { VStack(alignment: .leading, spacing: 0) { - Text(fromStationName) + Text(stationDisplay(fromStationName)) .fontWeight(.semibold) HStack(spacing: 0) { Image(systemName: "arrow.right.circle.fill").font(.subheadline) Spacer() .frame(width: 3.0) - Text(trainName).font(.subheadline) + Text(stationDisplay(trainName)).font(.subheadline) } @@ -40,7 +40,7 @@ struct TripComponentView: View { } Spacer() - Text(fromStationTime) + Text(timeDisplay(time: fromStationTime)) .font(.subheadline) } HStack { @@ -60,14 +60,14 @@ struct TripComponentView: View { } HStack { VStack(alignment: .leading, spacing: 0) { - Text(destinationStationName) .fontWeight(.semibold) + Text(stationDisplay(destinationStationName)).fontWeight(.semibold) } Spacer() - Text(toStationTime) + Text(timeDisplay(time:toStationTime)) .font(.subheadline) } }.padding([.top, .bottom, .trailing]).padding(.leading, 5.0) diff --git a/Arrival-iOS2/TripDetailView.swift b/Arrival-iOS2/TripDetailView.swift index a7f6ead..7b5abee 100644 --- a/Arrival-iOS2/TripDetailView.swift +++ b/Arrival-iOS2/TripDetailView.swift @@ -30,7 +30,7 @@ struct TripDetailView: View { VStack(alignment: .leading) { Text("Departs") .font(.caption) - Text(self.tripToShow.originTime) + Text(timeDisplay(time: self.tripToShow.originTime)) .font(.headline) } Spacer() @@ -45,13 +45,13 @@ struct TripDetailView: View { VStack(alignment: .trailing) { Text("Arrives") .font(.caption) - Text(self.tripToShow.destinatonTime) + Text(timeDisplay(time: self.tripToShow.destinatonTime)) .font(.headline) } }.padding([.top, .bottom]) Divider() List { - VStack { + ForEach(self.tripToShow.legs) {leg in VStack { @@ -64,21 +64,20 @@ struct TripDetailView: View { TripComponentView(fromStationName: leg.origin, trainName: leg.trainDestination, stops: leg.stops, type: leg.type, destinationStationName: leg.destination, fromStationTime: leg.originTime, toStationTime: leg.destinationTime, enrouteTime: leg.enrouteTime, color: self.appData.convertColor(color: leg.color)).listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0)) if (leg.order == self.tripToShow.legs.count) { - TripWaitTimeView(type: "arrive", time: self.tripToShow.destinatonTime) + TripWaitTimeView(type: "arrive", time: timeDisplay(time:self.tripToShow.destinatonTime)) } } } - - }.edgesIgnoringSafeArea(.bottom).listRowInsets(.init(top: 10, leading: 0, bottom: 0, trailing: 0)) + }.edgesIgnoringSafeArea(.bottom) - + Spacer() }.edgesIgnoringSafeArea(.bottom).padding().onAppear { - let originTIme = moment(self.tripToShow.originTime, "hh:mm") - let destinationTIme = moment(self.tripToShow.destinatonTime, "hh:mm") + let originTIme = moment(self.tripToShow.originTime, dateFormate) + let destinationTIme = moment(self.tripToShow.destinatonTime, dateFormate) let routeTime = destinationTIme.diff(originTIme, "minutes") - let boardTime = moment(self.tripToShow.legs[0].originTime, "hh:mm") + let boardTime = moment(self.tripToShow.legs[0].originTime, dateFormate) self.boardWait = boardTime.fromNow(true) print(routeTime, destinationTIme.format(), originTIme.format(), "route time", wait) self.routeTime = routeTime.stringValue + "min"