Commit 2c5ac8c1 by Demid Merzlyakov

Fix current location deletion.

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