-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix deeplink code and extend URLSchemeRouter
- Loading branch information
1 parent
1712ddc
commit 2a10eaa
Showing
5 changed files
with
101 additions
and
114 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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -278,6 +278,7 @@ public class Application: CoreApplication, PushServiceDelegate { | |
} | ||
|
||
private var presentDonationUIOnActive = false | ||
private var presentAddRegionAlertOnActive = false | ||
private var donationPromptID: String? | ||
|
||
public func pushService(_ pushService: PushService, receivedDonationPrompt id: String?) { | ||
|
@@ -363,6 +364,18 @@ public class Application: CoreApplication, PushServiceDelegate { | |
presentDonationUIOnActive = false | ||
donationPromptID = nil | ||
} | ||
|
||
if presentAddRegionAlertOnActive, let topViewController { | ||
// Show alert for nil addRegion data | ||
let alertController = UIAlertController( | ||
title: "Error", | ||
message: "The provided region URL is invalid or does not point to a functional OBA server.", | ||
preferredStyle: .alert | ||
) | ||
alertController.addAction(UIAlertAction(title: "OK", style: .default)) | ||
topViewController.present(alertController, animated: true) | ||
presentAddRegionAlertOnActive = false | ||
} | ||
} | ||
|
||
@objc public func applicationWillResignActive(_ application: UIApplication) { | ||
|
@@ -429,15 +442,48 @@ public class Application: CoreApplication, PushServiceDelegate { | |
} | ||
|
||
let router = URLSchemeRouter(scheme: scheme) | ||
guard | ||
let stopData = router.decode(url: url), | ||
let topViewController = topViewController | ||
else { | ||
|
||
guard let urlType = router.decodeURLType(from: url) else { | ||
return false | ||
} | ||
|
||
viewRouter.navigateTo(stopID: stopData.stopID, from: topViewController) | ||
return true | ||
switch urlType { | ||
case .viewStop(let stopData): | ||
guard let topViewController = self.topViewController else { return false } | ||
viewRouter.navigateTo(stopID: stopData.stopID, from: topViewController) | ||
return true | ||
case .addRegion(let regionData): | ||
viewRouter.rootNavigateTo(page: .map) | ||
Task { @MainActor in | ||
do { | ||
if let regionData = regionData { | ||
guard let regionCoordinate = try await self.apiService?.getAgenciesWithCoverage().list.first?.region else { return } | ||
|
||
// Adjustments for coordinate span | ||
var adjustedRegionCoordinate = regionCoordinate | ||
adjustedRegionCoordinate.span.latitudeDelta = 2 | ||
adjustedRegionCoordinate.span.longitudeDelta = 2 | ||
|
||
// Create region provider | ||
let regionProvider = RegionPickerCoordinator(regionsService: self.regionsService) | ||
|
||
// Construct Region from URL data | ||
let currentRegion = Region(name: regionData.name, OBABaseURL: regionData.obaURL, coordinateRegion: adjustedRegionCoordinate, contactEmail: "[email protected]", openTripPlannerURL: regionData.otpURL) | ||
|
||
// Add and set current region | ||
try await regionProvider.add(customRegion: currentRegion) | ||
try await regionProvider.setCurrentRegion(to: currentRegion) | ||
} else { | ||
presentAddRegionAlertOnActive = true | ||
return | ||
} | ||
} catch { | ||
presentAddRegionAlertOnActive = true | ||
return | ||
} | ||
} | ||
return true | ||
} | ||
} | ||
|
||
override public func apiServicesRefreshed() { | ||
|
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