-
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.
Merge pull request #723 from hilmyveradin/issue_719-custom_region_tap…
…_url Issue 719: Add Custom Region URL
- Loading branch information
Showing
9 changed files
with
125 additions
and
19 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 |
---|---|---|
|
@@ -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: Strings.error, | ||
message: OBALoc("region_url.error_messsage", value: "The provided region URL is invalid or does not point to a functional OBA server.", comment: "Error message of Custom Region URL if it's invalid or does not point to a functional OBA server"), | ||
preferredStyle: .alert | ||
) | ||
alertController.addAction(UIAlertAction(title: Strings.ok, style: .default)) | ||
topViewController.present(alertController, animated: true) | ||
presentAddRegionAlertOnActive = false | ||
} | ||
} | ||
|
||
@objc public func applicationWillResignActive(_ application: UIApplication) { | ||
|
@@ -429,15 +442,50 @@ 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 { | ||
guard let regionData else { | ||
presentAddRegionAlertOnActive = true | ||
return | ||
} | ||
|
||
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) | ||
} 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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