Commit d2321de6 by Demid Merzlyakov

NWSAlert screen: added an ad.

parent c2757262
......@@ -42,13 +42,14 @@ fileprivate struct HeaderSection: NWSAlertTableViewSection {
fileprivate struct ExtendedInfoSection: NWSAlertTableViewSection {
private var alert: NWSAlert
private let countOfAds = 1
init(alert: NWSAlert) {
self.alert = alert
}
var numberOfRows: Int {
alert.extendedInfo?.infoBlocks.count ?? 0
countOfAds + (alert.extendedInfo?.infoBlocks.count ?? 0)
}
mutating func update(with alert: NWSAlert) {
......@@ -56,7 +57,18 @@ fileprivate struct ExtendedInfoSection: NWSAlertTableViewSection {
}
func type(forRow row: Int) -> NWSAlertCellType {
return .extendedInfoBlock
if numberOfRows == 1 {
return .ad
}
else {
if row == 1 {
return .ad
}
else {
return .extendedInfoBlock
}
}
}
let rows: [NWSAlertCellType] = [.extendedInfoBlock]
......@@ -93,8 +105,8 @@ class NWSAlertCellFactory: CellFactoryProtocol {
return adView
}
let adView = adViewCache[indexPath] ?? AdView()
adView.loggingAlias = "📍 Today Banner"
adView.set(placementName: placementNameTodayBanner, adType: .banner)
adView.loggingAlias = "⚠️ Alert Banner"
adView.set(placementName: placementNamePrecipitationBanner, adType: .banner)
adViewCache[indexPath] = adView
return adView
}
......@@ -119,8 +131,8 @@ class NWSAlertCellFactory: CellFactoryProtocol {
forecastOfficeCell.configure(with: alert)
return forecastOfficeCell
case .extendedInfoBlock:
#warning("We've got to handle ads here.")
guard let info = alert.extendedInfo?.infoBlocks[indexPath.row] else {
let adsCount = adViewCache.keys.filter({ $0.row < indexPath.row}).count
guard let info = alert.extendedInfo?.infoBlocks[indexPath.row - adsCount] else {
return UITableViewCell()
}
let extendedInfoBlockCell = dequeueReusableCell(type: NWSAlertInfoBlockTableViewCell.self, tableView: tableView, indexPath: indexPath)
......
......@@ -73,10 +73,10 @@ extension NWSAlertInfoBlockTableViewCell {
func prepareContainer() {
contentView.addSubview(containerView)
containerView.snp.makeConstraints { (make) in
make.top.equalToSuperview().inset(18)
make.top.equalToSuperview()
make.left.equalToSuperview().inset(18)
make.right.equalToSuperview().inset(18)
make.bottom.equalToSuperview()
make.bottom.equalToSuperview().inset(18)
}
containerView.layer.cornerRadius = 8
containerView.backgroundColor = UIColor(named: "notifications_nwsalert_tile_background")
......
......@@ -91,10 +91,10 @@ class NWSForecastOfficeTableViewCell: UITableViewCell {
private func prepareContainer() {
contentView.addSubview(containerView)
containerView.snp.makeConstraints { (make) in
make.top.equalToSuperview().inset(18)
make.top.equalToSuperview()
make.left.equalToSuperview().inset(18)
make.right.equalToSuperview().inset(18)
make.bottom.equalToSuperview()
make.bottom.equalToSuperview().inset(18)
}
containerView.layer.cornerRadius = 8
containerView.backgroundColor = UIColor(named: "notifications_nwsalert_tile_background")
......
......@@ -110,4 +110,12 @@ extension NWSAlertViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 160
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
viewModel.cellFactory.willDisplay(cell: cell)
}
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
viewModel.cellFactory.didHide(cell: cell)
}
}
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