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
39aef5b9
Commit
39aef5b9
authored
Oct 05, 2021
by
Dmitry Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[IOS-182]: Implemented dynamic update munitely forecast every minute
parent
4ae087ec
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
12 deletions
+63
-12
1Weather/UI/SharedViews/MinutelyForecastView/MinutelyForecastDetailsView.swift
+4
-1
1Weather/UI/SharedViews/MinutelyForecastView/MinutelyForecastView.swift
+59
-8
1Weather/UI/View controllers/Today/Cells/TodayForecastTimePeriodCell.swift
+0
-3
No files found.
1Weather/UI/SharedViews/MinutelyForecastView/MinutelyForecastDetailsView.swift
View file @
39aef5b9
...
...
@@ -63,6 +63,9 @@ class MinutelyForecastDetailsView: UIView {
tempLabel
.
text
=
valueStirng
forecastImage
.
image
=
weatherImage
forecastImage
.
snp
.
updateConstraints
{
update
in
update
.
width
.
equalTo
(
weatherImage
==
nil
?
0
:
28
)
}
}
}
...
...
@@ -105,7 +108,7 @@ private extension MinutelyForecastDetailsView {
separator
.
snp
.
makeConstraints
{
make
in
make
.
width
.
equalTo
(
1
)
make
.
height
.
equalToSuperview
()
.
multipliedBy
(
0.65
)
make
.
left
.
equalToSuperview
()
.
inset
(
70
)
make
.
right
.
equalTo
(
tempLabel
.
snp
.
left
)
.
offset
(
-
6
)
make
.
centerY
.
equalToSuperview
()
}
...
...
1Weather/UI/SharedViews/MinutelyForecastView/MinutelyForecastView.swift
View file @
39aef5b9
...
...
@@ -74,6 +74,7 @@ class MinutelyForecastView: UIView {
private
var
weatherTypeCache
=
[
Int
:
UIImage
]()
private
var
lastSelectedLevelIndex
=
0
private
var
minutelyForecast
=
[
MinutelyItem
]()
private
var
timer
:
Timer
?
private
var
forecastType
=
MinutelyForecastType
.
temperature
private
lazy
var
dateFormatter
:
DateFormatter
=
{
let
formatter
=
DateFormatter
()
...
...
@@ -85,12 +86,22 @@ class MinutelyForecastView: UIView {
init
()
{
super
.
init
(
frame
:
.
zero
)
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
updateCurrentSelectedLevel
)
,
name
:
Notification
.
Name
.
NSSystemClockDidChange
,
object
:
nil
)
prepareDetailView
()
prepareCenterDashLine
()
prepareScrollView
()
prepareVerticalStackView
()
}
required
init
?(
coder
:
NSCoder
)
{
fatalError
(
"init(coder:) has not been implemented"
)
}
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
...
...
@@ -130,10 +141,27 @@ class MinutelyForecastView: UIView {
:
kPrecipitationColors
.
last
?
.
cgColor
prepareMinutelyItems
()
if
let
firstMinutelyItem
=
minutelyForecast
.
first
{
self
.
updateDetailsView
(
minutelyItem
:
firstMinutelyItem
)
}
updateChart
()
configureTimer
()
updateCurrentSelectedLevel
()
}
private
func
configureTimer
()
{
if
timer
==
nil
{
let
calendar
=
Calendar
(
identifier
:
.
gregorian
)
var
dateComponents
=
calendar
.
dateComponents
([
.
year
,
.
month
,
.
day
,
.
hour
,
.
minute
,
.
second
],
from
:
Date
())
if
let
oldMinutes
=
dateComponents
.
minute
{
dateComponents
.
minute
=
oldMinutes
+
1
// dateComponents handle rolling over 60.
}
dateComponents
.
second
=
0
let
firstFireDate
=
calendar
.
date
(
from
:
dateComponents
)
??
Date
()
.
addingTimeInterval
(
5
)
let
newTimer
=
Timer
(
fire
:
firstFireDate
,
interval
:
30.0
,
repeats
:
true
,
block
:
{
[
weak
self
]
_
in
self
?
.
updateCurrentSelectedLevel
()
})
RunLoop
.
main
.
add
(
newTimer
,
forMode
:
.
common
)
self
.
timer
=
newTimer
}
}
private
func
updateDetailsView
(
minutelyItem
:
MinutelyItem
)
{
...
...
@@ -155,14 +183,14 @@ class MinutelyForecastView: UIView {
private
func
prepareMinutelyItems
()
{
minutelyForecast
.
removeAll
()
guard
let
location
=
self
.
location
,
let
forecastItems
=
location
.
minutely
?
.
forecast
else
{
return
}
for
var
minutelyForecastItem
in
forecastItems
{
guard
let
hourly
=
(
location
.
hourly
.
first
{
...
...
@@ -171,9 +199,11 @@ class MinutelyForecastView: UIView {
return
minutelyForecastItem
.
time
>=
thisHour
&&
minutelyForecastItem
.
time
<
nextHour
})
else
{
minutelyForecastItem
.
weatherTypeImage
=
nil
minutelyForecast
.
append
(
minutelyForecastItem
)
continue
}
minutelyForecastItem
.
weatherTypeImage
=
hourly
.
type
.
image
(
isDay
:
hourly
.
isDay
)
minutelyForecast
.
append
(
minutelyForecastItem
)
}
...
...
@@ -330,8 +360,24 @@ class MinutelyForecastView: UIView {
}
}
required
init
?(
coder
:
NSCoder
)
{
fatalError
(
"init(coder:) has not been implemented"
)
@objc
private
func
updateCurrentSelectedLevel
()
{
for
(
index
,
minutelyForecastItem
)
in
minutelyForecast
.
enumerated
()
{
let
thisMinute
=
Date
()
let
prevMinute
=
thisMinute
.
addingTimeInterval
(
-
60
)
if
minutelyForecastItem
.
time
>=
prevMinute
&&
minutelyForecastItem
.
time
<
thisMinute
{
if
lastSelectedLevelIndex
==
index
{
continue
}
if
let
positionX
=
levelsPositionXCache
[
index
]
{
scrollView
.
setContentOffset
(
.
init
(
x
:
positionX
-
scrollView
.
contentInset
.
left
,
y
:
0
),
animated
:
true
)
}
self
.
updateDetailsView
(
minutelyItem
:
minutelyForecastItem
)
self
.
lastSelectedLevelIndex
=
index
return
}
}
}
}
...
...
@@ -396,6 +442,11 @@ private extension MinutelyForecastView {
//MARK:- UIScrollView Delegate
extension
MinutelyForecastView
:
UIScrollViewDelegate
{
func
scrollViewDidScroll
(
_
scrollView
:
UIScrollView
)
{
if
scrollView
.
panGestureRecognizer
.
state
==
.
began
{
timer
?
.
invalidate
()
timer
=
nil
}
let
targetPointX
=
Double
(
scrollView
.
contentInset
.
left
+
scrollView
.
contentOffset
.
x
)
guard
let
cachedValue
=
(
levelsPositionXCache
.
first
{
...
...
1Weather/UI/View controllers/Today/Cells/TodayForecastTimePeriodCell.swift
View file @
39aef5b9
...
...
@@ -10,9 +10,6 @@ import OneWeatherCore
class
TodayForecastTimePeriodCell
:
UITableViewCell
{
//Private
// private let periodSegmentedControl = ForecastTimePeriodControl(items: ["forecast.timePeriod.daily".localized(),
// "forecast.timePeriod.hourly".localized(),
// "forecast.timePeriod.minutely".localized()])
private
let
periodSegmentedControl
=
ForecastTimePeriodControl
(
items
:
nil
)
private
let
forecastTimePeriodView
=
ForecastTimePeriodView
()
private
let
minutelyForecastView
=
MinutelyForecastView
()
...
...
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