Commit c4d1d047 by Demid Merzlyakov

Day / Night support for weather type.

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