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
92fda9d3
Commit
92fda9d3
authored
Mar 19, 2021
by
Dmitriy Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added sync between DayControlsButton and ForecastTimePeriodCell
parent
bbf41fed
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
115 additions
and
24 deletions
+115
-24
1Weather.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
+1
-1
1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
1Weather/UI/Helpers/ForecastTimePeriod/ForecastTimePeriodView.swift
+18
-4
1Weather/UI/View controllers/Forecast/Cells/ForecastCellFactory.swift
+6
-0
1Weather/UI/View controllers/Forecast/Cells/ForecastTimePeriodCell.swift
+7
-0
1Weather/UI/View controllers/Forecast/DaysControlView.swift
+32
-9
1Weather/UI/View controllers/Forecast/ForecastViewController.swift
+31
-8
1Weather/ViewModels/ForecastViewModel.swift
+18
-0
Pods/Pods.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
+2
-2
No files found.
1Weather.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
92fda9d3
...
...
@@ -7,7 +7,7 @@
<
k
e
y
>
1Weather.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
4
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
5
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
k
e
y
>
PG
(
Playground
)
1.xcscheme
<
/k
e
y
>
<
d
i
c
t
>
...
...
1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
View file @
92fda9d3
No preview for this file type
1Weather/UI/Helpers/ForecastTimePeriod/ForecastTimePeriodView.swift
View file @
92fda9d3
...
...
@@ -60,9 +60,23 @@ class ForecastTimePeriodView: UIView {
}
}
public
func
set
(
timePeriod
:
TimePeriod
,
buttonType
:
PeriodButtonProtocol
.
Type
,
selectedIndex
:
Int
=
0
)
{
public
func
set
(
timePeriod
:
TimePeriod
,
buttonType
:
PeriodButtonProtocol
.
Type
)
{
self
.
currentTimePeriod
=
timePeriod
rebuildButtons
(
buttonType
:
buttonType
,
selectedIndex
:
selectedIndex
)
rebuildButtons
(
buttonType
:
buttonType
)
}
public
func
selectButtonAt
(
index
:
Int
)
{
guard
let
buttons
=
self
.
stackView
.
arrangedSubviews
as?
[
PeriodButtonProtocol
]
else
{
return
}
buttons
.
enumerated
()
.
forEach
{
$1
.
isSelected
=
$0
==
index
if
$1
.
isSelected
{
self
.
scrollView
.
scrollRectToVisible
(
$1
.
frame
,
animated
:
true
)
}
}
}
//Private
...
...
@@ -79,7 +93,7 @@ class ForecastTimePeriodView: UIView {
}
}
private
func
rebuildButtons
(
buttonType
:
PeriodButtonProtocol
.
Type
,
selectedIndex
:
Int
)
{
private
func
rebuildButtons
(
buttonType
:
PeriodButtonProtocol
.
Type
)
{
stackView
.
removeAll
()
let
numberOfButtons
:
Int
...
...
@@ -100,7 +114,7 @@ class ForecastTimePeriodView: UIView {
}
forecastButton
.
index
=
index
forecastButton
.
addTarget
(
self
,
action
:
#selector(
handleForecastButton(button:)
)
,
for
:
.
touchUpInside
)
forecastButton
.
isSelected
=
index
==
selectedIndex
forecastButton
.
isSelected
=
index
==
0
stackView
.
addArrangedSubview
(
forecastButton
)
forecastButton
.
snp
.
makeConstraints
{
(
make
)
in
...
...
1Weather/UI/View controllers/Forecast/Cells/ForecastCellFactory.swift
View file @
92fda9d3
...
...
@@ -47,6 +47,7 @@ class ForecastCellFactory {
case
.
forecastPeriod
:
let
cell
=
dequeueReusableCell
(
type
:
ForecastTimePeriodCell
.
self
,
tableView
:
tableView
,
indexPath
:
indexPath
)
cell
.
delegate
=
self
cell
.
selectDayButtonAt
(
index
:
forecastViewModel
.
selectedDailyWeatherIndex
)
if
let
daily
=
forecastViewModel
.
location
?
.
daily
,
let
hourly
=
forecastViewModel
.
location
?
.
hourly
{
...
...
@@ -100,6 +101,11 @@ class ForecastCellFactory {
//MARK:- ForecastTimePeriodCell Delegate
extension
ForecastCellFactory
:
ForecastTimePeriodCellDelegate
{
func
timePeriodCell
(
cell
:
ForecastTimePeriodCell
,
didSelectButtonAt
index
:
Int
)
{
guard
forecastViewModel
.
currentTimePeriod
==
.
daily
else
{
return
}
forecastViewModel
.
selectDailyWeather
(
at
:
index
)
}
func
timePeriodCell
(
cell
:
ForecastTimePeriodCell
,
didSelectTimePeriod
timePeriod
:
TimePeriod
)
{
forecastViewModel
.
setTimePeriod
(
timePeriod
:
timePeriod
)
}
}
1Weather/UI/View controllers/Forecast/Cells/ForecastTimePeriodCell.swift
View file @
92fda9d3
...
...
@@ -9,6 +9,7 @@ import UIKit
protocol
ForecastTimePeriodCellDelegate
:
class
{
func
timePeriodCell
(
cell
:
ForecastTimePeriodCell
,
didSelectButtonAt
index
:
Int
)
func
timePeriodCell
(
cell
:
ForecastTimePeriodCell
,
didSelectTimePeriod
timePeriod
:
TimePeriod
)
}
class
ForecastTimePeriodCell
:
UITableViewCell
{
...
...
@@ -48,6 +49,10 @@ class ForecastTimePeriodCell: UITableViewCell {
}
}
public
func
selectDayButtonAt
(
index
:
Int
)
{
self
.
forecastTimePeriodView
.
selectButtonAt
(
index
:
index
)
}
@objc
private
func
handleSegmentDidChange
()
{
guard
let
timePeriod
=
TimePeriod
(
rawValue
:
self
.
periodSegmentedControl
.
selectedSegmentIndex
)
else
{
return
...
...
@@ -59,6 +64,8 @@ class ForecastTimePeriodCell: UITableViewCell {
case
.
hourly
:
self
.
forecastTimePeriodView
.
set
(
timePeriod
:
timePeriod
,
buttonType
:
ForecastPeriodButton
.
self
)
}
delegate
?
.
timePeriodCell
(
cell
:
self
,
didSelectTimePeriod
:
timePeriod
)
}
}
...
...
1Weather/UI/View controllers/Forecast/DaysControlView.swift
View file @
92fda9d3
...
...
@@ -7,6 +7,10 @@
import
UIKit
protocol
DaysControlViewDelegate
:
class
{
func
didSelectButtonAt
(
index
:
Int
)
}
class
DaysControlView
:
UIView
{
//Private
private
let
scrollView
=
UIScrollView
()
...
...
@@ -14,10 +18,14 @@ class DaysControlView: UIView {
private
let
gradientView
=
GradientView
(
startColor
:
UIColor
(
hex
:
0xffffff
)
.
withAlphaComponent
(
0
),
endColor
:
UIColor
(
hex
:
0xdaddec
),
opacity
:
0.5
)
//Public
weak
var
delegate
:
DaysControlViewDelegate
?
private
var
statusBarHeight
:
CGFloat
{
var
statusBarHeight
:
CGFloat
=
0
if
#available(iOS 13.0, *)
{
let
window
=
UIApplication
.
shared
.
windows
.
filter
{
$0
.
isKeyWindow
}
.
first
let
window
=
UIApplication
.
shared
.
windows
.
filter
{
$0
.
isKeyWindow
}
.
first
statusBarHeight
=
window
?
.
windowScene
?
.
statusBarManager
?
.
statusBarFrame
.
height
??
0
}
else
{
statusBarHeight
=
UIApplication
.
shared
.
statusBarFrame
.
height
...
...
@@ -39,10 +47,7 @@ class DaysControlView: UIView {
}
public
func
configure
(
dailyWeather
:
[
DailyWeather
])
{
stackView
.
arrangedSubviews
.
forEach
{
stackView
.
removeArrangedSubview
(
$0
)
$0
.
removeFromSuperview
()
}
stackView
.
removeAll
()
for
index
in
0
..<
dailyWeather
.
count
{
let
button
=
DayControlButton
()
...
...
@@ -54,11 +59,29 @@ class DaysControlView: UIView {
stackView
.
layoutIfNeeded
()
}
public
func
selectDayAt
(
index
:
Int
)
{
guard
let
buttons
=
stackView
.
arrangedSubviews
as?
[
DayControlButton
]
else
{
return
}
buttons
.
enumerated
()
.
forEach
{
$1
.
isSelected
=
$0
==
index
if
$1
.
isSelected
{
scrollView
.
scrollRectToVisible
(
$1
.
frame
,
animated
:
true
)
}
}
}
@objc
private
func
handleDayButton
(
button
:
DayControlButton
)
{
guard
let
buttons
=
stackView
.
arrangedSubviews
as?
[
DayControlButton
]
else
{
return
}
buttons
.
forEach
{
$0
.
isSelected
=
$0
===
button
buttons
.
enumerated
()
.
forEach
{
$1
.
isSelected
=
$1
===
button
if
$1
.
isSelected
{
self
.
delegate
?
.
didSelectButtonAt
(
index
:
$0
)
}
}
}
}
...
...
@@ -80,7 +103,7 @@ private extension DaysControlView {
addSubview
(
scrollView
)
scrollView
.
snp
.
makeConstraints
{
(
make
)
in
make
.
top
.
equalToSuperview
()
.
inset
(
statusBarHeight
+
22
)
make
.
top
.
equalToSuperview
()
.
inset
(
statusBarHeight
)
make
.
left
.
right
.
equalToSuperview
()
make
.
bottom
.
equalToSuperview
()
.
inset
(
18
)
make
.
height
.
greaterThanOrEqualTo
(
50
)
...
...
@@ -94,7 +117,7 @@ private extension DaysControlView {
stackView
.
spacing
=
10
stackView
.
clipsToBounds
=
false
stackView
.
isLayoutMarginsRelativeArrangement
=
true
stackView
.
layoutMargins
=
.
init
(
top
:
0
,
left
:
10
,
bottom
:
0
,
right
:
10
)
stackView
.
layoutMargins
=
.
init
(
top
:
0
,
left
:
6
,
bottom
:
0
,
right
:
6
)
scrollView
.
addSubview
(
stackView
)
stackView
.
snp
.
makeConstraints
{
(
make
)
in
...
...
1Weather/UI/View controllers/Forecast/ForecastViewController.swift
View file @
92fda9d3
...
...
@@ -36,7 +36,9 @@ class ForecastViewController: UIViewController {
prepareNavigationBar
()
prepareTableView
()
prepareDayControlsView
()
refreshCityButton
()
refreshDayButtons
()
}
private
func
refreshCityButton
()
{
...
...
@@ -44,6 +46,15 @@ class ForecastViewController: UIViewController {
cityButton
.
isHidden
=
false
}
private
func
refreshDayButtons
()
{
if
let
dailyWeather
=
viewModel
.
location
?
.
daily
{
daysControlView
.
configure
(
dailyWeather
:
dailyWeather
)
}
else
{
daysControlView
.
alpha
=
0
}
}
@objc
private
func
handleCityButton
()
{
print
(
"Handle city button"
)
}
...
...
@@ -87,6 +98,7 @@ private extension ForecastViewController {
func
prepareDayControlsView
()
{
daysControlView
.
alpha
=
0
daysControlView
.
delegate
=
self
view
.
addSubview
(
daysControlView
)
daysControlView
.
snp
.
makeConstraints
{
(
make
)
in
make
.
top
.
left
.
right
.
equalToSuperview
()
...
...
@@ -116,7 +128,8 @@ extension ForecastViewController: UITableViewDelegate {
func
scrollViewDidScroll
(
_
scrollView
:
UIScrollView
)
{
guard
let
navVC
=
self
.
navigationController
,
viewModel
.
location
?
.
daily
.
isEmpty
==
false
viewModel
.
location
?
.
daily
.
isEmpty
==
false
,
viewModel
.
currentTimePeriod
==
.
daily
else
{
return
}
...
...
@@ -167,13 +180,7 @@ extension ForecastViewController: ForecastViewModelDelegate {
func
viewModelDidChange
<
P
>
(
model
:
P
)
where
P
:
ViewModelProtocol
{
refreshCityButton
()
tableView
.
reloadData
()
if
let
dailyWeather
=
viewModel
.
location
?
.
daily
{
daysControlView
.
configure
(
dailyWeather
:
dailyWeather
)
}
else
{
daysControlView
.
alpha
=
0
}
refreshDayButtons
()
}
func
selectedDailyWeatherDidChange
()
{
...
...
@@ -185,5 +192,21 @@ extension ForecastViewController: ForecastViewModelDelegate {
}
tableView
.
reloadRows
(
at
:
indexPathToReload
,
with
:
.
none
)
daysControlView
.
selectDayAt
(
index
:
viewModel
.
selectedDailyWeatherIndex
)
}
func
selectedTimePeriodDidChange
()
{
guard
let
timePeriodCell
=
tableView
.
cellForRow
(
at
:
[
0
,
0
])
as?
ForecastTimePeriodCell
else
{
return
}
timePeriodCell
.
selectDayButtonAt
(
index
:
viewModel
.
selectedDailyWeatherIndex
)
}
}
//MARK:- DaysControlView Delegate
extension
ForecastViewController
:
DaysControlViewDelegate
{
func
didSelectButtonAt
(
index
:
Int
)
{
viewModel
.
selectDailyWeather
(
at
:
index
)
}
}
1Weather/ViewModels/ForecastViewModel.swift
View file @
92fda9d3
...
...
@@ -9,6 +9,7 @@ import UIKit
protocol
ForecastViewModelDelegate
:
ViewModelDelegate
{
func
selectedDailyWeatherDidChange
()
func
selectedTimePeriodDidChange
()
}
class
ForecastViewModel
:
ViewModelProtocol
{
...
...
@@ -16,6 +17,18 @@ class ForecastViewModel: ViewModelProtocol {
public
weak
var
delegate
:
ForecastViewModelDelegate
?
public
private(set)
var
location
:
Location
?
public
private(set)
var
selectedDailyWeather
:
DailyWeather
?
public
private(set)
var
currentTimePeriod
=
TimePeriod
.
daily
public
var
selectedDailyWeatherIndex
:
Int
{
guard
let
loc
=
self
.
location
else
{
return
-
1
}
for
(
index
,
day
)
in
loc
.
daily
.
enumerated
()
{
if
day
==
selectedDailyWeather
{
return
index
}
}
return
-
1
}
//Private
private
var
locationManager
:
LocationManager
...
...
@@ -47,6 +60,11 @@ class ForecastViewModel: ViewModelProtocol {
}
self
.
delegate
?
.
selectedDailyWeatherDidChange
()
}
public
func
setTimePeriod
(
timePeriod
:
TimePeriod
)
{
self
.
currentTimePeriod
=
timePeriod
self
.
delegate
?
.
selectedTimePeriodDidChange
()
}
}
//MARK:- LocationManager Delegate
...
...
Pods/Pods.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
92fda9d3
...
...
@@ -40,14 +40,14 @@
<
k
e
y
>
isShown
<
/k
e
y
>
<
fa
ls
e
/
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
1
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
2
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
k
e
y
>
SnapKit.xcscheme
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
isShown
<
/k
e
y
>
<
fa
ls
e
/
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
2
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
3
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
k
e
y
>
XMLCoder.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
...
...
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