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
224238c5
Commit
224238c5
authored
Mar 30, 2021
by
Dmitriy Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed architrecture of TodayViewController
parent
5255d67c
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
42 additions
and
35 deletions
+42
-35
1Weather.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
+1
-1
1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
1Weather/Coordinators/TodayCoordinator.swift
+1
-2
1Weather/UI/View controllers/Today/Cells/TodayCellFactory.swift
+24
-9
1Weather/UI/View controllers/Today/TodayViewController.swift
+9
-7
1Weather/ViewModels/TodayViewModel.swift
+6
-15
Pods/Pods.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
+1
-1
No files found.
1Weather.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
224238c5
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
<
k
e
y
>
1Weather.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
k
e
y
>
1Weather.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
6
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
5
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
k
e
y
>
PG
(
Playground
)
1.xcscheme
<
/k
e
y
>
<
k
e
y
>
PG
(
Playground
)
1.xcscheme
<
/k
e
y
>
<
d
i
c
t
>
<
d
i
c
t
>
...
...
1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
View file @
224238c5
No preview for this file type
1Weather/Coordinators/TodayCoordinator.swift
View file @
224238c5
...
@@ -9,7 +9,6 @@ import UIKit
...
@@ -9,7 +9,6 @@ import UIKit
class
TodayCoordinator
:
Coordinator
{
class
TodayCoordinator
:
Coordinator
{
//Private
//Private
private
let
todayViewModel
=
TodayViewModel
(
locationManager
:
LocationManager
.
shared
)
// TODO: get rid of singleton maybe?
private
let
navigationController
=
UINavigationController
(
nibName
:
nil
,
bundle
:
nil
)
private
let
navigationController
=
UINavigationController
(
nibName
:
nil
,
bundle
:
nil
)
private
var
tabBarController
:
UITabBarController
?
private
var
tabBarController
:
UITabBarController
?
...
@@ -22,7 +21,7 @@ class TodayCoordinator:Coordinator {
...
@@ -22,7 +21,7 @@ class TodayCoordinator:Coordinator {
}
}
func
start
()
{
func
start
()
{
let
todayViewController
=
TodayViewController
(
viewModel
:
todayViewModel
)
let
todayViewController
=
TodayViewController
()
navigationController
.
viewControllers
=
[
todayViewController
]
navigationController
.
viewControllers
=
[
todayViewController
]
tabBarController
?
.
add
(
viewController
:
navigationController
)
tabBarController
?
.
add
(
viewController
:
navigationController
)
}
}
...
...
1Weather/UI/View controllers/Today/Cells/TodayCellFactory.swift
View file @
224238c5
...
@@ -7,8 +7,9 @@
...
@@ -7,8 +7,9 @@
import
UIKit
import
UIKit
private
enum
TodayCellType
:
Int
,
CaseIterable
{
private
enum
TodayCellType
:
Int
{
case
forecast
=
0
case
alert
=
0
case
forecast
case
ad
case
ad
case
conditions
case
conditions
case
forecastPeriod
case
forecastPeriod
...
@@ -18,17 +19,32 @@ private enum TodayCellType:Int, CaseIterable {
...
@@ -18,17 +19,32 @@ private enum TodayCellType:Int, CaseIterable {
case
moon
case
moon
}
}
private
struct
TodaySection
{
var
rows
:[
TodayCellType
]
}
class
TodayCellFactory
:
CellFactoryProtocol
{
class
TodayCellFactory
:
CellFactoryProtocol
{
public
var
onGetLocation
:(()
->
Location
?)?
//Private
private
let
todayViewModel
:
TodayViewModel
private
var
todaySection
=
TodaySection
(
rows
:
[
/*.alert,*/
.
forecast
,
.
ad
,
.
conditions
,
.
forecastPeriod
,
.
precipitation
,
.
dayTime
,
.
sun
,
.
moon
])
//Public
init
(
viewModel
:
TodayViewModel
)
{
self
.
todayViewModel
=
viewModel
}
public
var
numberOfSections
:
Int
{
public
var
numberOfSections
:
Int
{
return
1
return
1
}
}
public
func
numberOfRows
(
inSection
section
:
Int
)
->
Int
{
public
func
numberOfRows
(
inSection
section
:
Int
)
->
Int
{
return
TodayCellType
.
allCase
s
.
count
return
todaySection
.
row
s
.
count
}
}
public
func
registerCells
(
on
tableView
:
UITableView
)
{
public
func
registerCells
(
on
tableView
:
UITableView
)
{
registerCell
(
type
:
TodayAlertCell
.
self
,
tableView
:
tableView
)
registerCell
(
type
:
TodayForecastCell
.
self
,
tableView
:
tableView
)
registerCell
(
type
:
TodayForecastCell
.
self
,
tableView
:
tableView
)
registerCell
(
type
:
TodayAdCell
.
self
,
tableView
:
tableView
)
registerCell
(
type
:
TodayAdCell
.
self
,
tableView
:
tableView
)
registerCell
(
type
:
TodayConditionsCell
.
self
,
tableView
:
tableView
)
registerCell
(
type
:
TodayConditionsCell
.
self
,
tableView
:
tableView
)
...
@@ -41,15 +57,14 @@ class TodayCellFactory: CellFactoryProtocol {
...
@@ -41,15 +57,14 @@ class TodayCellFactory: CellFactoryProtocol {
}
}
public
func
cellFromTableView
(
tableView
:
UITableView
,
indexPath
:
IndexPath
)
->
UITableViewCell
{
public
func
cellFromTableView
(
tableView
:
UITableView
,
indexPath
:
IndexPath
)
->
UITableViewCell
{
guard
let
cellType
=
TodayCellType
(
rawValue
:
indexPath
.
row
)
else
{
let
cellType
=
todaySection
.
rows
[
indexPath
.
row
]
return
UITableViewCell
()
guard
let
loc
=
self
.
todayViewModel
.
location
else
{
}
guard
let
loc
=
self
.
onGetLocation
?()
else
{
return
UITableViewCell
()
return
UITableViewCell
()
}
}
switch
cellType
{
switch
cellType
{
case
.
alert
:
return
dequeueReusableCell
(
type
:
TodayAlertCell
.
self
,
tableView
:
tableView
,
indexPath
:
indexPath
)
case
.
forecast
:
case
.
forecast
:
let
cell
=
dequeueReusableCell
(
type
:
TodayForecastCell
.
self
,
tableView
:
tableView
,
indexPath
:
indexPath
)
let
cell
=
dequeueReusableCell
(
type
:
TodayForecastCell
.
self
,
tableView
:
tableView
,
indexPath
:
indexPath
)
cell
.
configure
(
with
:
loc
)
cell
.
configure
(
with
:
loc
)
...
...
1Weather/UI/View controllers/Today/TodayViewController.swift
View file @
224238c5
...
@@ -10,8 +10,9 @@ import CoreLocation
...
@@ -10,8 +10,9 @@ import CoreLocation
class
TodayViewController
:
UIViewController
{
class
TodayViewController
:
UIViewController
{
//Private
//Private
private
let
viewModel
=
TodayViewModel
()
private
let
todayCellFactory
:
TodayCellFactory
private
let
cityButton
=
NavigationCityButton
()
private
let
cityButton
=
NavigationCityButton
()
private
let
viewModel
:
TodayViewModel
private
let
tableView
=
UITableView
()
private
let
tableView
=
UITableView
()
private
var
localizationObserver
:
Any
?
private
var
localizationObserver
:
Any
?
...
@@ -21,8 +22,8 @@ class TodayViewController: UIViewController {
...
@@ -21,8 +22,8 @@ class TodayViewController: UIViewController {
}
}
}
}
init
(
viewModel
:
TodayViewModel
)
{
init
()
{
self
.
viewModel
=
viewModel
self
.
todayCellFactory
=
TodayCellFactory
(
viewModel
:
viewModel
)
super
.
init
(
nibName
:
nil
,
bundle
:
nil
)
super
.
init
(
nibName
:
nil
,
bundle
:
nil
)
}
}
...
@@ -90,7 +91,7 @@ private extension TodayViewController {
...
@@ -90,7 +91,7 @@ private extension TodayViewController {
}
}
func
prepareTableView
()
{
func
prepareTableView
()
{
viewModel
.
todayCellFactory
.
registerCells
(
on
:
tableView
)
todayCellFactory
.
registerCells
(
on
:
tableView
)
tableView
.
contentInset
=
.
init
(
top
:
0
,
left
:
0
,
bottom
:
15
,
right
:
0
)
tableView
.
contentInset
=
.
init
(
top
:
0
,
left
:
0
,
bottom
:
15
,
right
:
0
)
tableView
.
backgroundColor
=
ThemeManager
.
currentTheme
.
baseBackgroundColor
tableView
.
backgroundColor
=
ThemeManager
.
currentTheme
.
baseBackgroundColor
tableView
.
separatorStyle
=
.
none
tableView
.
separatorStyle
=
.
none
...
@@ -110,11 +111,11 @@ private extension TodayViewController {
...
@@ -110,11 +111,11 @@ private extension TodayViewController {
//MARK:- UITableView Data Source
//MARK:- UITableView Data Source
extension
TodayViewController
:
UITableViewDataSource
{
extension
TodayViewController
:
UITableViewDataSource
{
func
tableView
(
_
tableView
:
UITableView
,
numberOfRowsInSection
section
:
Int
)
->
Int
{
func
tableView
(
_
tableView
:
UITableView
,
numberOfRowsInSection
section
:
Int
)
->
Int
{
return
viewModel
.
todayCellFactory
.
numberOfRows
(
inSection
:
section
)
return
todayCellFactory
.
numberOfRows
(
inSection
:
section
)
}
}
func
tableView
(
_
tableView
:
UITableView
,
cellForRowAt
indexPath
:
IndexPath
)
->
UITableViewCell
{
func
tableView
(
_
tableView
:
UITableView
,
cellForRowAt
indexPath
:
IndexPath
)
->
UITableViewCell
{
return
viewModel
.
todayCellFactory
.
cellFromTableView
(
tableView
:
tableView
,
indexPath
:
indexPath
)
return
todayCellFactory
.
cellFromTableView
(
tableView
:
tableView
,
indexPath
:
indexPath
)
}
}
}
}
...
@@ -127,13 +128,14 @@ extension TodayViewController: UITableViewDelegate {
...
@@ -127,13 +128,14 @@ extension TodayViewController: UITableViewDelegate {
}
}
func
tableView
(
_
tableView
:
UITableView
,
willDisplay
cell
:
UITableViewCell
,
forRowAt
indexPath
:
IndexPath
)
{
func
tableView
(
_
tableView
:
UITableView
,
willDisplay
cell
:
UITableViewCell
,
forRowAt
indexPath
:
IndexPath
)
{
viewModel
.
todayCellFactory
.
willDisplay
(
cell
:
cell
)
todayCellFactory
.
willDisplay
(
cell
:
cell
)
}
}
}
}
//MARK:- ViewModel Delegate
//MARK:- ViewModel Delegate
extension
TodayViewController
:
ViewModelDelegate
{
extension
TodayViewController
:
ViewModelDelegate
{
func
viewModelDidChange
<
P
>
(
model
:
P
)
where
P
:
ViewModelProtocol
{
func
viewModelDidChange
<
P
>
(
model
:
P
)
where
P
:
ViewModelProtocol
{
print
(
"TodayViewModel did change"
)
cityButton
.
configure
(
with
:
viewModel
.
location
)
cityButton
.
configure
(
with
:
viewModel
.
location
)
cityButton
.
isHidden
=
false
cityButton
.
isHidden
=
false
tableView
.
reloadData
()
tableView
.
reloadData
()
...
...
1Weather/ViewModels/TodayViewModel.swift
View file @
224238c5
...
@@ -9,31 +9,22 @@ import UIKit
...
@@ -9,31 +9,22 @@ import UIKit
class
TodayViewModel
:
ViewModelProtocol
{
class
TodayViewModel
:
ViewModelProtocol
{
//Public
//Public
public
let
todayCellFactory
=
TodayCellFactory
()
public
weak
var
delegate
:
ViewModelDelegate
?
public
weak
var
delegate
:
ViewModelDelegate
?
public
private(set)
var
location
:
Location
?
private(set)
var
location
:
Location
?
//Private
private
var
locationManager
:
LocationManager
deinit
{
deinit
{
self
.
locationManager
.
remove
(
delegate
:
self
)
LocationManager
.
shared
.
remove
(
delegate
:
self
)
Settings
.
shared
.
delegate
.
remove
(
delegate
:
self
)
Settings
.
shared
.
delegate
.
remove
(
delegate
:
self
)
}
}
public
init
(
locationManager
:
LocationManager
)
{
public
init
()
{
self
.
location
Manager
=
locationManager
self
.
location
=
LocationManager
.
shared
.
currentLocation
locationManager
.
add
(
delegate
:
self
)
LocationManager
.
shared
.
add
(
delegate
:
self
)
Settings
.
shared
.
delegate
.
add
(
delegate
:
self
)
Settings
.
shared
.
delegate
.
add
(
delegate
:
self
)
//Setup factory callback
todayCellFactory
.
onGetLocation
=
{[
weak
self
]
in
return
self
?
.
location
}
}
}
public
func
updateWeather
()
{
public
func
updateWeather
()
{
locationManager
.
updateWeather
()
LocationManager
.
shared
.
updateWeather
()
}
}
}
}
...
...
Pods/Pods.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
224238c5
...
@@ -52,7 +52,7 @@
...
@@ -52,7 +52,7 @@
<
k
e
y
>
XMLCoder.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
k
e
y
>
XMLCoder.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
5
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
6
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
k
e
y
>
SuppressBuildableAutocreation
<
/k
e
y
>
<
k
e
y
>
SuppressBuildableAutocreation
<
/k
e
y
>
...
...
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