From f93959c92755c62a4a9f613325ac647408825cf2 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Sat, 20 May 2023 16:57:45 -0400 Subject: [PATCH] Update Activity indicator if authorization status changes. --- Clocker/Clocker/LocationController.swift | 7 ++++ Clocker/Onboarding/Onboarding.storyboard | 4 +-- .../OnboardingPermissionsViewController.swift | 32 ++++++++++++++----- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Clocker/Clocker/LocationController.swift b/Clocker/Clocker/LocationController.swift index f31ffdd..3b43b9c 100644 --- a/Clocker/Clocker/LocationController.swift +++ b/Clocker/Clocker/LocationController.swift @@ -5,9 +5,14 @@ import CoreLocation import CoreLoggerKit import CoreModelKit +protocol LocationControllerDelegate: NSObject { + func didChangeAuthorizationStatus() +} + class LocationController: NSObject { private let store: DataStore private static var sharedController = LocationController(withStore: DataStore.shared()) + weak var delegate: LocationControllerDelegate? init(withStore dataStore: DataStore) { store = dataStore @@ -33,6 +38,7 @@ class LocationController: NSObject { } func locationAccessGranted() -> Bool { + print("Location Status is ", CLLocationManager.authorizationStatus().rawValue.description) return CLLocationManager.authorizationStatus() == .authorizedAlways || CLLocationManager.authorizationStatus() == .authorized } @@ -120,6 +126,7 @@ extension LocationController: CLLocationManagerDelegate { } else if status == .notDetermined || status == .authorized || status == .authorizedAlways { locationManager.startUpdatingLocation() } + delegate?.didChangeAuthorizationStatus() } func locationManager(_: CLLocationManager, didFailWithError error: Error) { diff --git a/Clocker/Onboarding/Onboarding.storyboard b/Clocker/Onboarding/Onboarding.storyboard index 659ce34..b854fdc 100644 --- a/Clocker/Onboarding/Onboarding.storyboard +++ b/Clocker/Onboarding/Onboarding.storyboard @@ -189,7 +189,7 @@ DQ - + @@ -201,7 +201,7 @@ DQ - + diff --git a/Clocker/Onboarding/OnboardingPermissionsViewController.swift b/Clocker/Onboarding/OnboardingPermissionsViewController.swift index 03d53c2..f7e8588 100644 --- a/Clocker/Onboarding/OnboardingPermissionsViewController.swift +++ b/Clocker/Onboarding/OnboardingPermissionsViewController.swift @@ -42,16 +42,13 @@ class OnboardingPermissionsViewController: NSViewController { } private func setup() { - appLabel.stringValue = NSLocalizedString("Permissions Tab", - comment: "Title for Permissions screen") + appLabel.stringValue = NSLocalizedString("Permissions Tab", comment: "Title for Permissions screen") onboardingTypeLabel.stringValue = "Your data doesn't leave your device 🔐" - reminderHeaderLabel.stringValue = NSLocalizedString("Reminders Access Title", - comment: "Title for Reminders Access Label") - reminderDetailLabel.stringValue = "Set reminders in the timezone of the location of your choice. Your reminders are stored in the default Reminders app. " + reminderHeaderLabel.stringValue = NSLocalizedString("Reminders Access Title",comment: "Title for Reminders Access Label") + reminderDetailLabel.stringValue = "Set reminders in the timezone of the location of your choice." - calendarHeaderLabel.stringValue = NSLocalizedString("Calendar Access Title", - comment: "Title for Calendar access label") + calendarHeaderLabel.stringValue = NSLocalizedString("Calendar Access Title",comment: "Title for Calendar access label") calendarDetailLabel.stringValue = "Calendar Detail".localized() locationHeaderLabel.stringValue = "Location Access" @@ -160,6 +157,7 @@ class OnboardingPermissionsViewController: NSViewController { @IBAction func locationAction(_: NSButton) { let locationController = LocationController.shared() if locationController.locationAccessNotDetermined() { + locationController.delegate = self locationActivityIndicator.startAnimation(nil) locationController.determineAndRequestLocationAuthorization() } else if locationController.locationAccessDenied() { @@ -167,6 +165,24 @@ class OnboardingPermissionsViewController: NSViewController { } else if locationController.locationAccessGranted() { locationGrantButton.title = "Granted".localized() } - + } + + private func setupLocationButton() { + let locationController = LocationController.shared() + if locationController.locationAccessNotDetermined() { + locationGrantButton.title = "Grant".localized() + } else if locationController.locationAccessDenied() { + locationGrantButton.title = "Denied".localized() + } else if locationController.locationAccessGranted() { + locationGrantButton.title = "Granted".localized() + } + } +} + +extension OnboardingPermissionsViewController: LocationControllerDelegate { + + func didChangeAuthorizationStatus() { + locationActivityIndicator.stopAnimation(nil) + setupLocationButton() } }