Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
bd8ee8e9
Commit
bd8ee8e9
authored
Apr 08, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Air Quality: scale pollutants bars; set air quality advice.
parent
e007d965
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
16 deletions
+26
-16
1Weather/Model/ModelObjects/Health/Health.swift
+10
-9
1Weather/UI/View controllers/Today/Cells/TodayAirQualityCell/PollutantView.swift
+2
-2
1Weather/UI/View controllers/Today/Cells/TodayAirQualityCell/TodayAirQualityCell.swift
+14
-5
No files found.
1Weather/Model/ModelObjects/Health/Health.swift
View file @
bd8ee8e9
...
@@ -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
...
...
1Weather/UI/View controllers/Today/Cells/TodayAirQualityCell/PollutantView.swift
View file @
bd8ee8e9
...
@@ -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
]
}
}
...
...
1Weather/UI/View controllers/Today/Cells/TodayAirQualityCell/TodayAirQualityCell.swift
View file @
bd8ee8e9
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment