Commit fb670756 by Demid Merzlyakov

UV-index: work in progress.

parent bc167948
......@@ -19,6 +19,7 @@
87DE8C81263BFBCE00E1C8D4 /* LegacyMigrationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87DE8C80263BFBCE00E1C8D4 /* LegacyMigrationManager.swift */; };
87DE8CB2263C09BA00E1C8D4 /* LegacyWdtLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87DE8CB1263C09BA00E1C8D4 /* LegacyWdtLocation.swift */; };
87DE8CF4263C267B00E1C8D4 /* LegacySettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87DE8CF3263C267B00E1C8D4 /* LegacySettings.swift */; };
87DE8D01263C4ADD00E1C8D4 /* WdtHealth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87DE8D00263C4ADD00E1C8D4 /* WdtHealth.swift */; };
C27F92C189A9C9E637AF6C3A /* Pods_OneWeatherNotificationServiceExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 871EA87D239E6F89F6F8818E /* Pods_OneWeatherNotificationServiceExtension.framework */; };
CD1237C3255D5C5900C98139 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1237C2255D5C5900C98139 /* AppDelegate.swift */; };
CD1237CC255D5C5C00C98139 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CD1237CB255D5C5C00C98139 /* Assets.xcassets */; };
......@@ -339,6 +340,7 @@
87DE8C80263BFBCE00E1C8D4 /* LegacyMigrationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyMigrationManager.swift; sourceTree = "<group>"; };
87DE8CB1263C09BA00E1C8D4 /* LegacyWdtLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyWdtLocation.swift; sourceTree = "<group>"; };
87DE8CF3263C267B00E1C8D4 /* LegacySettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacySettings.swift; sourceTree = "<group>"; };
87DE8D00263C4ADD00E1C8D4 /* WdtHealth.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WdtHealth.swift; sourceTree = "<group>"; };
C8C576F6184B547435CFF0F3 /* Pods-1Weather.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-1Weather.debug.xcconfig"; path = "Target Support Files/Pods-1Weather/Pods-1Weather.debug.xcconfig"; sourceTree = "<group>"; };
CD1237BF255D5C5900C98139 /* 1Weather.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 1Weather.app; sourceTree = BUILT_PRODUCTS_DIR; };
CD1237C2255D5C5900C98139 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
......@@ -1501,6 +1503,7 @@
CEC5270225E7BB4000DA58A5 /* WdtSurfaceObservation.swift */,
CEC5275C25E8E50B00DA58A5 /* WdtDailySummary.swift */,
CEC5275F25E92DDA00DA58A5 /* WdtHourlySummary.swift */,
87DE8D00263C4ADD00E1C8D4 /* WdtHealth.swift */,
);
path = Model;
sourceTree = "<group>";
......@@ -2127,6 +2130,7 @@
CEC7D8EE2639FE2700B8836D /* OLInAppStoreManager.swift in Sources */,
CDECDB052629A6600087F9F2 /* RadarLayer.swift in Sources */,
CEFB857226174F7A00C5CDD2 /* Storage.swift in Sources */,
87DE8D01263C4ADD00E1C8D4 /* WdtHealth.swift in Sources */,
CD82300725D6A73F00A05501 /* TodayConditionButton.swift in Sources */,
CE13B7EB2624805F007CBD4D /* Constants.swift in Sources */,
CDC6126A25E90C8800188DA7 /* GraphLineSettings.swift in Sources */,
......
......@@ -15,6 +15,7 @@ public struct CurrentWeather: Equatable, Hashable {
public var type: WeatherType = .unknown
public var isDay: Bool
public var uv: Int?
public var minTemp: Temperature?
public var maxTemp: Temperature?
public var windSpeed: WindSpeed?
......
//
// WdtHealth.swift
// 1Weather
//
// Created by Demid Merzlyakov on 30.04.2021.
//
import Foundation
struct WdtUvIndex: Codable {
var today: Int?
var tomorrow: Int?
}
struct WdtHealth: Codable {
public var uvIndex: WdtUvIndex?
private enum CodingKeys: String, CodingKey {
case uvIndex = "uv_index"
}
}
......@@ -124,6 +124,39 @@ public class WdtWeatherSource: WeatherSource {
return
}
self.updateUV(for: newLocation, type: type, completion: completion)
}
catch {
completion(nil, WdtWeatherSourceError.badServerResponse(error))
}
}
dataTask.resume()
}
}
private func updateUV(for location: Location, type: WeatherUpdateType, completion: @escaping WeatherSourceCompletion) {
let urlBuildResult = buildURL(for: location, type: type, uvRequest: true)
switch urlBuildResult {
case .failure(let error):
completion(nil, error)
return
case .success(let url):
let urlSession = URLSession.shared
let dataTask = urlSession.dataTask(with: url) { [weak self] (data, reponse, error) in
guard let self = self else { return }
guard let data = data else {
self.log.debug("Network response (health) (\(location)): error \(String(describing: error))")
completion(nil, WdtWeatherSourceError.networkError(error))
return
}
let responseBodyString = String(data: data, encoding: .utf8) ?? "<couldn't show as string"
self.log.debug("Network response (\(location)): \(responseBodyString)")
let decoder = XMLDecoder()
do {
let locationResponse = try decoder.decode(WdtHealth.self, from: data)
var newLocation = location
newLocation.today?.uv = locationResponse.uvIndex?.today
self.log.debug("DMA Set UV to \(locationResponse.uvIndex?.today ?? -1) Value after setting: \(newLocation.today?.uv ?? -1)")
completion(newLocation, nil)
}
catch {
......
......@@ -47,7 +47,7 @@ class SunPhaseCell: UITableViewCell {
private let sunsetTimeLabel = UILabel()
private let sunsetImageView = UIImageView(image: UIImage(named: "sun_down_arrow"))
private let sunUvLineView = SunUvLineView()
private let sunUvView = SunUvView()
// private let sunUvView = SunUvView()
private let maxUvLabel = UILabel()
private var sunProgress:CGFloat = 0.0
......@@ -102,6 +102,8 @@ class SunPhaseCell: UITableViewCell {
return
}
setUV(level: location.today?.uv)
SunPhaseCell.dateFormatter.timeZone = location.today?.timeZone
SunPhaseCell.nowDateFormatter.timeZone = location.today?.timeZone
sunriseTimeLabel.text = SunPhaseCell.dateFormatter.string(from: sunrise)
......@@ -140,12 +142,15 @@ class SunPhaseCell: UITableViewCell {
return path
}
private func setUV(level:Int) {
sunUvView.set(uvLevel: level)
private func setUV(level: Int?) {
// sunUvView.set(uvLevel: level)
//Label
let maxUvText = "sun.maxUV".localized()
let levelText = "\(level)"
var levelText = "--"
if let level = level {
levelText = "\(level)"
}
let color = interfaceStyle == .light ? ThemeManager.currentTheme.secondaryTextColor :
ThemeManager.currentTheme.primaryTextColor
let attrStirng = NSMutableAttributedString(string: "\(maxUvText): \(level)",
......@@ -338,19 +343,18 @@ private extension SunPhaseCell {
}
//UV levels
sunUvView.set(uvLevel: 8)
sunActivityContainer.addSubview(sunUvView)
sunUvView.snp.makeConstraints { (make) in
make.left.right.equalToSuperview().inset(18)
make.height.equalTo(8)
make.top.equalTo(sunriseImageView.snp.bottom).offset(20)
}
// sunUvView.set(uvLevel: 8)
// sunActivityContainer.addSubview(sunUvView)
// sunUvView.snp.makeConstraints { (make) in
// make.left.right.equalToSuperview().inset(18)
// make.height.equalTo(8)
// make.top.equalTo(sunriseImageView.snp.bottom).offset(20)
// }
//UL label
setUV(level: 8)
sunActivityContainer.addSubview(maxUvLabel)
maxUvLabel.snp.makeConstraints { (make) in
make.top.equalTo(sunUvView.snp.bottom).offset(11)
make.top.equalTo(sunriseImageView.snp.bottom).offset(20)
make.centerX.equalToSuperview()
make.bottom.bottom.equalToSuperview().inset(18)
}
......
......@@ -122,10 +122,10 @@ class TodayCellFactory: CellFactoryProtocol {
return cell
case .conditions:
let cell = dequeueReusableCell(type: TodayConditionsCell.self, tableView: tableView, indexPath: indexPath)
if cellsToUpdate.contains(.condition) {
// if cellsToUpdate.contains(.condition) {
cell.configure(with: loc)
cellsToUpdate.remove(.condition)
}
// cellsToUpdate.remove(.condition)
// }
return cell
case .forecastPeriod:
let cell = dequeueReusableCell(type: TodayForecastTimePeriodCell.self, tableView: tableView, indexPath: indexPath)
......
......@@ -32,7 +32,12 @@ class TodayConditionButton: UIControl {
case .humidity:
valueLabel.text = "\(location.today?.humidity ?? 0)%"
case .uvIndex:
valueLabel.text = "4"
if let uv = location.today?.uv {
valueLabel.text = "\(uv)"
}
else {
valueLabel.text = "--"
}
case .pressure:
valueLabel.text = location.today?.pressure?.settingsConverted.string
case .dewPoint:
......
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