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
efb9810d
Commit
efb9810d
authored
Oct 01, 2021
by
Dmitry Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[IOS-172]: Changed minutely precipitation UI
parent
0f90e48f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
18 deletions
+91
-18
1Weather/UI/SharedViews/MinutelyForecastView/MinutelyForecastView.swift
+91
-18
WDTWeatherSource/WDTWeatherSource/HelperObjects/WdtWeatherSource.swift
+0
-0
No files found.
1Weather/UI/SharedViews/MinutelyForecastView/MinutelyForecastView.swift
View file @
efb9810d
...
@@ -39,7 +39,7 @@ private class MinutelyLevelView: UIView {
...
@@ -39,7 +39,7 @@ private class MinutelyLevelView: UIView {
layer
.
shadowColor
=
UIColor
(
hex
:
0xd8ddfa
)
.
withAlphaComponent
(
0.8
)
.
cgColor
layer
.
shadowColor
=
UIColor
(
hex
:
0xd8ddfa
)
.
withAlphaComponent
(
0.8
)
.
cgColor
layer
.
shadowOffset
=
.
init
(
width
:
0
,
height
:
3
)
layer
.
shadowOffset
=
.
init
(
width
:
0
,
height
:
3
)
layer
.
shadowRadius
=
3
layer
.
shadowRadius
=
3
layer
.
shadowOpacity
=
1
layer
.
shadowOpacity
=
interfaceStyle
==
.
light
?
1
:
0
}
}
required
init
?(
coder
:
NSCoder
)
{
required
init
?(
coder
:
NSCoder
)
{
...
@@ -53,6 +53,11 @@ private class MinutelyLevelView: UIView {
...
@@ -53,6 +53,11 @@ private class MinutelyLevelView: UIView {
gradient
.
frame
=
bounds
gradient
.
frame
=
bounds
layer
.
shadowPath
=
UIBezierPath
(
roundedRect
:
bounds
,
cornerRadius
:
bounds
.
width
/
2
)
.
cgPath
layer
.
shadowPath
=
UIBezierPath
(
roundedRect
:
bounds
,
cornerRadius
:
bounds
.
width
/
2
)
.
cgPath
}
}
override
func
traitCollectionDidChange
(
_
previousTraitCollection
:
UITraitCollection
?)
{
super
.
traitCollectionDidChange
(
previousTraitCollection
)
layer
.
shadowOpacity
=
interfaceStyle
==
.
light
?
1
:
0
}
}
}
class
MinutelyForecastView
:
UIView
{
class
MinutelyForecastView
:
UIView
{
...
@@ -120,7 +125,9 @@ class MinutelyForecastView: UIView {
...
@@ -120,7 +125,9 @@ class MinutelyForecastView: UIView {
self
.
location
=
location
self
.
location
=
location
self
.
forecastType
=
forecastType
self
.
forecastType
=
forecastType
self
.
dateFormatter
.
timeZone
=
location
.
timeZone
self
.
dateFormatter
.
timeZone
=
location
.
timeZone
centerDashline
.
strokeColor
=
kTemperatureColors
.
last
?
.
cgColor
centerDashline
.
strokeColor
=
forecastType
==
.
temperature
?
kTemperatureColors
.
last
?
.
cgColor
:
kPrecipitationColors
.
last
?
.
cgColor
prepareMinutelyItems
()
prepareMinutelyItems
()
if
let
firstMinutelyItem
=
minutelyForecast
.
first
{
if
let
firstMinutelyItem
=
minutelyForecast
.
first
{
...
@@ -184,10 +191,36 @@ class MinutelyForecastView: UIView {
...
@@ -184,10 +191,36 @@ class MinutelyForecastView: UIView {
}
}
}
}
switch
forecastType
{
case
.
temperature
:
updateTemperatureChart
()
case
.
precipitation
:
updatePrecipitationChart
()
}
levelsStackView
.
layoutIfNeeded
()
verticalStackView
.
layoutIfNeeded
()
//Levels dashline
for
_
in
0
..<
verticalStackView
.
arrangedSubviews
.
count
{
let
levelShape
=
CAShapeLayer
()
levelShape
.
opacity
=
0.3
levelShape
.
lineWidth
=
1
levelShape
.
lineDashPattern
=
[
4
,
5
]
levelShape
.
strokeColor
=
UIColor
(
hex
:
0x979797
)
.
cgColor
layer
.
insertSublayer
(
levelShape
,
at
:
0
)
levelsDashline
.
append
(
levelShape
)
}
for
(
index
,
view
)
in
levelsStackView
.
arrangedSubviews
.
enumerated
()
{
levelsPositionXCache
[
index
]
=
view
.
frame
.
origin
.
x
}
}
private
func
updateTemperatureChart
()
{
guard
guard
let
maxTemp
=
(
minutelyForecast
.
compactMap
{
$0
.
temp
}
.
max
{
$0
.
value
<
$1
.
value
}
),
let
maxTemp
=
(
minutelyForecast
.
compactMap
{
$0
.
temp
}
.
max
{
$0
.
value
<
$1
.
value
}
),
let
minTemp
=
(
minutelyForecast
.
compactMap
{
$0
.
temp
}
.
min
{
$0
.
value
<
$1
.
value
}
)
let
minTemp
=
(
minutelyForecast
.
compactMap
{
$0
.
temp
}
.
min
{
$0
.
value
<
$1
.
value
}
)
else
{
else
{
return
return
}
}
...
@@ -216,9 +249,10 @@ class MinutelyForecastView: UIView {
...
@@ -216,9 +249,10 @@ class MinutelyForecastView: UIView {
}
}
for
index
in
0
..<
minutelyForecast
.
count
{
for
index
in
0
..<
minutelyForecast
.
count
{
let
view
=
MinutelyLevelView
(
forecastType
:
self
.
forecastTyp
e
)
let
view
=
MinutelyLevelView
(
forecastType
:
.
temperatur
e
)
levelsStackView
.
addArrangedSubview
(
view
)
levelsStackView
.
addArrangedSubview
(
view
)
let
level
=
(
0.05
+
0.9
*
((
minutelyForecast
[
index
]
.
temp
.
value
-
minTemp
.
value
)
/
(
maxTemp
.
value
-
minTemp
.
value
)))
let
diff
=
maxTemp
.
value
-
minTemp
.
value
==
0
?
1
:
maxTemp
.
value
-
minTemp
.
value
let
level
=
(
0.05
+
0.9
*
((
minutelyForecast
[
index
]
.
temp
.
value
-
minTemp
.
value
)
/
diff
))
view
.
snp
.
makeConstraints
{
make
in
view
.
snp
.
makeConstraints
{
make
in
make
.
width
.
equalTo
(
kLevelWidth
)
make
.
width
.
equalTo
(
kLevelWidth
)
make
.
height
.
equalToSuperview
()
.
multipliedBy
(
level
)
make
.
height
.
equalToSuperview
()
.
multipliedBy
(
level
)
...
@@ -237,23 +271,62 @@ class MinutelyForecastView: UIView {
...
@@ -237,23 +271,62 @@ class MinutelyForecastView: UIView {
}
}
}
}
}
}
}
levelsStackView
.
layoutIfNeeded
()
private
func
updatePrecipitationChart
()
{
verticalStackView
.
layoutIfNeeded
()
guard
let
maxPrecip
=
(
minutelyForecast
.
compactMap
{
$0
.
precipitation
}
.
max
{
$0
<
$1
}),
let
minPrecip
=
(
minutelyForecast
.
compactMap
{
$0
.
precipitation
}
.
min
{
$0
<
$1
})
//Levels dashline
else
{
for
_
in
0
..<
verticalStackView
.
arrangedSubviews
.
count
{
return
let
levelShape
=
CAShapeLayer
()
levelShape
.
opacity
=
0.3
levelShape
.
lineWidth
=
1
levelShape
.
lineDashPattern
=
[
4
,
5
]
levelShape
.
strokeColor
=
UIColor
(
hex
:
0x979797
)
.
cgColor
layer
.
insertSublayer
(
levelShape
,
at
:
0
)
levelsDashline
.
append
(
levelShape
)
}
}
for
(
index
,
view
)
in
levelsStackView
.
arrangedSubviews
.
enumerated
()
{
var
uniqPrecips
=
minutelyForecast
.
compactMap
{
$0
.
precipitation
}
.
unique
()
.
sorted
{
$0
>
$1
}
levelsPositionXCache
[
index
]
=
view
.
frame
.
origin
.
x
if
uniqPrecips
.
count
>
4
{
let
uniqMax
=
uniqPrecips
.
removeFirst
()
let
uniqMin
=
uniqPrecips
.
removeLast
()
let
midPoint
=
(
uniqPrecips
.
count
/
2
)
let
firstHalf
=
uniqPrecips
[
..<
midPoint
]
let
firstHalfTemp
=
firstHalf
[
firstHalf
.
startIndex
+
firstHalf
.
count
/
2
]
let
seconHalf
=
uniqPrecips
[
midPoint
...
]
let
secondHalfTemp
=
seconHalf
[
seconHalf
.
startIndex
+
seconHalf
.
count
/
2
]
uniqPrecips
=
[
uniqMax
,
firstHalfTemp
,
secondHalfTemp
,
uniqMin
]
}
for
precipitation
in
uniqPrecips
{
let
label
=
UILabel
()
label
.
text
=
"
\(
Int
(
precipitation
*
100
)
)
%"
label
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
10
)
label
.
setContentHuggingPriority
(
.
fittingSizeLevel
,
for
:
.
vertical
)
label
.
sizeToFit
()
verticalStackView
.
addArrangedSubview
(
label
)
}
for
index
in
0
..<
minutelyForecast
.
count
{
let
view
=
MinutelyLevelView
(
forecastType
:
.
precipitation
)
levelsStackView
.
addArrangedSubview
(
view
)
let
diff
=
maxPrecip
-
minPrecip
==
0
?
1
:
maxPrecip
-
minPrecip
let
level
=
(
0.05
+
0.9
*
((
minutelyForecast
[
index
]
.
precipitation
-
minPrecip
)
/
diff
))
view
.
snp
.
makeConstraints
{
make
in
make
.
width
.
equalTo
(
kLevelWidth
)
make
.
height
.
equalToSuperview
()
.
multipliedBy
(
level
)
}
let
minutes
=
Calendar
.
current
.
component
(
.
minute
,
from
:
minutelyForecast
[
index
]
.
time
)
if
minutes
%
20
==
0
{
let
label
=
UILabel
()
label
.
font
=
AppFont
.
SFPro
.
bold
(
size
:
12
)
label
.
text
=
dateFormatter
.
string
(
from
:
minutelyForecast
[
index
]
.
time
)
scrollView
.
addSubview
(
label
)
label
.
snp
.
makeConstraints
{
make
in
make
.
top
.
equalTo
(
view
.
snp
.
bottom
)
.
offset
(
12
)
make
.
centerX
.
equalTo
(
view
)
}
}
}
}
}
}
...
...
WDTWeatherSource/WDTWeatherSource/HelperObjects/WdtWeatherSource.swift
View file @
efb9810d
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