Commit dd5b89b8 by Demid Merzlyakov

IOS-22: Strong wind smart text.

parent 5e0ea178
...@@ -152,6 +152,10 @@ public enum WindDirection: String, Codable, CaseIterable { ...@@ -152,6 +152,10 @@ public enum WindDirection: String, Codable, CaseIterable {
return 337.5 return 337.5
} }
} }
var fullLocalized: String {
return ("wind.direction." + self.rawValue).localized()
}
} }
......
...@@ -14,6 +14,9 @@ private enum Macro: String { ...@@ -14,6 +14,9 @@ private enum Macro: String {
case expectedPrecipitationHour = "#EXPECTED_PRECIPITATION_HOUR#" case expectedPrecipitationHour = "#EXPECTED_PRECIPITATION_HOUR#"
case expectedPrecipitationProbability = "#EXPECTED_PRECIPITATION_PROBABILITY#" case expectedPrecipitationProbability = "#EXPECTED_PRECIPITATION_PROBABILITY#"
case expectedPrecipitationWeatherType = "#EXPECTED_PRECIPITATION_WEATHER_TYPE#" case expectedPrecipitationWeatherType = "#EXPECTED_PRECIPITATION_WEATHER_TYPE#"
case windType = "#WIND_TYPE#"
case windSpeed = "#WIND_SPEED#"
case windDirection = "#WIND_DIRECTION#"
static let hourFormatter: DateFormatter = { static let hourFormatter: DateFormatter = {
let dateFormatter = DateFormatter() let dateFormatter = DateFormatter()
...@@ -29,6 +32,27 @@ private enum Macro: String { ...@@ -29,6 +32,27 @@ private enum Macro: String {
} }
} }
func windType(from windSpeed: WindSpeed) -> String? {
let speedKPH = windSpeed.converted(to: .kilometersPerHour).value
guard speedKPH >= 75 else {
return nil
}
var windType: String = ""
if speedKPH < 89 {
windType = "strongGale"
}
else if speedKPH < 103 {
windType = "storm"
}
else if speedKPH < 118 {
windType = "violentStorm"
}
else {
windType = "hurricane"
}
return ("wind.type." + windType).localized()
}
func string(from location: Location) -> String? { func string(from location: Location) -> String? {
switch self { switch self {
case .feelsLikeTemp: case .feelsLikeTemp:
...@@ -75,6 +99,15 @@ private enum Macro: String { ...@@ -75,6 +99,15 @@ private enum Macro: String {
return nil return nil
} }
return expectedPrecipitationHour.type.localized(isDay: expectedPrecipitationHour.isDay) return expectedPrecipitationHour.type.localized(isDay: expectedPrecipitationHour.isDay)
case .windType:
guard let windSpeed = location.today?.windSpeed else {
return nil
}
return windType(from: windSpeed)
case .windSpeed:
return location.today?.windSpeed?.settingsConverted.string
case .windDirection:
return location.today?.windDirection?.fullLocalized
} }
} }
} }
...@@ -141,10 +174,26 @@ fileprivate struct ApproachingPrecipitationSmartText: SmartText { ...@@ -141,10 +174,26 @@ fileprivate struct ApproachingPrecipitationSmartText: SmartText {
} }
} }
fileprivate struct StrongWindSmartText: SmartText {
let templateKey: String = "today.smart.strongWind"
let requiredMacros: [Macro] = [.windType, .windSpeed, .windDirection]
func applicable(to location: Location) -> Bool {
guard let today = location.today else {
return false
}
guard let windSpeed = today.windSpeed, let _ = today.windDirection else {
return false
}
return windSpeed.converted(to: .kilometersPerHour).value >= 75
}
}
class SmartTextProvider { class SmartTextProvider {
private var prioritizedSmartTexts: [SmartText] = [ private var prioritizedSmartTexts: [SmartText] = [
OngoingPrecipitationSmartText(), OngoingPrecipitationSmartText(),
ApproachingPrecipitationSmartText(), ApproachingPrecipitationSmartText(),
StrongWindSmartText(),
//Continue adding here. //Continue adding here.
DefaultSmartText()] DefaultSmartText()]
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
"today.smart.default" = "Feels like #FEELS_LIKE_TEMP#."; "today.smart.default" = "Feels like #FEELS_LIKE_TEMP#.";
"today.smart.ongoingPrecipitation" = "#WEATHER_TYPE# until #WEATHER_TYPE_CHANGE_HOUR#."; "today.smart.ongoingPrecipitation" = "#WEATHER_TYPE# until #WEATHER_TYPE_CHANGE_HOUR#.";
"today.smart.approachingPrecipitation" = "#EXPECTED_PRECIPITATION_PROBABILITY#% chance of #EXPECTED_PRECIPITATION_WEATHER_TYPE# by #EXPECTED_PRECIPITATION_HOUR#."; "today.smart.approachingPrecipitation" = "#EXPECTED_PRECIPITATION_PROBABILITY#% chance of #EXPECTED_PRECIPITATION_WEATHER_TYPE# by #EXPECTED_PRECIPITATION_HOUR#.";
"today.smart.strongWind" = "#WIND_TYPE# - #WIND_SPEED# blowing from #WIND_DIRECTION#.";
//Forecast //Forecast
"forecast.sunny" = "Sunny"; "forecast.sunny" = "Sunny";
...@@ -233,3 +234,27 @@ ...@@ -233,3 +234,27 @@
"inapp.restoration.error.no.purchases" = "There are no purchases to restore"; "inapp.restoration.error.no.purchases" = "There are no purchases to restore";
"inapp.upgrade.to.pro.title" = "1Weather Pro"; "inapp.upgrade.to.pro.title" = "1Weather Pro";
"inapp.upgrade.to.pro.text" = "The same great experience without the ads for only $1.99!"; "inapp.upgrade.to.pro.text" = "The same great experience without the ads for only $1.99!";
// Wind
"wind.direction.N" = "North";
"wind.direction.NNE" = "North North East";
"wind.direction.NE" = "North East";
"wind.direction.ENE" = "East North East";
"wind.direction.E" = "East";
"wind.direction.ESE" = "East South East";
"wind.direction.SE" = "South East";
"wind.direction.SSE" = "South South East";
"wind.direction.S" = "South";
"wind.direction.SSW" = "South South West";
"wind.direction.SW" = "South West";
"wind.direction.WSW" = "West South West";
"wind.direction.W" = "West";
"wind.direction.WNW" = "West North West";
"wind.direction.NW" = "North West";
"wind.direction.NNW" = "North North West";
// Wind type
"wind.type.strongGale" = "Strong gale";
"wind.type.storm" = "Storm";
"wind.type.violentStorm" = "Violent storm";
"wind.type.hurricane" = "Hurricane";
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