Commit 76edf32f by Demid Merzlyakov

IOS-183: Basic smart texts for minutely forecast.

parent 12ff1437
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
"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.wind" = "#WIND_TYPE# - #WIND_SPEED# blowing from #WIND_DIRECTION#."; "today.smart.wind" = "#WIND_TYPE# - #WIND_SPEED# blowing from #WIND_DIRECTION#.";
"today.smart.humidity" = "Feels like #FEELS_LIKE_TEMP# due to #HUMIDITY_TYPE# humidity (#HUMIDITY#%)."; "today.smart.humidity" = "Feels like #FEELS_LIKE_TEMP# due to #HUMIDITY_TYPE# humidity (#HUMIDITY#%).";
"today.minutely.smart.hottestDay" = "Today is the hottest day of this week";
//Forecast //Forecast
"forecast.sunny" = "Sunny"; "forecast.sunny" = "Sunny";
......
...@@ -151,6 +151,15 @@ class MinutelyForecastView: UIView { ...@@ -151,6 +151,15 @@ class MinutelyForecastView: UIView {
private func updateSmartText() { private func updateSmartText() {
smartTextBackgroundView.backgroundColor = self.forecastType == .temperature ? kSmartTextBackgroundColorTemperature : kSmartTextBackgroundColorPrecipitation smartTextBackgroundView.backgroundColor = self.forecastType == .temperature ? kSmartTextBackgroundColorTemperature : kSmartTextBackgroundColorPrecipitation
smartTextIcon.image = UIImage(named: forecastType == .temperature ? "minutely_smart_text_temperature" : "minutely_smart_text_precipitation") smartTextIcon.image = UIImage(named: forecastType == .temperature ? "minutely_smart_text_temperature" : "minutely_smart_text_precipitation")
let smartTextsToUse: [SmartText]
if forecastType == .temperature {
smartTextsToUse = [HottestDaySmartText()]
}
else {
smartTextsToUse = [ApproachingPrecipitationSmartText()]
}
smartTextProvider = SmartTextProvider(prioritizedSmartTexts: smartTextsToUse)
var smartText = "" var smartText = ""
if let location = self.location { if let location = self.location {
smartText = smartTextProvider.smartText(for: location) smartText = smartTextProvider.smartText(for: location)
......
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
CE72A76A26D676A000F13CF7 /* USOnlyFeatureAvailabilityChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE72A76926D676A000F13CF7 /* USOnlyFeatureAvailabilityChecker.swift */; }; CE72A76A26D676A000F13CF7 /* USOnlyFeatureAvailabilityChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE72A76926D676A000F13CF7 /* USOnlyFeatureAvailabilityChecker.swift */; };
CE72A77026D6917300F13CF7 /* DeviceTypeFeatureAvailabilityChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE72A76F26D6917300F13CF7 /* DeviceTypeFeatureAvailabilityChecker.swift */; }; CE72A77026D6917300F13CF7 /* DeviceTypeFeatureAvailabilityChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE72A76F26D6917300F13CF7 /* DeviceTypeFeatureAvailabilityChecker.swift */; };
CEC363AD26E93EE1009F2607 /* ClosureFeatureAvailabilityChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC363AC26E93EE1009F2607 /* ClosureFeatureAvailabilityChecker.swift */; }; CEC363AD26E93EE1009F2607 /* ClosureFeatureAvailabilityChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC363AC26E93EE1009F2607 /* ClosureFeatureAvailabilityChecker.swift */; };
CEE798FE270DD74700218318 /* HottestDaySmartText.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEE798FD270DD74700218318 /* HottestDaySmartText.swift */; };
CEFE851826948C15003C67D3 /* SmartTextProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFE851726948C15003C67D3 /* SmartTextProvider.swift */; }; CEFE851826948C15003C67D3 /* SmartTextProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFE851726948C15003C67D3 /* SmartTextProvider.swift */; };
CEFE851C2694986D003C67D3 /* SmartText.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFE851B2694986D003C67D3 /* SmartText.swift */; }; CEFE851C2694986D003C67D3 /* SmartText.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFE851B2694986D003C67D3 /* SmartText.swift */; };
CEFE85202694C4BC003C67D3 /* DefaultSmartText.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFE851F2694C4BC003C67D3 /* DefaultSmartText.swift */; }; CEFE85202694C4BC003C67D3 /* DefaultSmartText.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFE851F2694C4BC003C67D3 /* DefaultSmartText.swift */; };
...@@ -210,6 +211,7 @@ ...@@ -210,6 +211,7 @@
CE72A76926D676A000F13CF7 /* USOnlyFeatureAvailabilityChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = USOnlyFeatureAvailabilityChecker.swift; sourceTree = "<group>"; }; CE72A76926D676A000F13CF7 /* USOnlyFeatureAvailabilityChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = USOnlyFeatureAvailabilityChecker.swift; sourceTree = "<group>"; };
CE72A76F26D6917300F13CF7 /* DeviceTypeFeatureAvailabilityChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceTypeFeatureAvailabilityChecker.swift; sourceTree = "<group>"; }; CE72A76F26D6917300F13CF7 /* DeviceTypeFeatureAvailabilityChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceTypeFeatureAvailabilityChecker.swift; sourceTree = "<group>"; };
CEC363AC26E93EE1009F2607 /* ClosureFeatureAvailabilityChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClosureFeatureAvailabilityChecker.swift; sourceTree = "<group>"; }; CEC363AC26E93EE1009F2607 /* ClosureFeatureAvailabilityChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClosureFeatureAvailabilityChecker.swift; sourceTree = "<group>"; };
CEE798FD270DD74700218318 /* HottestDaySmartText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HottestDaySmartText.swift; sourceTree = "<group>"; };
CEFE851726948C15003C67D3 /* SmartTextProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartTextProvider.swift; sourceTree = "<group>"; }; CEFE851726948C15003C67D3 /* SmartTextProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartTextProvider.swift; sourceTree = "<group>"; };
CEFE851B2694986D003C67D3 /* SmartText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartText.swift; sourceTree = "<group>"; }; CEFE851B2694986D003C67D3 /* SmartText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartText.swift; sourceTree = "<group>"; };
CEFE851D2694C477003C67D3 /* SmartTextMacro.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartTextMacro.swift; sourceTree = "<group>"; }; CEFE851D2694C477003C67D3 /* SmartTextMacro.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartTextMacro.swift; sourceTree = "<group>"; };
...@@ -576,6 +578,7 @@ ...@@ -576,6 +578,7 @@
CEFE85232694C5D1003C67D3 /* ApproachingPrecipitationSmartText.swift */, CEFE85232694C5D1003C67D3 /* ApproachingPrecipitationSmartText.swift */,
CEFE85252694C5E4003C67D3 /* WindSmartText.swift */, CEFE85252694C5E4003C67D3 /* WindSmartText.swift */,
CEFE85272694C5F7003C67D3 /* HumiditySmartText.swift */, CEFE85272694C5F7003C67D3 /* HumiditySmartText.swift */,
CEE798FD270DD74700218318 /* HottestDaySmartText.swift */,
); );
path = SmartTexts; path = SmartTexts;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -807,6 +810,7 @@ ...@@ -807,6 +810,7 @@
CD615F9E265526E700B717DB /* Health.swift in Sources */, CD615F9E265526E700B717DB /* Health.swift in Sources */,
CD2D55DE2655377F007B70F4 /* NWSSeverityLevel.swift in Sources */, CD2D55DE2655377F007B70F4 /* NWSSeverityLevel.swift in Sources */,
CD8B659127047ED800343897 /* LossyCodableList.swift in Sources */, CD8B659127047ED800343897 /* LossyCodableList.swift in Sources */,
CEE798FE270DD74700218318 /* HottestDaySmartText.swift in Sources */,
CEC363AD26E93EE1009F2607 /* ClosureFeatureAvailabilityChecker.swift in Sources */, CEC363AD26E93EE1009F2607 /* ClosureFeatureAvailabilityChecker.swift in Sources */,
CD615F9F265526E700B717DB /* AirQuality.swift in Sources */, CD615F9F265526E700B717DB /* AirQuality.swift in Sources */,
CDD2F8EF2665102B00B48322 /* LocationManager.swift in Sources */, CDD2F8EF2665102B00B48322 /* LocationManager.swift in Sources */,
......
...@@ -20,4 +20,6 @@ public struct ApproachingPrecipitationSmartText: SmartText { ...@@ -20,4 +20,6 @@ public struct ApproachingPrecipitationSmartText: SmartText {
} }
return SmartTextMacros.expectedPrecipitation(for: location) != nil return SmartTextMacros.expectedPrecipitation(for: location) != nil
} }
public init() {}
} }
...@@ -16,4 +16,6 @@ public struct DefaultSmartText: SmartText { ...@@ -16,4 +16,6 @@ public struct DefaultSmartText: SmartText {
public func applicable(to location: Location) -> Bool { public func applicable(to location: Location) -> Bool {
true true
} }
public init() {}
} }
//
// HottestDaySmartText.swift
// OneWeatherCore
//
// Created by Demid Merzlyakov on 06.10.2021.
//
import Foundation
public struct HottestDaySmartText: SmartText {
public let templateKey: String = "today.minutely.smart.hottestDay"
public let requiredMacros: [SmartTextMacro] = []
public func applicable(to location: Location) -> Bool {
guard let todayMaxTemp = location.today?.maxTemp else {
return false
}
let oneWeek = TimeInterval(7 * 24 * 3600)
let sevenDaysAhead = location.daily.filter { weather in
let timeUntilDate = weather.date.timeIntervalSince(Date())
return !weather.isToday
&& timeUntilDate > 0
&& timeUntilDate < oneWeek
}
guard sevenDaysAhead.count > 5 else {
return false
}
let dayHotterThanToday = sevenDaysAhead.first {
guard let maxTemp = $0.maxTemp else {
return false
}
return maxTemp > todayMaxTemp
}
return dayHotterThanToday == nil
}
public init() {}
}
...@@ -17,4 +17,6 @@ public struct HumiditySmartText: SmartText { ...@@ -17,4 +17,6 @@ public struct HumiditySmartText: SmartText {
} }
return humidity > 50 || humidity < 30 return humidity > 50 || humidity < 30
} }
public init() {}
} }
...@@ -17,4 +17,6 @@ public struct OngoingPrecipitationSmartText: SmartText { ...@@ -17,4 +17,6 @@ public struct OngoingPrecipitationSmartText: SmartText {
} }
return today.type.isPrecipitation return today.type.isPrecipitation
} }
public init() {}
} }
...@@ -21,4 +21,8 @@ public struct WindSmartText: SmartText { ...@@ -21,4 +21,8 @@ public struct WindSmartText: SmartText {
} }
return windSpeed >= minAllowedWindSpeed return windSpeed >= minAllowedWindSpeed
} }
public init(minAllowedWindSpeed: WindSpeed) {
self.minAllowedWindSpeed = minAllowedWindSpeed
}
} }
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