-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from OneBusAway/add-custom-region-onboarding
Add onboarding for otpkitdemo
- Loading branch information
Showing
7 changed files
with
170 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
private let regions = [ | ||
"Puget Sound": [ | ||
"url": URL(string: "https://otp.prod.sound.obaweb.org/otp/routers/default/")!, | ||
"center": CLLocationCoordinate2D(latitude: 47.64585, longitude: -122.2963) | ||
], | ||
"San Diego": [ | ||
"url": URL(string: "https://realtime.sdmts.com:9091/otp/routers/default/")!, | ||
"center": CLLocationCoordinate2D(latitude: 32.731591, longitude: -117.1896335) | ||
], | ||
"Tampa": [ | ||
"url": URL(string: "https://otp.prod.obahart.org/otp/routers/default/")!, | ||
"center": CLLocationCoordinate2D(latitude: 27.9769105, longitude: -82.445851) | ||
] | ||
] | ||
|
||
var body: some View { | ||
VStack { | ||
Spacer(minLength: 20) | ||
Text("Welcome to OTPKitDemo!") | ||
.bold() | ||
.font(.title) | ||
|
||
Text("Please choose your region.") | ||
|
||
List(Array(regions.keys.sorted()), id: \.self) { key in | ||
Button { | ||
selectedRegion = key | ||
} label: { | ||
HStack { | ||
Text(key) | ||
Spacer() | ||
if selectedRegion == key { | ||
Image(systemName: "checkmark") | ||
.foregroundColor(.blue) | ||
} | ||
} | ||
} | ||
.foregroundColor(.primary) | ||
} | ||
|
||
Button { | ||
let selection = regions[selectedRegion]! | ||
|
||
// swiftlint:disable force_cast | ||
let url = selection["url"] as! URL | ||
let center = selection["center"] as! CLLocationCoordinate2D | ||
// swiftlint:enable force_cast | ||
|
||
selectedRegionURL = url | ||
|
||
tripPlannerService = TripPlannerService( | ||
apiClient: RestAPI(baseURL: url), | ||
locationManager: CLLocationManager(), | ||
searchCompleter: MKLocalSearchCompleter() | ||
) | ||
|
||
tripPlannerService?.changeMapCamera(to: center) | ||
hasCompletedOnboarding = true | ||
|
||
} label: { | ||
Text("OK") | ||
.frame(maxWidth: .infinity, minHeight: 44) | ||
} | ||
.buttonStyle(BorderedProminentButtonStyle()) | ||
.padding() | ||
} | ||
.background(Color(UIColor.systemGroupedBackground)) | ||
} | ||
} | ||
|
||
#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) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters