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