Commit bd8ee8e9 by Demid Merzlyakov

Air Quality: scale pollutants bars; set air quality advice.

parent e007d965
...@@ -179,15 +179,7 @@ public enum HealthStatus: String { ...@@ -179,15 +179,7 @@ public enum HealthStatus: String {
public struct Pollutant: Equatable, Hashable { public struct Pollutant: Equatable, Hashable {
public let name: String public let name: String
public let value: Double public let value: Double
public var progress:CGFloat { public let progress: CGFloat
guard let hazardousLevelStart = self.hazardousLevelStart else {
return 0.1 // not great, not terrible
}
var progressValue = max(0, CGFloat(value / hazardousLevelStart))
progressValue = min(1, progressValue)
return progressValue
}
public init(name: String, value: Double) { public init(name: String, value: Double) {
self.name = name self.name = name
...@@ -224,6 +216,15 @@ public struct Pollutant: Equatable, Hashable { ...@@ -224,6 +216,15 @@ public struct Pollutant: Equatable, Hashable {
hazardousLevelStart = nil hazardousLevelStart = nil
} }
self.status = statusValue self.status = statusValue
if let hazardousLevelStart = self.hazardousLevelStart {
var progressValue = max(0, CGFloat(value / hazardousLevelStart))
progressValue = min(1, progressValue)
self.progress = progressValue
}
else {
self.progress = 0.1 // not great, not terrible
}
} }
public private (set) var status: HealthStatus public private (set) var status: HealthStatus
......
...@@ -38,12 +38,12 @@ class PollutantView: UIView { ...@@ -38,12 +38,12 @@ class PollutantView: UIView {
progressGradient.frame = .init(x: 0, y: 0, width: progressContainer.bounds.width * progressValue, height: progressContainer.bounds.height) progressGradient.frame = .init(x: 0, y: 0, width: progressContainer.bounds.width * progressValue, height: progressContainer.bounds.height)
} }
func configure(pollutant: Pollutant) { func configure(pollutant: Pollutant, progressCoefficient: CGFloat) {
typeLabel.text = pollutant.name.localized typeLabel.text = pollutant.name.localized
valueLabel.text = "\(Int(pollutant.value))" valueLabel.text = "\(Int(pollutant.value))"
statusLabel.text = pollutant.status.localized statusLabel.text = pollutant.status.localized
statusLabel.textColor = pollutant.status.textColor statusLabel.textColor = pollutant.status.textColor
progressValue = pollutant.progress progressValue = pollutant.progress * progressCoefficient
progressGradient.colors = [pollutant.status.gradientColorStart.cgColor, progressGradient.colors = [pollutant.status.gradientColorStart.cgColor,
pollutant.status.gradientColorEnd.cgColor] pollutant.status.gradientColorEnd.cgColor]
} }
......
...@@ -60,12 +60,21 @@ class TodayAirQualityCell: UITableViewCell { ...@@ -60,12 +60,21 @@ class TodayAirQualityCell: UITableViewCell {
length: aqiConditionText.count)) length: aqiConditionText.count))
airQualityLabel.attributedText = attrString airQualityLabel.attributedText = attrString
airDescLabel.text = health?.airQuality?.advice
//Fill pollutions //Fill pollutions
stackView.removeAll() stackView.removeAll()
health?.pollutants.map{$1}.forEach { if let pollutants = health?.pollutants.values, let maxPollutantProgress: CGFloat = pollutants.max(by: { $0.progress < $1.progress })?.progress {
let pollutionView = PollutantView() var coefficient: CGFloat = 1.0
pollutionView.configure(pollutant: $0) let desiredMinProgress: CGFloat = 0.3
stackView.addArrangedSubview(pollutionView) if maxPollutantProgress < desiredMinProgress {
coefficient = desiredMinProgress / maxPollutantProgress
}
for pollutant in pollutants {
let pollutionView = PollutantView()
pollutionView.configure(pollutant: pollutant, progressCoefficient: coefficient)
stackView.addArrangedSubview(pollutionView)
}
} }
stackView.layoutIfNeeded() stackView.layoutIfNeeded()
...@@ -118,7 +127,7 @@ private extension TodayAirQualityCell { ...@@ -118,7 +127,7 @@ private extension TodayAirQualityCell {
airDescLabel.lineBreakMode = .byWordWrapping airDescLabel.lineBreakMode = .byWordWrapping
airDescLabel.font = AppFont.SFPro.regular(size: 16) airDescLabel.font = AppFont.SFPro.regular(size: 16)
airDescLabel.textColor = ThemeManager.currentTheme.secondaryTextColor airDescLabel.textColor = ThemeManager.currentTheme.secondaryTextColor
airDescLabel.text = "Slightly elevated pollution, but general public likely not affected" airDescLabel.text = ""
contentView.addSubview(airDescLabel) contentView.addSubview(airDescLabel)
//Constraints //Constraints
......
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