Skip to content

Commit

Permalink
Merge pull request #235 from skedgo/upstream
Browse files Browse the repository at this point in the history
Upstream
  • Loading branch information
nighthawk authored Jan 19, 2023
2 parents ba8d0c2 + 7b53195 commit af818a0
Show file tree
Hide file tree
Showing 30 changed files with 1,053 additions and 58 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:

jobs:
build_spm:
runs-on: macos-12

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build
run: swift build --target TripKit

Expand All @@ -21,13 +22,13 @@ jobs:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build TripKit Mac
run: xcodebuild build -quiet -project TripKit.xcodeproj -scheme "TripKit-macOS"
- name: Build TripKitUI iOS
run: xcodebuild build -quiet -project TripKit.xcodeproj -scheme "TripKitUI-iOS" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8'
run: xcodebuild build -quiet -project TripKit.xcodeproj -scheme "TripKitUI-iOS" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14'
- name: Build TripKitInterApp iOS
run: xcodebuild build -quiet -project TripKit.xcodeproj -scheme "TripKitInterApp-iOS" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8'
run: xcodebuild build -quiet -project TripKit.xcodeproj -scheme "TripKitInterApp-iOS" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14'

test_xcode:
runs-on: macos-12
Expand All @@ -36,7 +37,7 @@ jobs:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Run tests
env:
TRIPGO_API_KEY: ${{ secrets.TRIPGO_API_KEY }}
Expand All @@ -45,7 +46,7 @@ jobs:
DD_ENV: ci
DD_SERVICE: tripkit-ios
run: |
xcodebuild test -quiet -project TripKit.xcodeproj -scheme "TripKit-iOS" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12' -resultBundlePath TestResults
xcodebuild test -quiet -project TripKit.xcodeproj -scheme "TripKit-iOS" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' -resultBundlePath TestResults
- uses: kishikawakatsumi/[email protected]
with:
path: TestResults.xcresult
Expand All @@ -60,9 +61,9 @@ jobs:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build TripKitUIExample
run: xcodebuild build -quiet -project TripKit.xcodeproj -scheme TripKitUIExample -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8'
run: xcodebuild build -quiet -project TripKit.xcodeproj -scheme TripKitUIExample -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14'
- name: Build MiniMap
run: |
cd Examples/MiniMap
Expand All @@ -72,4 +73,4 @@ jobs:
run: |
cd Examples/CocoaPodsTest
pod install
xcodebuild build -workspace CocoaPodsTest.xcworkspace -scheme CocoaPodsTest -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 13 mini'
xcodebuild build -workspace CocoaPodsTest.xcworkspace -scheme CocoaPodsTest -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14'
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -367,7 +367,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand Down
2 changes: 1 addition & 1 deletion Examples/CocoaPodsTest/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, '13.0'
platform :ios, '14.0'
use_frameworks!

target 'CocoaPodsTest' do
Expand Down
22 changes: 13 additions & 9 deletions Examples/CocoaPodsTest/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PODS:
- GeoMonitor (0.1.1)
- Kingfisher (7.4.1)
- RxCocoa (6.5.0):
- RxRelay (= 6.5.0)
Expand All @@ -7,15 +8,16 @@ PODS:
- RxSwift (= 6.5.0)
- RxSwift (6.5.0)
- TGCardViewController (2.1.2)
- TripKit (4.1.0)
- TripKitInterApp (4.1.0):
- TripKit (~> 4.1.0)
- TripKitUI (4.1.0):
- TripKit (4.3.0)
- TripKitInterApp (4.3.0):
- TripKit (~> 4.3.0)
- TripKitUI (4.3.0):
- GeoMonitor (~> 0.1)
- Kingfisher (~> 7.0)
- RxCocoa (~> 6.5)
- RxSwift (~> 6.5)
- TGCardViewController (>= 2.1)
- TripKit (~> 4.1.0)
- TripKit (~> 4.3.0)

DEPENDENCIES:
- TripKit (from `../../`)
Expand All @@ -24,6 +26,7 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- GeoMonitor
- Kingfisher
- RxCocoa
- RxRelay
Expand All @@ -39,15 +42,16 @@ EXTERNAL SOURCES:
:path: "../../"

SPEC CHECKSUMS:
GeoMonitor: 4f71326249934ee41b16772546f79e93205cac45
Kingfisher: cd762a593a61b2fbecf7645c00f9a801a3ebfc9c
RxCocoa: 94f817b71c07517321eb4f9ad299112ca8af743b
RxRelay: 1de1523e604c72b6c68feadedd1af3b1b4d0ecbd
RxSwift: 5710a9e6b17f3c3d6e40d6e559b9fa1e813b2ef8
TGCardViewController: a19c5fad9f8352f75a7cd0663292d63c693b9947
TripKit: adcb84002375f80c8b376ba997f369e5415b1e3c
TripKitInterApp: 77a13fc163fa246ce0b5e180f62904f469b47830
TripKitUI: 0e0cbfdb0725e35807b1b1fa337de2475298e2bf
TripKit: fca5aab1f4a6b2a4e2e2bb9d236192a528cc6ea7
TripKitInterApp: 4a61bcde573c741d107cd973dcbb15a3eba61026
TripKitUI: 309c28ef02d05a3111da454d6e990322abf9f7a6

PODFILE CHECKSUM: a2ca0312f3711cec4dd98455d47462fd95511a05
PODFILE CHECKSUM: fd67bcba748ae215ff8d7ed6cf43555a3235bd4a

COCOAPODS: 1.11.3
10 changes: 8 additions & 2 deletions Examples/TripKitUIExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Search from or to your current location. Locate yourself on the map. Get notifications about your trip.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Search from or to your current location. Locate yourself on the map. Get notifications about your trip.</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Search from or to your current location. Locate yourself on the map. Get updated ETAs.</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
7 changes: 7 additions & 0 deletions Examples/TripKitUIExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class MainViewController: UITableViewController {
return actions
}
}

// Enable trip notifications
TKUINotificationManager.shared.subscribe(to: .tripAlerts) { requests in
for request in requests {
UNUserNotificationCenter.current().add(request)
}
}
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
Expand Down
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"object": {
"pins": [
{
"package": "GeoMonitor",
"repositoryURL": "https://github.com/skedgo/GeoMonitor.git",
"state": {
"branch": null,
"revision": "c411962eded60edc0e4104c29a361b747c9113cd",
"version": "0.1.0"
}
},
{
"package": "Kingfisher",
"repositoryURL": "https://github.com/onevcat/Kingfisher.git",
Expand Down
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
name: "TripKit",
defaultLocalization: "en",
platforms: [
.iOS(.v13),
.iOS(.v14),
.macOS(.v11),
],
products: [
Expand All @@ -22,6 +22,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "6.1.0")),
.package(url: "https://github.com/onevcat/Kingfisher.git", .upToNextMajor(from: "7.0.0")),
.package(url: "https://github.com/skedgo/GeoMonitor.git", .upToNextMajor(from: "0.1.0")),
.package(url: "https://github.com/skedgo/TGCardViewController.git", .upToNextMajor(from: "2.1.0")),
],
targets: [
Expand All @@ -43,6 +44,7 @@ let package = Package(
"Kingfisher",
.product(name: "RxCocoa", package: "RxSwift"),
"TGCardViewController",
"GeoMonitor",
],
exclude: ["Supporting Files/Info.plist"]
),
Expand Down
2 changes: 1 addition & 1 deletion Sources/TripKit/core/Loc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,5 @@ public class Loc : NSObject {
let format = NSLocalizedString("%@ wheelchair friendly", tableName: "TripKit", bundle: .tripKit, comment: "Indicator for how wheelchair-friendly a wheelchair route is. Placeholder will get replaced with '75%'.")
return String(format: format, percentage)
}

}
117 changes: 117 additions & 0 deletions Sources/TripKit/model/API/RoutingAPIModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extension TKAPI {
}

public struct Trip: Codable, Hashable {
public var id: String?
@ISO8601OrSecondsSince1970 public var depart: Date
@ISO8601OrSecondsSince1970 public var arrive: Date
@DefaultFalse public var hideExactTimes: Bool
Expand Down Expand Up @@ -141,6 +142,7 @@ extension TKAPI {
public let action: String?
public var notes: String?
@UnknownNil public var localCost: TKLocalCost? // Backend is sometimes sending this invalid without currency as of 2021-08-17
@DefaultEmptyArray public var notifications: [TripNotification]
var mini: TKMiniInstruction?
@DefaultFalse var hideExactTimes: Bool

Expand Down Expand Up @@ -201,6 +203,7 @@ extension TKAPI {
case from
case to
case shapes
case notifications = "geofences"
}
}

Expand Down Expand Up @@ -234,6 +237,120 @@ extension TKAPI {
}
}

public struct TripNotification: Codable, Hashable {
public enum Kind: Hashable {
case circle(center: CLLocationCoordinate2D, radius: CLLocationDistance, trigger: Trigger)
case time(Date)

public static func == (lhs: TKAPI.TripNotification.Kind, rhs: TKAPI.TripNotification.Kind) -> Bool {
switch (lhs, rhs) {
case let (.circle(lc, lr, lt), .circle(rc, rr, rt)):
return lc.latitude == rc.latitude
&& lc.longitude == rc.longitude
&& lr == rr
&& lt == rt
case let (.time(lhs), .time(rhs)):
return lhs == rhs
default:
return false
}
}

public func hash(into hasher: inout Hasher) {
switch self {
case let .circle(center, radius, trigger):
hasher.combine(center.latitude)
hasher.combine(center.longitude)
hasher.combine(radius)
hasher.combine(trigger)
case let .time(date):
hasher.combine(date)
}
}

}

struct Coordinate: Codable {
let lat: CLLocationDegrees
let lng: CLLocationDegrees
}

public enum Trigger: String, Codable, Hashable {
case onEnter = "ENTER"
case onExit = "EXIT"
}

public enum MessageKind: String, Codable, Hashable {
case tripStart = "TRIP_START"
case tripEnd = "TRIP_END"
case arrivingAtYourStop = "ARRIVING_AT_YOUR_STOP"
case nextStopIsYours = "NEXT_STOP_IS_YOURS"
}

public let id: String
public let kind: Kind
public let messageKind: MessageKind
public let messageTitle: String
public let messageBody: String

public enum CodingKeys: String, CodingKey {
case id
case kind = "type"
case messageKind = "messageType"
case messageTitle
case messageBody

// geofences
case center
case radius
case trigger

// time-based
case time
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decode(String.self, forKey: .id)

messageKind = try container.decode(MessageKind.self, forKey: .messageKind)
messageTitle = try container.decode(String.self, forKey: .messageTitle)
messageBody = try container.decode(String.self, forKey: .messageBody)

let rawKind = try container.decode(String.self, forKey: .kind)
switch rawKind {
case "CIRCLE":
let coordinate = try container.decode(Coordinate.self, forKey: .center)
let radius = try container.decode(CLLocationDistance.self, forKey: .radius)
let trigger = try container.decode(Trigger.self, forKey: .trigger)
kind = .circle(center: .init(latitude: coordinate.lat, longitude: coordinate.lng), radius: radius, trigger: trigger)
case "TIME":
let date = try container.decode(ISO8601OrSecondsSince1970.self, forKey: .time)
kind = .time(date.wrappedValue)
default:
throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Expected 'type' of value 'CIRCLE', but got '\(rawKind)'"))
}
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(messageKind, forKey: .messageKind)
try container.encode(messageTitle, forKey: .messageTitle)
try container.encode(messageBody, forKey: .messageBody)
switch kind {
case let .circle(center, radius, trigger):
try container.encode("CIRCLE", forKey: .kind)
try container.encode(Coordinate(lat: center.latitude, lng: center.longitude), forKey: .center)
try container.encode(radius, forKey: .radius)
try container.encode(trigger, forKey: .trigger)
case let .time(date):
try container.encode("TIME", forKey: .kind)
try container.encode(date, forKey: .time)
}
}
}

public struct SegmentShape: Codable, Hashable {
public let encodedWaypoints: String

Expand Down
2 changes: 1 addition & 1 deletion Sources/TripKit/model/CoreData/SegmentReference+Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension SegmentReference {

extension SegmentReference {
func populate(from api: TKAPI.SegmentReference) {
// transport
// Public transport
departurePlatform = api.startPlatform
arrivalPlatform = api.endPlatform
serviceStops = api.serviceStops
Expand Down
Loading

0 comments on commit af818a0

Please sign in to comment.