Commit 9243ce65 by Demid Merzlyakov

IOS-73: add ads to the Forecast creen.

parent 993157e4
......@@ -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
public var timePeriod = TimePeriod.daily
private 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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment