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
9243ce65
Commit
9243ce65
authored
May 31, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IOS-73: add ads to the Forecast creen.
parent
993157e4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
3 deletions
+51
-3
1Weather/UI/View controllers/Forecast/Cells/ForecastCellFactory.swift
+50
-2
1Weather/UI/View controllers/Today/Cells/TodayCellFactory.swift
+1
-1
No files found.
1Weather/UI/View controllers/Forecast/Cells/ForecastCellFactory.swift
View file @
9243ce65
...
...
@@ -10,6 +10,7 @@ import UIKit
private
enum
DailyForecastCellType
:
Int
,
CaseIterable
{
case
forecast
=
0
case
forecastInfo
case
ad
// case forecast
// case conditions
// case precipitation
...
...
@@ -21,6 +22,7 @@ private enum DailyForecastCellType:Int, CaseIterable {
private
enum
HourlyForecastCellType
:
Int
,
CaseIterable
{
case
day
case
forecastHourly
case
ad
case
precipitation
case
wind
}
...
...
@@ -39,10 +41,11 @@ class ForecastCellFactory: CellFactoryProtocol {
//Private
private
var
cellsToUpdate
:
CellsToUpdate
=
[
.
dailyTimePeriod
,
.
hourlyTimePeriod
,
.
dailyForecastInfoCell
,
.
precipitation
,
.
wind
]
private
let
forecastViewModel
:
ForecastViewModel
p
ublic
var
timePeriod
=
TimePeriod
.
daily
p
rivate
var
adViewCache
=
[
TimePeriod
:
[
IndexPath
:
AdView
]]()
//Public
var
numberOfSections
:
Int
{
public
var
timePeriod
=
TimePeriod
.
daily
public
var
numberOfSections
:
Int
{
return
1
}
...
...
@@ -63,6 +66,7 @@ class ForecastCellFactory: CellFactoryProtocol {
registerCell
(
type
:
ForecastWindSpeedCell
.
self
,
tableView
:
tableView
)
registerCell
(
type
:
SunPhaseCell
.
self
,
tableView
:
tableView
)
registerCell
(
type
:
MoonPhaseCell
.
self
,
tableView
:
tableView
)
registerCell
(
type
:
AdCell
.
self
,
tableView
:
tableView
)
}
public
func
cellFromTableView
(
tableView
:
UITableView
,
indexPath
:
IndexPath
)
->
UITableViewCell
{
...
...
@@ -88,11 +92,45 @@ class ForecastCellFactory: CellFactoryProtocol {
sunCell
.
updateSunPosition
()
case
let
moonCell
as
MoonPhaseCell
:
moonCell
.
updateMoonPosition
()
case
let
adCell
as
AdCell
:
adCell
.
adView
?
.
start
()
default
:
break
}
}
public
func
didHide
(
cell
:
UITableViewCell
)
{
switch
cell
{
case
let
adCell
as
AdCell
:
adCell
.
adView
?
.
stop
()
default
:
break
}
}
private
func
adView
(
for
timePeriod
:
TimePeriod
,
indexPath
:
IndexPath
)
->
AdView
{
if
let
adView
=
adViewCache
[
self
.
timePeriod
]?[
indexPath
]
{
return
adView
}
let
adView
=
AdView
()
var
placementName
:
String
!
var
timePeriodString
:
String
!
switch
timePeriod
{
case
.
daily
:
placementName
=
placementNameForecastExtendedBanner
timePeriodString
=
"D"
case
.
hourly
:
placementName
=
placementNameForecastHourlyBanner
timePeriodString
=
"H"
}
adView
.
set
(
placementName
:
placementName
,
adType
:
.
banner
)
adView
.
loggingAlias
=
"🔹 Forecast
\(
timePeriodString
!
)
Banner"
var
edited
=
adViewCache
[
timePeriod
]
??
[
IndexPath
:
AdView
]()
edited
[
indexPath
]
=
adView
adViewCache
[
timePeriod
]
=
edited
return
adView
}
//Private
private
func
dailyCellFor
(
tableView
:
UITableView
,
indexPath
:
IndexPath
)
->
UITableViewCell
{
guard
let
cellType
=
DailyForecastCellType
(
rawValue
:
indexPath
.
row
)
else
{
...
...
@@ -137,6 +175,10 @@ class ForecastCellFactory: CellFactoryProtocol {
cell
.
configure
(
with
:
loc
)
}
return
cell
case
.
ad
:
let
cell
=
dequeueReusableCell
(
type
:
AdCell
.
self
,
tableView
:
tableView
,
indexPath
:
indexPath
)
cell
.
adView
=
adView
(
for
:
timePeriod
,
indexPath
:
indexPath
)
return
cell
}
}
...
...
@@ -179,8 +221,14 @@ class ForecastCellFactory: CellFactoryProtocol {
}
}
return
cell
case
.
ad
:
let
cell
=
dequeueReusableCell
(
type
:
AdCell
.
self
,
tableView
:
tableView
,
indexPath
:
indexPath
)
cell
.
adView
=
adView
(
for
:
timePeriod
,
indexPath
:
indexPath
)
return
cell
}
}
}
//MARK:- ForecastTimePeriodCell Delegate
...
...
1Weather/UI/View controllers/Today/Cells/TodayCellFactory.swift
View file @
9243ce65
...
...
@@ -90,7 +90,7 @@ class TodayCellFactory: CellFactoryProtocol {
if
let
adView
=
adViewCache
[
indexPath
]
{
return
adView
}
let
adView
=
adViewCache
[
indexPath
]
??
AdView
()
let
adView
=
AdView
()
adView
.
loggingAlias
=
"📍 Today Banner"
adView
.
set
(
placementName
:
placementNameTodayBanner
,
adType
:
.
banner
)
adViewCache
[
indexPath
]
=
adView
...
...
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