Skip to content

Commit

Permalink
add onboarding for otpkitdemo
Browse files Browse the repository at this point in the history
  • Loading branch information
hilmyveradin committed Aug 28, 2024
1 parent c724fa5 commit 063a69d
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 40 deletions.
19 changes: 7 additions & 12 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
## Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
(Please include a summary of the changes and the related issue. Please also include relevant motivation and context.)

## Related Issues

Mention your issue by typing the issue number: #(issue number)
(Mention your issue by typing the issue number: #(issue number))

## Media

Please include the media if applicable. For UI changes, it is recommended to provide screen record or screenshots
(Please include the media if applicable. For UI changes, it is recommended to provide screen record or screenshots)

## Test Instructions
(Please describe the tests that you ran to verify your changes. Provide instructions so others can reproduce.)

Please describe the tests that you ran to verify your changes. Provide instructions so others can reproduce.

1. Test A
2. Test B
1. (Test A)
2. (Test B)

## Additional Context

Add any other context about the pull request here.
(Add any other context about the pull request here.)
4 changes: 4 additions & 0 deletions Examples/OTPKitDemo/OTPKitDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
0111FD712C6CFBE400B4472E /* OTPKit in Frameworks */ = {isa = PBXBuildFile; productRef = 0111FD702C6CFBE400B4472E /* OTPKit */; };
014316DF2C6B6F2C00B33240 /* OTPKit in Frameworks */ = {isa = PBXBuildFile; productRef = 014316DE2C6B6F2C00B33240 /* OTPKit */; };
015364702C7E93BE00146182 /* OnboardingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0153646F2C7E93BE00146182 /* OnboardingView.swift */; };
01AA23162C758E62008F484E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 01AA23152C758E62008F484E /* LaunchScreen.storyboard */; };
01AA80542C6B6A7500D4038A /* OTPKitDemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01AA80532C6B6A7500D4038A /* OTPKitDemoApp.swift */; };
01AA80562C6B6A7500D4038A /* MapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01AA80552C6B6A7500D4038A /* MapView.swift */; };
Expand All @@ -18,6 +19,7 @@

/* Begin PBXFileReference section */
014316E02C6B713D00B33240 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
0153646F2C7E93BE00146182 /* OnboardingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingView.swift; sourceTree = "<group>"; };
01AA23152C758E62008F484E /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
01AA80502C6B6A7500D4038A /* OTPKitDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OTPKitDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
01AA80532C6B6A7500D4038A /* OTPKitDemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OTPKitDemoApp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -62,6 +64,7 @@
014316E02C6B713D00B33240 /* Info.plist */,
01AA80532C6B6A7500D4038A /* OTPKitDemoApp.swift */,
01AA80552C6B6A7500D4038A /* MapView.swift */,
0153646F2C7E93BE00146182 /* OnboardingView.swift */,
01AA80572C6B6A7600D4038A /* Assets.xcassets */,
01AA80592C6B6A7600D4038A /* Preview Content */,
);
Expand Down Expand Up @@ -154,6 +157,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
015364702C7E93BE00146182 /* OnboardingView.swift in Sources */,
01AA80562C6B6A7500D4038A /* MapView.swift in Sources */,
01AA80542C6B6A7500D4038A /* OTPKitDemoApp.swift in Sources */,
);
Expand Down
31 changes: 14 additions & 17 deletions Examples/OTPKitDemo/OTPKitDemo/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,25 @@ struct MapView: View {
@Environment(TripPlannerService.self) private var tripPlanner

var body: some View {
TripPlannerExtensionView {
Map(position: tripPlanner.currentCameraPositionBinding, interactionModes: .all) {
tripPlanner.generateMarkers()
tripPlanner.generateMapPolyline()
.stroke(.blue, lineWidth: 5)
}
.mapControls {
if !tripPlanner.isMapMarkingMode {
MapUserLocationButton()
MapPitchToggle()
ZStack {
TripPlannerExtensionView {
Map(position: tripPlanner.currentCameraPositionBinding, interactionModes: .all) {
tripPlanner.generateMarkers()
tripPlanner.generateMapPolyline()
.stroke(.blue, lineWidth: 5)
}
.mapControls {
if !tripPlanner.isMapMarkingMode {
MapUserLocationButton()
MapPitchToggle()
}
}
}
}

}
}

#Preview {
let planner = TripPlannerService(
apiClient: RestAPI(baseURL: URL(string: "https://otp.prod.sound.obaweb.org/otp/routers/default/")!),
locationManager: CLLocationManager(),
searchCompleter: MKLocalSearchCompleter()
)

return MapView()
MapView()
}
23 changes: 12 additions & 11 deletions Examples/OTPKitDemo/OTPKitDemo/OTPKitDemoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ import SwiftUI

@main
struct OTPKitDemoApp: App {
let tripPlannerService = TripPlannerService(
apiClient: RestAPI(baseURL: URL(string: "https://otp.prod.sound.obaweb.org/otp/routers/default/")!),
locationManager: CLLocationManager(),
searchCompleter: MKLocalSearchCompleter()
)

let sheetEnvironment = OriginDestinationSheetEnvironment()

@State private var hasCompletedOnboarding = false
@State private var selectedRegionURL: URL?
@State private var tripPlannerService: TripPlannerService?

var body: some Scene {
WindowGroup {
MapView()
.environment(tripPlannerService)
.environment(sheetEnvironment)
if hasCompletedOnboarding, let service = tripPlannerService {
MapView()
.environment(service)
.environment(OriginDestinationSheetEnvironment())
} else {
OnboardingView(hasCompletedOnboarding: $hasCompletedOnboarding, selectedRegionURL: $selectedRegionURL, tripPlannerService: $tripPlannerService)
}
}
}
}

94 changes: 94 additions & 0 deletions Examples/OTPKitDemo/OTPKitDemo/OnboardingView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import SwiftUI
import OTPKit
import MapKit

/// View to select region for demo purposes
struct OnboardingView: View {
@Binding var hasCompletedOnboarding: Bool
@Binding var selectedRegionURL: URL?
@Binding var tripPlannerService: TripPlannerService?
@State private var selectedRegion: String = "Puget Sound"

Check warning on line 11 in Examples/OTPKitDemo/OTPKitDemo/OnboardingView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
private let regions = [
"Puget Sound": [
"url": "https://otp.prod.sound.obaweb.org/otp/routers/default/",
"lat": 47.64585,
"lon": -122.2963
],
"San Diego": [
"url": "https://realtime.sdmts.com:9091/otp/routers/default/",
"lat": 32.731591,
"lon": -117.1896335
],
"Tampa": [
"url": "https://otp.prod.obahart.org/otp/routers/default/",
"lat": 27.9769105,
"lon": -82.445851
]
]

Check warning on line 29 in Examples/OTPKitDemo/OTPKitDemo/OnboardingView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
var body: some View {
VStack(spacing: 20) {
Text("Hello! Welcome to OTPKitDemo!")
.font(.title)

Check warning on line 34 in Examples/OTPKitDemo/OTPKitDemo/OnboardingView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
Text("Please choose your initial region.")
.font(.subheadline)

Check warning on line 37 in Examples/OTPKitDemo/OTPKitDemo/OnboardingView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
List(Array(regions.keys), id: \.self) { key in
Button(action: {
selectedRegion = key
}) {

Check warning on line 41 in Examples/OTPKitDemo/OTPKitDemo/OnboardingView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument (multiple_closures_with_trailing_closure)
HStack {
Text(key)
Spacer()
if selectedRegion == key {
Image(systemName: "checkmark")
.foregroundColor(.blue)
}
}
}
.foregroundColor(.primary)
}
.frame(height: 200)

Check warning on line 54 in Examples/OTPKitDemo/OTPKitDemo/OnboardingView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
Button(action: {
if let urlString = regions[selectedRegion]?["url"] as? String,
let url = URL(string: urlString),
let latitude = regions[selectedRegion]?["lat"] as? Double,
let longitude = regions[selectedRegion]?["lon"] as? Double {

selectedRegionURL = url

print(urlString)
tripPlannerService = TripPlannerService(
apiClient: RestAPI(baseURL: url),
locationManager: CLLocationManager(),
searchCompleter: MKLocalSearchCompleter()
)

let locationCoordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
tripPlannerService?.changeMapCamera(to: locationCoordinate)
hasCompletedOnboarding = true
}
}) {

Check warning on line 74 in Examples/OTPKitDemo/OTPKitDemo/OnboardingView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument (multiple_closures_with_trailing_closure)
Text("Submit")
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
}
}
.padding()
}
}

#Preview {
let planner = TripPlannerService(
apiClient: RestAPI(baseURL: URL(string: "https://otp.prod.sound.obaweb.org/otp/routers/default/")!),
locationManager: CLLocationManager(),
searchCompleter: MKLocalSearchCompleter()
)

return OnboardingView(hasCompletedOnboarding: .constant(true), selectedRegionURL: .constant(nil), tripPlannerService: .constant(planner))

Check warning on line 93 in Examples/OTPKitDemo/OTPKitDemo/OnboardingView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 120 characters or less; currently it has 141 characters (line_length)
}
8 changes: 8 additions & 0 deletions Sources/OTPKit/Services/TripPlannerService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ public final class TripPlannerService: NSObject {
public func changeMapCamera(_ item: MKMapItem) {
currentCameraPosition = MapCameraPosition.item(item)
}

Check warning on line 197 in Sources/OTPKit/Services/TripPlannerService.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
/// Changes the map camera to focus on the given coordinate
///
/// - Parameter to coordinate: Add the CLLocationCoordinate2D object
public func changeMapCamera(to coordinate: CLLocationCoordinate2D) {
let region = MKCoordinateRegion(center: coordinate, latitudinalMeters: 1000, longitudinalMeters: 1000)
currentCameraPosition = .region(region)
}

/// Generates markers for the map based on selected points
///
Expand Down

0 comments on commit 063a69d

Please sign in to comment.