Commit c4d1d047 by Demid Merzlyakov

Day / Night support for weather type.

parent 76f74ba9
...@@ -6,14 +6,13 @@ ...@@ -6,14 +6,13 @@
// //
import Foundation import Foundation
import UIKit
public enum WeatherType: String, CaseIterable { public enum WeatherType: String, CaseIterable {
case clearDay = "clearDay" case clear = "clear"
case partlyCloudyDay = "partlyCloudyDay" case partlyCloudy = "partlyCloudy"
case snowyDay = "snowyDay" case snowy = "snowy"
case snowyNight = "snowyNight" case mostlyCloudy = "mostlyCloudy"
case clearNight = "clearNight"
case partlyCloudyNight = "partlyCloudyNight"
case thunderstorm = "thunderstorm" case thunderstorm = "thunderstorm"
case heavySnow = "heavySnow" case heavySnow = "heavySnow"
case lightSnow = "lightSnow" case lightSnow = "lightSnow"
...@@ -23,58 +22,31 @@ public enum WeatherType: String, CaseIterable { ...@@ -23,58 +22,31 @@ public enum WeatherType: String, CaseIterable {
case blowingDust = "blowingDust" case blowingDust = "blowingDust"
case haze = "haze" case haze = "haze"
case lightFog = "lightFog" case lightFog = "lightFog"
case mostlyCloudyDay = "mostlyCloudyDay"
case mostlyCloudyNight = "mostlyCloudyNight"
case lightDrizzle = "lightDrizzle" case lightDrizzle = "lightDrizzle"
case heavyRain = "heavyRain" case heavyRain = "heavyRain"
case smoke = "smoke" case smoke = "smoke"
case unknown = "unknown" case unknown = "unknown"
var localized:String { public func localized(isDay: Bool) -> String {
switch self { return "forecast.\(self.stringId(isDay: isDay).localized())"
case .clearDay: }
return "forecast.clear".localized()
case .partlyCloudyDay: public func image(isDay: Bool) -> UIImage {
return "forecast.cloudy".localized() guard let result = UIImage(named: self.stringId(isDay: isDay)) else {
case .snowyDay: assertionFailure("Image is missing for WeatherType \(self)")
return "forecast.snowyDay".localized() return UIImage()
case .snowyNight: }
return "forecast.snowyNight".localized() return result
case .clearNight: }
return "forecast.clearNight".localized()
case .partlyCloudyNight: private static let dayNightCustomizable: Set<WeatherType> = Set<WeatherType>(arrayLiteral: .clear, .partlyCloudy, .snowy, .mostlyCloudy)
return "forecast.partlyCloudyNight".localized()
case .thunderstorm: private func stringId(isDay: Bool) -> String {
return "forecast.thunderstorm".localized() var stringId = self.rawValue
case .heavySnow: if WeatherType.dayNightCustomizable.contains(self) {
return "forecast.heavySnow".localized() stringId += isDay ? "Day" : "Night"
case .lightSnow:
return "forecast.lightSnow".localized()
case .freezingRain:
return "forecast.freezingRain".localized()
case .freezingFog:
return "forecast.freezingFog".localized()
case .lightHail:
return "forecast.lightHail".localized()
case .blowingDust:
return "forecast.blowingDust".localized()
case .haze:
return "forecast.haze".localized()
case .lightFog:
return "forecast.lightFog".localized()
case .mostlyCloudyDay:
return "forecast.mostlyCloudyDay".localized()
case .mostlyCloudyNight:
return "forecast.mostlyCloudyNight".localized()
case .lightDrizzle:
return "forecast.lightDrizzle".localized()
case .heavyRain:
return "forecast.heavyRain".localized()
case .smoke:
return "forecast.smoke".localized()
case .unknown:
return "forecast.unknown".localized()
} }
return stringId
} }
} }
......
...@@ -81,8 +81,7 @@ enum WdtWeatherCode: String, Codable { ...@@ -81,8 +81,7 @@ enum WdtWeatherCode: String, Codable {
case .lightFog, .patchyFog, .fog: case .lightFog, .patchyFog, .fog:
return .lightFog return .lightFog
case .squall, .driftingSnow, .blowingSnow: case .squall, .driftingSnow, .blowingSnow:
return .snowyDay return .snowy
//TODO: handle snowyNight
case .freezingFog: case .freezingFog:
return .freezingFog return .freezingFog
case .lightDrizzle, .drizzle, .heavyDrizzle, .lightRain, .lightRainShower: case .lightDrizzle, .drizzle, .heavyDrizzle, .lightRain, .lightRainShower:
...@@ -97,26 +96,19 @@ enum WdtWeatherCode: String, Codable { ...@@ -97,26 +96,19 @@ enum WdtWeatherCode: String, Codable {
case .lightSnow, .lightSnowShower: case .lightSnow, .lightSnowShower:
return .lightSnow return .lightSnow
case .snow, .snowShower: case .snow, .snowShower:
//TODO: handle snowyNight return .snowy
return .snowyDay
case .heavySnow: case .heavySnow:
return .heavySnow return .heavySnow
case .lightHail, .hail: case .lightHail, .hail:
return .lightHail return .lightHail
case .thunderstorm, .heavyThunderstorm: case .thunderstorm, .heavyThunderstorm:
return .thunderstorm return .thunderstorm
// isDay ? "ic_static_sunny" : "ic_static_clear_night"
case .clear: case .clear:
//TODO: handle clear night return .clear
return .clearDay
// isDay ? "ic_static_partly_cloudy" : "ic_static_partly_cloudy_night"
case .mostlyClear, .partlyCloudy: case .mostlyClear, .partlyCloudy:
// TODO: handle partly cloudy night return .partlyCloudy
return .partlyCloudyDay
// isDay ? "ic_static_heavy_cloudy" : "ic_static_heavy_cloudy_night"
case .mostlyCloudy, .overcast: case .mostlyCloudy, .overcast:
//TODO: handle mostly cloudy night return .mostlyCloudy
return .mostlyCloudyDay
} }
} }
} }
...@@ -30,7 +30,7 @@ class DayTimeView: UIView { ...@@ -30,7 +30,7 @@ class DayTimeView: UIView {
public func configure(with dayTimeWeather:DayTimeWeather) { public func configure(with dayTimeWeather:DayTimeWeather) {
dayTimeLabel.text = dayTimeWeather.dayTime.localized dayTimeLabel.text = dayTimeWeather.dayTime.localized
forecastImageView.image = UIImage(named: dayTimeWeather.type.rawValue) forecastImageView.image = dayTimeWeather.type.image(isDay: dayTimeWeather.isDay)
tempLabel.text = dayTimeWeather.temp?.shortString ?? "--" tempLabel.text = dayTimeWeather.temp?.shortString ?? "--"
} }
} }
......
...@@ -39,9 +39,9 @@ class CityForecastCell: UITableViewCell { ...@@ -39,9 +39,9 @@ class CityForecastCell: UITableViewCell {
let maxTemp = location.today?.maxTemp?.shortString ?? "--" let maxTemp = location.today?.maxTemp?.shortString ?? "--"
let minTemp = location.today?.minTemp?.shortString ?? "--" let minTemp = location.today?.minTemp?.shortString ?? "--"
let feelstemp = location.today?.apparentTemp?.shortString ?? "--" let feelstemp = location.today?.apparentTemp?.shortString ?? "--"
forecastDescriptionLabel.text = "\(location.today?.type.localized ?? "") | \(maxTemp)/\(minTemp)" forecastDescriptionLabel.text = "\(location.today?.type.localized(isDay: location.today?.isDay ?? true) ?? "") | \(maxTemp)/\(minTemp)"
feelsLikeLabel.text = "Feels like \(feelstemp) - Due to high humidity" feelsLikeLabel.text = "Feels like \(feelstemp) - Due to high humidity"
forecastImageView.image = UIImage(named: location.today?.type.rawValue ?? "") forecastImageView.image = location.today?.type.image(isDay: location.today?.isDay ?? true)
} }
} }
......
...@@ -84,7 +84,7 @@ class PeriodForecastButton: UIControl { ...@@ -84,7 +84,7 @@ class PeriodForecastButton: UIControl {
self.tempLabel.text = dailyWeather.maxTemp?.shortString self.tempLabel.text = dailyWeather.maxTemp?.shortString
self.minTempLabel.text = dailyWeather.minTemp?.shortString self.minTempLabel.text = dailyWeather.minTemp?.shortString
self.indicatorImageView.image = nil self.indicatorImageView.image = nil
self.forecastImageView.image = UIImage(named: dailyWeather.type.rawValue) self.forecastImageView.image = dailyWeather.type.image(isDay: true)
if Calendar.current.isDateInToday(dailyWeather.date) { if Calendar.current.isDateInToday(dailyWeather.date) {
self.timeLabel.text = "day.today".localized() self.timeLabel.text = "day.today".localized()
} }
......
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