Commit f8b0819d by Demid Merzlyakov

IOS-22: Basic smart texts structure.

parent 294fc4c2
......@@ -212,6 +212,7 @@
CE578FE625FB415F00E8B85D /* LocationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FE325FB415F00E8B85D /* LocationViewController.swift */; };
CE578FE725FB415F00E8B85D /* LocationsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FE425FB415F00E8B85D /* LocationsViewModel.swift */; };
CE6BE4942634170800626822 /* USStateCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6BE4932634170800626822 /* USStateCode.swift */; };
CE6F5F0C263C8B3D00973137 /* SmartTextProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6F5F0B263C8B3C00973137 /* SmartTextProvider.swift */; };
CE849DB82638C33600DEFFBD /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE849DB72638C33600DEFFBD /* NotificationService.swift */; };
CE849DBC2638C33600DEFFBD /* OneWeatherNotificationServiceExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = CE849DB52638C33600DEFFBD /* OneWeatherNotificationServiceExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
CE849E382638CE8000DEFFBD /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE849E372638CE8000DEFFBD /* UserNotifications.framework */; };
......@@ -539,6 +540,7 @@
CE578FE325FB415F00E8B85D /* LocationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationViewController.swift; sourceTree = "<group>"; };
CE578FE425FB415F00E8B85D /* LocationsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationsViewModel.swift; sourceTree = "<group>"; };
CE6BE4932634170800626822 /* USStateCode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = USStateCode.swift; sourceTree = "<group>"; };
CE6F5F0B263C8B3C00973137 /* SmartTextProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartTextProvider.swift; sourceTree = "<group>"; };
CE849DB52638C33600DEFFBD /* OneWeatherNotificationServiceExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = OneWeatherNotificationServiceExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
CE849DB72638C33600DEFFBD /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
CE849DB92638C33600DEFFBD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
......@@ -1478,6 +1480,7 @@
CD37D3EA260DD30F002669D6 /* Settings.swift */,
CE6BE4932634170800626822 /* USStateCode.swift */,
CE895F0E26393FD800214175 /* WeatherImageProvider.swift */,
CE6F5F0B263C8B3C00973137 /* SmartTextProvider.swift */,
);
path = Model;
sourceTree = "<group>";
......@@ -2127,6 +2130,7 @@
CD86245E25E646350097F3FB /* SunUvView.swift in Sources */,
CDF8F12D26208E7B00DB384A /* MapCurrentTimeView.swift in Sources */,
CEAFF08325DFC67F00DF4EBF /* Location.swift in Sources */,
CE6F5F0C263C8B3D00973137 /* SmartTextProvider.swift in Sources */,
CEC7D8EE2639FE2700B8836D /* OLInAppStoreManager.swift in Sources */,
CDECDB052629A6600087F9F2 /* RadarLayer.swift in Sources */,
CEFB857226174F7A00C5CDD2 /* Storage.swift in Sources */,
......
//
// SmartTextProvider.swift
// 1Weather
//
// Created by Demid Merzlyakov on 01.05.2021.
//
import Foundation
private enum Macro: String {
case feelsLikeTemp = "#FEELS_LIKE_TEMP"
func string(from location: Location) -> String {
switch self {
case .feelsLikeTemp:
return location.today?.apparentTemp?.settingsConverted.shortString ?? "--"
}
}
}
fileprivate protocol SmartText {
var templateKey: String { get }
var requiredMacros: [Macro] { get }
func applicable(to: Location) -> Bool
func buildText(for location: Location) -> String
}
fileprivate extension SmartText {
func buildText(for location: Location) -> String {
var result = self.templateKey.localized()
for macro in requiredMacros {
result = result.replacingOccurrences(of: macro.rawValue, with: macro.string(from: location))
}
return result
}
}
fileprivate struct DefaultSmartText: SmartText {
let templateKey = "today.smart.default"
var requiredMacros: [Macro] = [.feelsLikeTemp]
func applicable(to: Location) -> Bool {
true
}
}
class SmartTextProvider {
private var prioritizedSmartTexts: [SmartText] = [DefaultSmartText()]
public func smartText(for location: Location) -> String {
var result = ""
for candidate in prioritizedSmartTexts {
if candidate.applicable(to: location) {
result = candidate.buildText(for: location)
break
}
}
return result
}
}
......@@ -35,6 +35,8 @@
"privacy.notice.text" = "You can modify your choices at any time as per our Privacy Policy, and use this app without sharing your location. We utilise location data to deliver forecasts, weather alerts & ads. We may share your data with trusted partners to provide you these services.";
"privacy.notice.close" = "Close";
//Today Smart Text
"today.smart.default" = "Feels like #FEELS_LIKE_TEMP.";
//Forecast
"forecast.sunny" = "Sunny";
......
......@@ -16,6 +16,7 @@ class TodayForecastCell: UITableViewCell {
private let forecastDescriptionLabel = UILabel()
private let feelsLikeLabel = UILabel()
private let forecastImageView = UIImageView()
private let smartTextProvider = SmartTextProvider()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
......@@ -47,7 +48,7 @@ class TodayForecastCell: UITableViewCell {
let minTemp = location.today?.minTemp?.settingsConverted.shortString ?? "--"
let feelstemp = location.today?.apparentTemp?.settingsConverted.shortString ?? "--"
forecastDescriptionLabel.text = "\(location.today?.type.localized(isDay: location.today?.isDay ?? true) ?? "") | \(maxTemp)/\(minTemp)"
feelsLikeLabel.text = "Feels like \(feelstemp) - Due to high humidity"
feelsLikeLabel.text = smartTextProvider.smartText(for: location)
forecastImageView.image = location.today?.type.image(isDay: location.today?.isDay ?? true)
}
......
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