Commit 2c5ac8c1 by Demid Merzlyakov

Fix current location deletion.

parent c7d6b24e
...@@ -225,12 +225,12 @@ extension DeviceLocationMonitor: CLLocationManagerDelegate { ...@@ -225,12 +225,12 @@ extension DeviceLocationMonitor: CLLocationManagerDelegate {
guard let clError = error as? CLError else { return } guard let clError = error as? CLError else { return }
switch clError { switch clError {
case CLError.denied: case CLError.denied:
log.error("error: user denied access") log.error("User denied access")
DispatchQueue.main.async { DispatchQueue.main.async {
self.delegate?.deviceLocationMonitor(self, authorizationStatusChanged: false) self.delegate?.deviceLocationMonitor(self, authorizationStatusChanged: false)
} }
default: default:
log.error("error: \(error)") log.error("Unknown error: \(error)")
} }
} }
} }
...@@ -39,7 +39,6 @@ public class LocationManager { ...@@ -39,7 +39,6 @@ public class LocationManager {
didSet { didSet {
log.info("Locations list updated: \(locations.map { $0.description }.joined(separator: ", "))") log.info("Locations list updated: \(locations.map { $0.description }.joined(separator: ", "))")
let newValue = locations let newValue = locations
DispatchQueue.main.async {
if let selectedIndex = self.selectedLocationIndex, selectedIndex >= newValue.count { if let selectedIndex = self.selectedLocationIndex, selectedIndex >= newValue.count {
self.selectedLocationIndex = newValue.count > 0 ? 0 : nil self.selectedLocationIndex = newValue.count > 0 ? 0 : nil
} }
...@@ -55,7 +54,6 @@ public class LocationManager { ...@@ -55,7 +54,6 @@ public class LocationManager {
} }
} }
}
private var selectedLocationIndex: Int? { private var selectedLocationIndex: Int? {
didSet { didSet {
...@@ -304,12 +302,16 @@ public class LocationManager { ...@@ -304,12 +302,16 @@ public class LocationManager {
// MARK: - DeviceLocationMonitorDelegate implementation // MARK: - DeviceLocationMonitorDelegate implementation
extension LocationManager: DeviceLocationMonitorDelegate { extension LocationManager: DeviceLocationMonitorDelegate {
func deviceLocationMonitor(_ monitor: DeviceLocationMonitor, didUpdateLocation newLocation: PartialLocation) { func deviceLocationMonitor(_ monitor: DeviceLocationMonitor, didUpdateLocation newLocation: PartialLocation) {
log.debug("device location updated: (\(newLocation.lat ?? "-"); \(newLocation.lon ?? "-"))")
addIfNeeded(partialLocation: newLocation, selectLocation: false) addIfNeeded(partialLocation: newLocation, selectLocation: false)
} }
func deviceLocationMonitor(_ monitor: DeviceLocationMonitor, authorizationStatusChanged locationIsAllowed: Bool) { func deviceLocationMonitor(_ monitor: DeviceLocationMonitor, authorizationStatusChanged locationIsAllowed: Bool) {
if !locationIsAllowed && locations.first?.deviceLocation == true { DispatchQueue.main.async {
locations = [Location](locations.suffix(from: 1)) if !locationIsAllowed && self.locations.first?.deviceLocation == true {
self.log.debug("device location: remove due to error")
self.locations = [Location](self.locations.suffix(from: 1))
}
} }
} }
} }
...@@ -241,7 +241,7 @@ extension LocationViewController: LocationsViewModelDelegate { ...@@ -241,7 +241,7 @@ extension LocationViewController: LocationsViewModelDelegate {
} }
} }
//MARK: UItableView Data Source //MARK: - UItableView Data Source
extension LocationViewController: UITableViewDataSource { extension LocationViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return locationsViewModel.cities.count return locationsViewModel.cities.count
...@@ -281,7 +281,7 @@ extension LocationViewController: UITableViewDataSource { ...@@ -281,7 +281,7 @@ extension LocationViewController: UITableViewDataSource {
} }
} }
//MARK: UITableView Delegate //MARK: - UITableView Delegate
extension LocationViewController: UITableViewDelegate { extension LocationViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let container = UIView() let container = UIView()
......
...@@ -226,6 +226,7 @@ public class LocationsViewModel { ...@@ -226,6 +226,7 @@ public class LocationsViewModel {
} }
} }
// MARK: - LocationManagerDelegate implementation
extension LocationsViewModel: LocationManagerDelegate { extension LocationsViewModel: LocationManagerDelegate {
public func locationManager(_ locationManager: LocationManager, changedSelectedLocation newLocation: Location?) { public func locationManager(_ locationManager: LocationManager, changedSelectedLocation newLocation: Location?) {
DispatchQueue.main.async { DispatchQueue.main.async {
...@@ -237,7 +238,6 @@ extension LocationsViewModel: LocationManagerDelegate { ...@@ -237,7 +238,6 @@ extension LocationsViewModel: LocationManagerDelegate {
} }
public func locationManager(_ locationManager: LocationManager, updatedLocationsList newList: [Location]) { public func locationManager(_ locationManager: LocationManager, updatedLocationsList newList: [Location]) {
self.delegate?.viewModelDidChange(model: self)
DispatchQueue.main.async { DispatchQueue.main.async {
self.delegate?.viewModelDidChange(model: self) self.delegate?.viewModelDidChange(model: self)
} }
......
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