Commit 9970096b by Demid Merzlyakov

Basic showing of alerts.

parent 6e2ff6c8
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
87D815852636CFFE0015A6D1 /* NWSAlertViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87D815842636CFFD0015A6D1 /* NWSAlertViewController.swift */; }; 87D815852636CFFE0015A6D1 /* NWSAlertViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87D815842636CFFD0015A6D1 /* NWSAlertViewController.swift */; };
87D815AA2636D5E60015A6D1 /* NWSAlertCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87D815A92636D5E60015A6D1 /* NWSAlertCoordinator.swift */; }; 87D815AA2636D5E60015A6D1 /* NWSAlertCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87D815A92636D5E60015A6D1 /* NWSAlertCoordinator.swift */; };
87D815AC2636D61D0015A6D1 /* NWSAlertViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87D815AB2636D61D0015A6D1 /* NWSAlertViewModel.swift */; }; 87D815AC2636D61D0015A6D1 /* NWSAlertViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87D815AB2636D61D0015A6D1 /* NWSAlertViewModel.swift */; };
87D815AF2636E6BF0015A6D1 /* NWSForecastOfficeTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87D815AE2636E6BF0015A6D1 /* NWSForecastOfficeTableViewCell.swift */; };
87D815B12636ED850015A6D1 /* NWSAlertCellFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87D815B02636ED850015A6D1 /* NWSAlertCellFactory.swift */; };
87D815B32636F2040015A6D1 /* NWSAlertInfoBlockTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87D815B22636F2040015A6D1 /* NWSAlertInfoBlockTableViewCell.swift */; };
CD1237C3255D5C5900C98139 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1237C2255D5C5900C98139 /* AppDelegate.swift */; }; CD1237C3255D5C5900C98139 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1237C2255D5C5900C98139 /* AppDelegate.swift */; };
CD1237CC255D5C5C00C98139 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CD1237CB255D5C5C00C98139 /* Assets.xcassets */; }; CD1237CC255D5C5C00C98139 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CD1237CB255D5C5C00C98139 /* Assets.xcassets */; };
CD1237F1255D83C500C98139 /* UIColor+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1237F0255D83C500C98139 /* UIColor+Hex.swift */; }; CD1237F1255D83C500C98139 /* UIColor+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1237F0255D83C500C98139 /* UIColor+Hex.swift */; };
...@@ -258,6 +261,9 @@ ...@@ -258,6 +261,9 @@
87D815842636CFFD0015A6D1 /* NWSAlertViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSAlertViewController.swift; sourceTree = "<group>"; }; 87D815842636CFFD0015A6D1 /* NWSAlertViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSAlertViewController.swift; sourceTree = "<group>"; };
87D815A92636D5E60015A6D1 /* NWSAlertCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSAlertCoordinator.swift; sourceTree = "<group>"; }; 87D815A92636D5E60015A6D1 /* NWSAlertCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSAlertCoordinator.swift; sourceTree = "<group>"; };
87D815AB2636D61D0015A6D1 /* NWSAlertViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSAlertViewModel.swift; sourceTree = "<group>"; }; 87D815AB2636D61D0015A6D1 /* NWSAlertViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSAlertViewModel.swift; sourceTree = "<group>"; };
87D815AE2636E6BF0015A6D1 /* NWSForecastOfficeTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSForecastOfficeTableViewCell.swift; sourceTree = "<group>"; };
87D815B02636ED850015A6D1 /* NWSAlertCellFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSAlertCellFactory.swift; sourceTree = "<group>"; };
87D815B22636F2040015A6D1 /* NWSAlertInfoBlockTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSAlertInfoBlockTableViewCell.swift; sourceTree = "<group>"; };
C8C576F6184B547435CFF0F3 /* Pods-1Weather.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-1Weather.debug.xcconfig"; path = "Target Support Files/Pods-1Weather/Pods-1Weather.debug.xcconfig"; sourceTree = "<group>"; }; C8C576F6184B547435CFF0F3 /* Pods-1Weather.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-1Weather.debug.xcconfig"; path = "Target Support Files/Pods-1Weather/Pods-1Weather.debug.xcconfig"; sourceTree = "<group>"; };
CD1237BF255D5C5900C98139 /* 1Weather.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 1Weather.app; sourceTree = BUILT_PRODUCTS_DIR; }; CD1237BF255D5C5900C98139 /* 1Weather.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 1Weather.app; sourceTree = BUILT_PRODUCTS_DIR; };
CD1237C2255D5C5900C98139 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; CD1237C2255D5C5900C98139 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
...@@ -522,11 +528,22 @@ ...@@ -522,11 +528,22 @@
87D815832636CFED0015A6D1 /* NWSAlert */ = { 87D815832636CFED0015A6D1 /* NWSAlert */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
87D815AD2636E6A90015A6D1 /* Cells */,
87D815842636CFFD0015A6D1 /* NWSAlertViewController.swift */, 87D815842636CFFD0015A6D1 /* NWSAlertViewController.swift */,
); );
path = NWSAlert; path = NWSAlert;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
87D815AD2636E6A90015A6D1 /* Cells */ = {
isa = PBXGroup;
children = (
87D815B02636ED850015A6D1 /* NWSAlertCellFactory.swift */,
87D815AE2636E6BF0015A6D1 /* NWSForecastOfficeTableViewCell.swift */,
87D815B22636F2040015A6D1 /* NWSAlertInfoBlockTableViewCell.swift */,
);
path = Cells;
sourceTree = "<group>";
};
CD0A2CC325FA5857006148A4 /* ForecastTimePeriod */ = { CD0A2CC325FA5857006148A4 /* ForecastTimePeriod */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -1550,6 +1567,7 @@ ...@@ -1550,6 +1567,7 @@
CD866A72260F6A5300E96A5C /* SettingsDetailsCell.swift in Sources */, CD866A72260F6A5300E96A5C /* SettingsDetailsCell.swift in Sources */,
CEC5270325E7BB4000DA58A5 /* WdtSurfaceObservation.swift in Sources */, CEC5270325E7BB4000DA58A5 /* WdtSurfaceObservation.swift in Sources */,
CE28474F26159857006C8DC5 /* HealthSource.swift in Sources */, CE28474F26159857006C8DC5 /* HealthSource.swift in Sources */,
87D815AF2636E6BF0015A6D1 /* NWSForecastOfficeTableViewCell.swift in Sources */,
CE13B80F262480B3007CBD4D /* BRNativeBannerContainerView.swift in Sources */, CE13B80F262480B3007CBD4D /* BRNativeBannerContainerView.swift in Sources */,
CEAFF08C25DFC6BD00DF4EBF /* DailyWeather.swift in Sources */, CEAFF08C25DFC6BD00DF4EBF /* DailyWeather.swift in Sources */,
CEDE4F0B25EFA3A7007457E9 /* UpdatableModelObject.swift in Sources */, CEDE4F0B25EFA3A7007457E9 /* UpdatableModelObject.swift in Sources */,
...@@ -1624,6 +1642,7 @@ ...@@ -1624,6 +1642,7 @@
CE8962A526175DF500CA274A /* _CoreHourlyWeather.swift in Sources */, CE8962A526175DF500CA274A /* _CoreHourlyWeather.swift in Sources */,
CEDE4E8325EEFD56007457E9 /* WdtLocationResponse.swift in Sources */, CEDE4E8325EEFD56007457E9 /* WdtLocationResponse.swift in Sources */,
CD37D3FE260DF726002669D6 /* SettingsCellFactory.swift in Sources */, CD37D3FE260DF726002669D6 /* SettingsCellFactory.swift in Sources */,
87D815B12636ED850015A6D1 /* NWSAlertCellFactory.swift in Sources */,
CD8E041625F8F91B001785B6 /* ForecastCellFactory.swift in Sources */, CD8E041625F8F91B001785B6 /* ForecastCellFactory.swift in Sources */,
87C1720D25FF870600DA3464 /* GeoNamesPlace.swift in Sources */, 87C1720D25FF870600DA3464 /* GeoNamesPlace.swift in Sources */,
CE8962A826175DF500CA274A /* _CoreCurrentWeather.swift in Sources */, CE8962A826175DF500CA274A /* _CoreCurrentWeather.swift in Sources */,
...@@ -1673,6 +1692,7 @@ ...@@ -1673,6 +1692,7 @@
CE13B816262480B3007CBD4D /* NativeAdLoader.swift in Sources */, CE13B816262480B3007CBD4D /* NativeAdLoader.swift in Sources */,
CDF9BF8E26133D050037847D /* LocationSearchCoordinator.swift in Sources */, CDF9BF8E26133D050037847D /* LocationSearchCoordinator.swift in Sources */,
CD86246125E662BC0097F3FB /* SunUvLineView.swift in Sources */, CD86246125E662BC0097F3FB /* SunUvLineView.swift in Sources */,
87D815B32636F2040015A6D1 /* NWSAlertInfoBlockTableViewCell.swift in Sources */,
CD32CE0B260C744A00235081 /* MenuCoordinator.swift in Sources */, CD32CE0B260C744A00235081 /* MenuCoordinator.swift in Sources */,
CD55E0BB2615EE2400CC4DC7 /* PollutantView.swift in Sources */, CD55E0BB2615EE2400CC4DC7 /* PollutantView.swift in Sources */,
CE13B81C262480B3007CBD4D /* Interstitial.swift in Sources */, CE13B81C262480B3007CBD4D /* Interstitial.swift in Sources */,
......
{
"images" : [
{
"filename" : "groupCopy2.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "groupCopy2@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "groupCopy2@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
//
// NWSAlertCellFactory.swift
// 1Weather
//
// Created by Demid Merzlyakov on 26.04.2021.
//
import UIKit
fileprivate enum NWSAlertCellType: Int {
case header = 0
case forecastOffice
case extendedInfoBlock
case ad
}
fileprivate protocol NWSAlertTableViewSection {
init(alert: NWSAlert)
var numberOfRows: Int { get }
mutating func update(with alert: NWSAlert)
func type(forRow row: Int) -> NWSAlertCellType
}
fileprivate struct HeaderSection: NWSAlertTableViewSection {
init(alert: NWSAlert) {
// do nothing
}
func update(with alert: NWSAlert) {
//do nothing
}
private let rows: [NWSAlertCellType] = [.header, .forecastOffice]
var numberOfRows: Int {
return rows.count
}
func type(forRow row: Int) -> NWSAlertCellType {
return rows[row]
}
}
fileprivate struct ExtendedInfoSection: NWSAlertTableViewSection {
private var alert: NWSAlert
init(alert: NWSAlert) {
self.alert = alert
}
var numberOfRows: Int {
alert.extendedInfo?.infoBlocks.count ?? 0
}
mutating func update(with alert: NWSAlert) {
self.alert = alert
}
func type(forRow row: Int) -> NWSAlertCellType {
return .extendedInfoBlock
}
let rows: [NWSAlertCellType] = [.extendedInfoBlock]
}
class NWSAlertCellFactory: CellFactoryProtocol {
var alert: NWSAlert {
didSet {
for i in 0..<sections.count {
sections[i].update(with: alert)
}
}
}
init(alert: NWSAlert) {
self.alert = alert
self.sections = [HeaderSection(alert: alert), ExtendedInfoSection(alert: alert)]
}
fileprivate var sections: [NWSAlertTableViewSection]
private var adViewCache = [IndexPath: AdView]()
var numberOfSections: Int {
return sections.count
}
func numberOfRows(inSection section: Int) -> Int {
sections[section].numberOfRows
}
private func adView(for indexPath: IndexPath) -> AdView {
if let adView = adViewCache[indexPath] {
return adView
}
let adView = adViewCache[indexPath] ?? AdView()
adView.loggingAlias = "📍 Today Banner"
adView.set(placementName: placementNameTodayBanner, adType: .banner)
adViewCache[indexPath] = adView
return adView
}
func registerCells(on tableView: UITableView) {
registerCell(type: NWSAlertCell.self, tableView: tableView)
registerCell(type: NWSForecastOfficeTableViewCell.self, tableView: tableView)
registerCell(type: NWSAlertInfoBlockTableViewCell.self, tableView: tableView)
registerCell(type: AdCell.self, tableView: tableView)
}
func cellFromTableView(tableView: UITableView, indexPath: IndexPath) -> UITableViewCell {
let section = sections[indexPath.section]
let type = section.type(forRow: indexPath.row)
switch type {
case .header:
let alertCell = dequeueReusableCell(type: NWSAlertCell.self, tableView: tableView, indexPath: indexPath)
alertCell.configure(with: alert)
return alertCell
case .forecastOffice:
let forecastOfficeCell = dequeueReusableCell(type: NWSForecastOfficeTableViewCell.self, tableView: tableView, indexPath: indexPath)
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 {
return UITableViewCell()
}
let extendedInfoBlockCell = dequeueReusableCell(type: NWSAlertInfoBlockTableViewCell.self, tableView: tableView, indexPath: indexPath)
extendedInfoBlockCell.configure(with: info)
return extendedInfoBlockCell
case .ad:
let adCell = dequeueReusableCell(type: AdCell.self, tableView: tableView, indexPath: indexPath)
adCell.adView = adView(for: indexPath)
return adCell
}
}
public func willDisplay(cell: UITableViewCell) {
switch cell {
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
}
}
}
//
// NWSAlertInfoBlockTableViewCell.swift
// 1Weather
//
// Created by Demid Merzlyakov on 26.04.2021.
//
import UIKit
class NWSAlertInfoBlockTableViewCell: UITableViewCell {
let titleLabel = UILabel()
let detailsLabel = UILabel()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public func configure(with info: NWSAlertInfoBlock) {
for subview in contentView.subviews {
subview.removeFromSuperview()
}
titleLabel.removeFromSuperview()
detailsLabel.removeFromSuperview()
let vStack = UIStackView()
vStack.axis = .vertical
contentView.addSubview(vStack)
if info.title?.isEmpty ?? false {
titleLabel.text = info.title
vStack.addSubview(titleLabel)
}
if info.text?.isEmpty ?? false {
detailsLabel.text = info.text
vStack.addSubview(detailsLabel)
}
vStack.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
}
}
// MARK: - UI Setup
extension NWSAlertInfoBlockTableViewCell {
func prepareLabels() {
titleLabel.font = AppFont.SFPro.bold(size: 18)
detailsLabel.font = AppFont.SFPro.regular(size: 14)
titleLabel.textColor = UIColor(named: "notifications_primary_text")
detailsLabel.textColor = UIColor(named: "notifications_primary_text")
}
}
//
// NWSForecastOfficeTableViewCell.swift
// 1Weather
//
// Created by Demid Merzlyakov on 26.04.2021.
//
import UIKit
import SnapKit
class NWSForecastOfficeTableViewCell: UITableViewCell {
var alert: NWSAlert?
private let officeTitleLabel = UILabel()
private let sentLabel = UILabel()
private let expiresLabel = UILabel()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
prepareSubviews()
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configure(with alert: NWSAlert) {
}
func prepareSubviews() {
}
}
...@@ -12,6 +12,8 @@ class NWSAlertViewController: UIViewController { ...@@ -12,6 +12,8 @@ class NWSAlertViewController: UIViewController {
private let viewModel: NWSAlertViewModel private let viewModel: NWSAlertViewModel
private var localizationObserver: Any? private var localizationObserver: Any?
private let tableView = UITableView()
init(coordinator: NWSAlertCoordinator, viewModel: NWSAlertViewModel) { init(coordinator: NWSAlertCoordinator, viewModel: NWSAlertViewModel) {
self.viewModel = viewModel self.viewModel = viewModel
self.coordinator = coordinator self.coordinator = coordinator
...@@ -25,6 +27,7 @@ class NWSAlertViewController: UIViewController { ...@@ -25,6 +27,7 @@ class NWSAlertViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
prepareViewController() prepareViewController()
prepareNavigationBar() prepareNavigationBar()
prepareTableView()
} }
deinit { deinit {
...@@ -43,10 +46,6 @@ class NWSAlertViewController: UIViewController { ...@@ -43,10 +46,6 @@ class NWSAlertViewController: UIViewController {
@objc private func handleCloseButton() { @objc private func handleCloseButton() {
close() close()
} }
private func updateUI() {
}
} }
//MARK: - UI Setup //MARK: - UI Setup
...@@ -68,13 +67,44 @@ extension NWSAlertViewController { ...@@ -68,13 +67,44 @@ extension NWSAlertViewController {
func prepareNavigationBar() { func prepareNavigationBar() {
title = "notifications.title".localized() title = "notifications.title".localized()
} }
func prepareTableView() {
view.addSubview(tableView)
viewModel.cellFactory.registerCells(on: tableView)
tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = .none
tableView.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
}
} }
extension NWSAlertViewController: ViewModelDelegate { extension NWSAlertViewController: ViewModelDelegate {
func viewModelDidChange<P: ViewModelProtocol>(model:P) { func viewModelDidChange<P: ViewModelProtocol>(model:P) {
DispatchQueue.main.async { DispatchQueue.main.async {
self.updateUI() self.tableView.reloadData()
} }
} }
} }
// MARK: UITableView Delegate & DataSource
extension NWSAlertViewController: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
viewModel.cellFactory.numberOfSections
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
viewModel.cellFactory.numberOfRows(inSection: section)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
viewModel.cellFactory.cellFromTableView(tableView: tableView, indexPath: indexPath)
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
UITableView.automaticDimension
}
}
...@@ -10,7 +10,7 @@ import UIKit ...@@ -10,7 +10,7 @@ import UIKit
class NWSAlertCell: UITableViewCell { class NWSAlertCell: UITableViewCell {
// TODO: we don't have an image for this one? // TODO: we don't have an image for this one?
// private let headerImage = UIImageView() // private let headerImage = UIImageView()
private let alertIconImageView = UIImageView(image: UIImage(named: "notifications_alert_icon")) private let alertIconImageView = UIImageView(image: UIImage(named: "alert"))
private let headerActiveExpiredLabel = UILabel() private let headerActiveExpiredLabel = UILabel()
private let alertTextLabel = UILabel() private let alertTextLabel = UILabel()
private let alertLocationLabel = UILabel() private let alertLocationLabel = UILabel()
...@@ -34,6 +34,10 @@ class NWSAlertCell: UITableViewCell { ...@@ -34,6 +34,10 @@ class NWSAlertCell: UITableViewCell {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
}
private static let expiryDateFormatter: DateFormatter = { private static let expiryDateFormatter: DateFormatter = {
let dateFormatter = DateFormatter() let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .full dateFormatter.dateStyle = .full
...@@ -99,6 +103,7 @@ class NWSAlertCell: UITableViewCell { ...@@ -99,6 +103,7 @@ class NWSAlertCell: UITableViewCell {
private extension NWSAlertCell { private extension NWSAlertCell {
var primaryTextColor: UIColor! { var primaryTextColor: UIColor! {
// TODO: use ThemeManager here.
UIColor(named: "notifications_primary_text") UIColor(named: "notifications_primary_text")
} }
...@@ -155,7 +160,8 @@ private extension NWSAlertCell { ...@@ -155,7 +160,8 @@ private extension NWSAlertCell {
} }
func prepareFooter() { func prepareFooter() {
let locationIconImageView = UIImageView(image: UIImage(named: "notifications_alert_location_icon")) let locationIconImageView = UIImageView(image: UIImage(named: "city_pin"))
locationIconImageView.tintColor = primaryTextColor
alertLocationLabel.font = AppFont.SFPro.regular(size: 12) alertLocationLabel.font = AppFont.SFPro.regular(size: 12)
alertLocationLabel.textColor = primaryTextColor alertLocationLabel.textColor = primaryTextColor
alertLocationLabel.numberOfLines = 0 alertLocationLabel.numberOfLines = 0
......
...@@ -77,6 +77,7 @@ private extension NotificationsViewController { ...@@ -77,6 +77,7 @@ private extension NotificationsViewController {
tableView.register(NWSAlertCell.self, forCellReuseIdentifier: NWSAlertCell.self.kIdentifier) tableView.register(NWSAlertCell.self, forCellReuseIdentifier: NWSAlertCell.self.kIdentifier)
tableView.delegate = self tableView.delegate = self
tableView.dataSource = self tableView.dataSource = self
tableView.separatorInset = .zero
tableView.snp.makeConstraints { (make) in tableView.snp.makeConstraints { (make) in
make.edges.equalToSuperview() make.edges.equalToSuperview()
......
...@@ -11,6 +11,7 @@ class NWSAlertViewModel: ViewModelProtocol { ...@@ -11,6 +11,7 @@ class NWSAlertViewModel: ViewModelProtocol {
public weak var delegate: ViewModelDelegate? public weak var delegate: ViewModelDelegate?
public private(set) var alert: NWSAlert public private(set) var alert: NWSAlert
private let alertsManager: NWSAlertsManager private let alertsManager: NWSAlertsManager
public var cellFactory: NWSAlertCellFactory
deinit { deinit {
alertsManager.delegates.remove(delegate: self) alertsManager.delegates.remove(delegate: self)
...@@ -19,6 +20,7 @@ class NWSAlertViewModel: ViewModelProtocol { ...@@ -19,6 +20,7 @@ class NWSAlertViewModel: ViewModelProtocol {
public init(alert: NWSAlert, alertsManager: NWSAlertsManager = LocationManager.shared.nwsAlertsManager) { public init(alert: NWSAlert, alertsManager: NWSAlertsManager = LocationManager.shared.nwsAlertsManager) {
self.alert = alert self.alert = alert
self.alertsManager = alertsManager self.alertsManager = alertsManager
cellFactory = NWSAlertCellFactory(alert: alert)
alertsManager.delegates.add(delegate: self) alertsManager.delegates.add(delegate: self)
} }
} }
...@@ -31,6 +33,7 @@ extension NWSAlertViewModel: NWSAlertsManagerDelegate { ...@@ -31,6 +33,7 @@ extension NWSAlertViewModel: NWSAlertsManagerDelegate {
func extendedInfoAvailable(from alertsManager: NWSAlertsManager, for alert: NWSAlert) { func extendedInfoAvailable(from alertsManager: NWSAlertsManager, for alert: NWSAlert) {
if self.alert == alert { if self.alert == alert {
self.alert = alert self.alert = alert
self.cellFactory.alert = alert
self.delegate?.viewModelDidChange(model: self) self.delegate?.viewModelDidChange(model: self)
} }
} }
......
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