Commit de2c40ad by Demid Merzlyakov

Forecase wind: update on settings change. Update on city change.

parent ec8f9db9
...@@ -43,9 +43,7 @@ class ForecastWindSpeedCell: UITableViewCell { ...@@ -43,9 +43,7 @@ class ForecastWindSpeedCell: UITableViewCell {
//Public //Public
public func configure(with hourly:[HourlyWeather]) { public func configure(with hourly:[HourlyWeather]) {
self.timePeriodView.set(daily: nil, hourly: hourly) self.timePeriodView.set(daily: nil, hourly: hourly)
if self.timePeriodView.isEmpty { self.timePeriodView.set(forecastType: .wind, buttonType: ForecastWindButton.self)
self.timePeriodView.set(forecastType: .wind, buttonType: ForecastWindButton.self)
}
} }
} }
......
...@@ -248,6 +248,7 @@ extension ForecastViewController: ForecastViewModelDelegate { ...@@ -248,6 +248,7 @@ extension ForecastViewController: ForecastViewModelDelegate {
func selectedWeatherDidChange() { func selectedWeatherDidChange() {
DispatchQueue.main.async { DispatchQueue.main.async {
self.forecastCellFactory.setNeedsUpdate()
self.forecastCellFactory.selectedWeatherDidChange() self.forecastCellFactory.selectedWeatherDidChange()
self.daysControlView.selectDayAt(index: self.viewModel.selectedDailyWeatherIndex) self.daysControlView.selectDayAt(index: self.viewModel.selectedDailyWeatherIndex)
self.tableView.reloadData() self.tableView.reloadData()
......
...@@ -34,12 +34,14 @@ class ForecastViewModel: ViewModelProtocol { ...@@ -34,12 +34,14 @@ class ForecastViewModel: ViewModelProtocol {
private var locationManager: LocationManager private var locationManager: LocationManager
deinit { deinit {
Settings.shared.delegate.remove(delegate: self)
self.locationManager.remove(delegate: self) self.locationManager.remove(delegate: self)
} }
public init(locationManager: LocationManager) { public init(locationManager: LocationManager) {
self.locationManager = locationManager self.locationManager = locationManager
locationManager.add(delegate: self) locationManager.add(delegate: self)
Settings.shared.delegate.add(delegate: self)
} }
public func updateWeather() { public func updateWeather() {
...@@ -83,3 +85,13 @@ extension ForecastViewModel: LocationManagerDelegate { ...@@ -83,3 +85,13 @@ extension ForecastViewModel: LocationManagerDelegate {
// do nothing // do nothing
} }
} }
//MARK:- Settings Delegate
extension ForecastViewModel: SettingsDelegate {
func settingsDidChange() {
onMain {
self.delegate?.viewModelDidChange(model: self)
}
}
}
...@@ -122,7 +122,7 @@ extension TodayViewModel: LocationManagerDelegate { ...@@ -122,7 +122,7 @@ extension TodayViewModel: LocationManagerDelegate {
} }
} }
//MARK:- Settings View Model //MARK:- Settings Delegate
extension TodayViewModel: SettingsDelegate { extension TodayViewModel: SettingsDelegate {
func settingsDidChange() { func settingsDidChange() {
delegate?.viewModelDidChange(model: 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