Commit d2321de6 by Demid Merzlyakov

NWSAlert screen: added an ad.

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