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
dd049516
Commit
dd049516
authored
Apr 21, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an ability to hide rows on the Today screen that are not needed.
parent
dcd92a0e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
10 deletions
+49
-10
1Weather/UI/View controllers/Today/Cells/TodayCellFactory.swift
+38
-2
1Weather/UI/View controllers/Today/TodayViewController.swift
+6
-8
1Weather/ViewModels/TodayViewModel.swift
+5
-0
No files found.
1Weather/UI/View controllers/Today/Cells/TodayCellFactory.swift
View file @
dd049516
...
...
@@ -30,14 +30,30 @@ private struct CellsToUpdate:OptionSet {
}
private
struct
TodaySection
{
var
rows
:[
TodayCellType
]
var
rows
:
[
TodayCellType
]
var
hiddenRows
=
Set
<
TodayCellType
>
()
{
didSet
{
var
filteredRows
=
allRows
if
!
hiddenRows
.
isEmpty
{
filteredRows
.
removeAll
(
where
:
{
hiddenRows
.
contains
(
$0
)
})
}
rows
=
filteredRows
}
}
let
allRows
:
[
TodayCellType
]
init
(
allRows
:
[
TodayCellType
])
{
self
.
allRows
=
allRows
self
.
rows
=
allRows
}
}
class
TodayCellFactory
:
CellFactoryProtocol
{
//Private
private
var
cellsToUpdate
:
CellsToUpdate
=
[
.
condition
,
.
timePeriod
,
.
precipitation
,
.
dayTime
]
private
let
todayViewModel
:
TodayViewModel
private
var
todaySection
=
TodaySection
(
rows
:
[
.
alert
,
.
forecast
,
.
ad
,
private
var
todaySection
=
TodaySection
(
allRows
:
[
.
alert
,
.
forecast
,
.
ad
,
.
conditions
,
.
forecastPeriod
,
.
precipitation
,
.
airQuality
,
.
dayTime
,
.
sun
,
.
moon
])
...
...
@@ -142,6 +158,7 @@ class TodayCellFactory: CellFactoryProtocol {
public
func
setNeedsUpdate
()
{
cellsToUpdate
=
[
.
condition
,
.
timePeriod
,
.
precipitation
,
.
dayTime
]
setupHiddenRows
()
}
public
func
willDisplay
(
cell
:
UITableViewCell
)
{
...
...
@@ -165,4 +182,23 @@ class TodayCellFactory: CellFactoryProtocol {
break
}
}
private
func
setupHiddenRows
()
{
var
rowsToHide
=
Set
<
TodayCellType
>
()
if
!
AdConfigManager
.
shared
.
adConfig
.
adsEnabled
{
rowsToHide
.
insert
(
.
ad
)
}
let
location
=
self
.
todayViewModel
.
location
if
location
?
.
notifications
?
.
nwsAlers
.
count
??
0
==
0
{
rowsToHide
.
insert
(
.
alert
)
}
if
location
?
.
health
?
.
airQuality
==
nil
{
rowsToHide
.
insert
(
.
airQuality
)
}
todaySection
.
hiddenRows
=
rowsToHide
}
}
1Weather/UI/View controllers/Today/TodayViewController.swift
View file @
dd049516
...
...
@@ -12,7 +12,7 @@ class TodayViewController: UIViewController {
//Private
private
let
coordinator
:
TodayCoordinator
private
let
viewModel
=
TodayViewModel
()
private
let
todayCellFactory
:
TodayCellFactory
private
let
notificationButton
=
UIButton
()
private
let
cityButton
=
NavigationCityButton
()
private
let
tableView
=
UITableView
()
...
...
@@ -26,7 +26,6 @@ class TodayViewController: UIViewController {
init
(
coordinator
:
TodayCoordinator
)
{
self
.
coordinator
=
coordinator
self
.
todayCellFactory
=
TodayCellFactory
(
viewModel
:
viewModel
)
super
.
init
(
nibName
:
nil
,
bundle
:
nil
)
}
...
...
@@ -93,7 +92,7 @@ private extension TodayViewController {
}
func
prepareTableView
()
{
todayCellFactory
.
registerCells
(
on
:
tableView
)
viewModel
.
todayCellFactory
.
registerCells
(
on
:
tableView
)
tableView
.
isHidden
=
true
tableView
.
contentInset
=
.
init
(
top
:
0
,
left
:
0
,
bottom
:
15
,
right
:
0
)
tableView
.
backgroundColor
=
ThemeManager
.
currentTheme
.
baseBackgroundColor
...
...
@@ -114,11 +113,11 @@ private extension TodayViewController {
//MARK:- UITableView Data Source
extension
TodayViewController
:
UITableViewDataSource
{
func
tableView
(
_
tableView
:
UITableView
,
numberOfRowsInSection
section
:
Int
)
->
Int
{
return
todayCellFactory
.
numberOfRows
(
inSection
:
section
)
return
viewModel
.
todayCellFactory
.
numberOfRows
(
inSection
:
section
)
}
func
tableView
(
_
tableView
:
UITableView
,
cellForRowAt
indexPath
:
IndexPath
)
->
UITableViewCell
{
return
todayCellFactory
.
cellFromTableView
(
tableView
:
tableView
,
indexPath
:
indexPath
)
return
viewModel
.
todayCellFactory
.
cellFromTableView
(
tableView
:
tableView
,
indexPath
:
indexPath
)
}
}
...
...
@@ -129,11 +128,11 @@ extension TodayViewController: UITableViewDelegate {
}
func
tableView
(
_
tableView
:
UITableView
,
willDisplay
cell
:
UITableViewCell
,
forRowAt
indexPath
:
IndexPath
)
{
todayCellFactory
.
willDisplay
(
cell
:
cell
)
viewModel
.
todayCellFactory
.
willDisplay
(
cell
:
cell
)
}
func
tableView
(
_
tableView
:
UITableView
,
didEndDisplaying
cell
:
UITableViewCell
,
forRowAt
indexPath
:
IndexPath
)
{
todayCellFactory
.
didHide
(
cell
:
cell
)
viewModel
.
todayCellFactory
.
didHide
(
cell
:
cell
)
}
}
...
...
@@ -143,7 +142,6 @@ extension TodayViewController: ViewModelDelegate {
cityButton
.
configure
(
with
:
viewModel
.
location
)
cityButton
.
isHidden
=
false
tableView
.
isHidden
=
false
todayCellFactory
.
setNeedsUpdate
()
tableView
.
reloadData
()
}
}
1Weather/ViewModels/TodayViewModel.swift
View file @
dd049516
...
...
@@ -13,6 +13,10 @@ class TodayViewModel: ViewModelProtocol {
private
let
locationManager
=
LocationManager
.
shared
private(set)
var
location
:
Location
?
public
lazy
var
todayCellFactory
:
TodayCellFactory
=
{
TodayCellFactory
(
viewModel
:
self
)
}()
deinit
{
locationManager
.
remove
(
delegate
:
self
)
Settings
.
shared
.
delegate
.
remove
(
delegate
:
self
)
...
...
@@ -34,6 +38,7 @@ extension TodayViewModel: LocationManagerDelegate {
func
locationManager
(
_
locationManager
:
LocationManager
,
changedSelectedLocation
newLocation
:
Location
?)
{
DispatchQueue
.
main
.
async
{
self
.
location
=
newLocation
self
.
todayCellFactory
.
setNeedsUpdate
()
self
.
delegate
?
.
viewModelDidChange
(
model
:
self
)
}
}
...
...
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