Browse Source

Update Activity indicator if authorization status changes.

master
Abhishek Banthia 2 years ago
parent
commit
f93959c927
  1. 7
      Clocker/Clocker/LocationController.swift
  2. 4
      Clocker/Onboarding/Onboarding.storyboard
  3. 30
      Clocker/Onboarding/OnboardingPermissionsViewController.swift

7
Clocker/Clocker/LocationController.swift

@ -5,9 +5,14 @@ import CoreLocation
import CoreLoggerKit import CoreLoggerKit
import CoreModelKit import CoreModelKit
protocol LocationControllerDelegate: NSObject {
func didChangeAuthorizationStatus()
}
class LocationController: NSObject { class LocationController: NSObject {
private let store: DataStore private let store: DataStore
private static var sharedController = LocationController(withStore: DataStore.shared()) private static var sharedController = LocationController(withStore: DataStore.shared())
weak var delegate: LocationControllerDelegate?
init(withStore dataStore: DataStore) { init(withStore dataStore: DataStore) {
store = dataStore store = dataStore
@ -33,6 +38,7 @@ class LocationController: NSObject {
} }
func locationAccessGranted() -> Bool { func locationAccessGranted() -> Bool {
print("Location Status is ", CLLocationManager.authorizationStatus().rawValue.description)
return CLLocationManager.authorizationStatus() == .authorizedAlways || CLLocationManager.authorizationStatus() == .authorized return CLLocationManager.authorizationStatus() == .authorizedAlways || CLLocationManager.authorizationStatus() == .authorized
} }
@ -120,6 +126,7 @@ extension LocationController: CLLocationManagerDelegate {
} else if status == .notDetermined || status == .authorized || status == .authorizedAlways { } else if status == .notDetermined || status == .authorized || status == .authorizedAlways {
locationManager.startUpdatingLocation() locationManager.startUpdatingLocation()
} }
delegate?.didChangeAuthorizationStatus()
} }
func locationManager(_: CLLocationManager, didFailWithError error: Error) { func locationManager(_: CLLocationManager, didFailWithError error: Error) {

4
Clocker/Onboarding/Onboarding.storyboard

@ -189,7 +189,7 @@ DQ
</connections> </connections>
</button> </button>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="749" translatesAutoresizingMaskIntoConstraints="NO" id="gHR-Pd-9pP"> <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="749" translatesAutoresizingMaskIntoConstraints="NO" id="gHR-Pd-9pP">
<rect key="frame" x="8" y="5" width="370" height="22"/> <rect key="frame" x="8" y="5" width="370" height="27"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" placeholderString="Reminder Access Detail" id="zbc-CH-UBI"> <textFieldCell key="cell" sendsActionOnEndEditing="YES" placeholderString="Reminder Access Detail" id="zbc-CH-UBI">
<font key="font" size="12" name="Avenir-Book"/> <font key="font" size="12" name="Avenir-Book"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -201,7 +201,7 @@ DQ
</progressIndicator> </progressIndicator>
</subviews> </subviews>
<constraints> <constraints>
<constraint firstItem="gHR-Pd-9pP" firstAttribute="top" secondItem="Lef-GT-zuM" secondAttribute="bottom" constant="15" id="1ke-VP-hq5"/> <constraint firstItem="gHR-Pd-9pP" firstAttribute="top" secondItem="Lef-GT-zuM" secondAttribute="bottom" constant="10" id="1ke-VP-hq5"/>
<constraint firstItem="Lef-GT-zuM" firstAttribute="leading" secondItem="mF9-1w-sxR" secondAttribute="leading" constant="10" id="2Re-VO-tfj"/> <constraint firstItem="Lef-GT-zuM" firstAttribute="leading" secondItem="mF9-1w-sxR" secondAttribute="leading" constant="10" id="2Re-VO-tfj"/>
<constraint firstItem="gHR-Pd-9pP" firstAttribute="leading" secondItem="mF9-1w-sxR" secondAttribute="leading" constant="10" id="B1U-lb-GUc"/> <constraint firstItem="gHR-Pd-9pP" firstAttribute="leading" secondItem="mF9-1w-sxR" secondAttribute="leading" constant="10" id="B1U-lb-GUc"/>
<constraint firstItem="Lef-GT-zuM" firstAttribute="top" secondItem="mF9-1w-sxR" secondAttribute="top" constant="10" id="S18-SM-uCW"/> <constraint firstItem="Lef-GT-zuM" firstAttribute="top" secondItem="mF9-1w-sxR" secondAttribute="top" constant="10" id="S18-SM-uCW"/>

30
Clocker/Onboarding/OnboardingPermissionsViewController.swift

@ -42,16 +42,13 @@ class OnboardingPermissionsViewController: NSViewController {
} }
private func setup() { private func setup() {
appLabel.stringValue = NSLocalizedString("Permissions Tab", appLabel.stringValue = NSLocalizedString("Permissions Tab", comment: "Title for Permissions screen")
comment: "Title for Permissions screen")
onboardingTypeLabel.stringValue = "Your data doesn't leave your device 🔐" onboardingTypeLabel.stringValue = "Your data doesn't leave your device 🔐"
reminderHeaderLabel.stringValue = NSLocalizedString("Reminders Access Title", reminderHeaderLabel.stringValue = NSLocalizedString("Reminders Access Title",comment: "Title for Reminders Access Label")
comment: "Title for Reminders Access Label") reminderDetailLabel.stringValue = "Set reminders in the timezone of the location of your choice."
reminderDetailLabel.stringValue = "Set reminders in the timezone of the location of your choice. Your reminders are stored in the default Reminders app. "
calendarHeaderLabel.stringValue = NSLocalizedString("Calendar Access Title", calendarHeaderLabel.stringValue = NSLocalizedString("Calendar Access Title",comment: "Title for Calendar access label")
comment: "Title for Calendar access label")
calendarDetailLabel.stringValue = "Calendar Detail".localized() calendarDetailLabel.stringValue = "Calendar Detail".localized()
locationHeaderLabel.stringValue = "Location Access" locationHeaderLabel.stringValue = "Location Access"
@ -160,6 +157,7 @@ class OnboardingPermissionsViewController: NSViewController {
@IBAction func locationAction(_: NSButton) { @IBAction func locationAction(_: NSButton) {
let locationController = LocationController.shared() let locationController = LocationController.shared()
if locationController.locationAccessNotDetermined() { if locationController.locationAccessNotDetermined() {
locationController.delegate = self
locationActivityIndicator.startAnimation(nil) locationActivityIndicator.startAnimation(nil)
locationController.determineAndRequestLocationAuthorization() locationController.determineAndRequestLocationAuthorization()
} else if locationController.locationAccessDenied() { } else if locationController.locationAccessDenied() {
@ -167,6 +165,24 @@ class OnboardingPermissionsViewController: NSViewController {
} else if locationController.locationAccessGranted() { } else if locationController.locationAccessGranted() {
locationGrantButton.title = "Granted".localized() 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()
} }
} }

Loading…
Cancel
Save