Commit 4d515dda by Demid Merzlyakov

Fix weather updates for the default location.

parent 2c5ac8c1
......@@ -20,9 +20,17 @@ public class LocationManager {
private let deviceLocationMonitor: DeviceLocationMonitor
private let weatherUpdateSource: WeatherSource
private let defaultLocation = Location(deviceLocation: false,
private var defaultLocation = Location(deviceLocation: false,
coordinates: .init(latitude: 37.3230, longitude: -122.0322), // Cupertino
timeZone: TimeZone(abbreviation: "PST")!)
timeZone: TimeZone(abbreviation: "PST")!) {
didSet {
if locations.count == 0 {
self.delegates.invoke { (delegate) in
delegate.locationManager(self, changedSelectedLocation: defaultLocation)
}
}
}
}
public enum LocationRequestResult {
/// User provided us with location permissions, we can use the current location.
......@@ -150,10 +158,16 @@ public class LocationManager {
}
DispatchQueue.main.async {
self.log.info("Update weather finished for location: \(location)")
if let indexToUpdate = self.locations.firstIndex(where: { $0 == updatedLocation }) {
self.locations[indexToUpdate] = updatedLocation
}
else if self.defaultLocation == updatedLocation {
self.defaultLocation = self.defaultLocation.mergedWith(incrementalChanges: updatedLocation)
}
else {
self.log.warning("Update weather: Failed to find location after update. Maybe it was deleted while the update was performed. Maybe something went wrong. Location: \(updatedLocation)")
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment