Commit c2757262 by Demid Merzlyakov

Alerts display.

parent 3fcf0f43
......@@ -284,7 +284,7 @@ public class LocationManager {
}
}
log.info("Update weather for: \(location); type: \(updateType)")
// log.info("Update weather for: \(location); type: \(updateType)")
weatherUpdateSource.updateWeather(for: location, type: updateType) { [weak self] (updatedLocation, error) in
guard let self = self else { return }
......@@ -295,11 +295,16 @@ public class LocationManager {
}
}
else {
if let error = error {
self.log.error("Update weather (\(location)) error: \(error)")
if let wdtError = error as? WdtWeatherSourceError {
if case WdtWeatherSourceError.alreadyBeingUpdated = wdtError {
// do nothing
}
else {
self.log.error("Update weather (\(location)) error: \(error)")
}
}
else {
self.log.error("Update weather (\(location)) error: unknown error")
self.log.error("Update weather (\(location)) error: \(error)")
}
}
}
......
{
"colors" : [
{
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.988",
"green" : "0.968",
"red" : "0.965"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "26",
"green" : "23",
"red" : "23"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"colors" : [
{
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.592",
"green" : "0.592",
"red" : "0.592"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.592",
"green" : "0.592",
"red" : "0.592"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000",
"red" : "1.000"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.169",
"green" : "0.149",
"red" : "0.149"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -23,6 +23,7 @@
"notifications.nwsCell.expired" = "Expired";
"notifications.nwsCell.staticTitle" = "NWS ALERT";
"notifications.nwsCell.remainsInEffectUntil" = "remains in effect until";
"notifications.nwsAlert.forecastOffice" = "Forecast office";
//Forecast
"forecast.sunny" = "Sunny";
......
......@@ -112,7 +112,7 @@ class NWSAlertCellFactory: CellFactoryProtocol {
switch type {
case .header:
let alertCell = dequeueReusableCell(type: NWSAlertCell.self, tableView: tableView, indexPath: indexPath)
alertCell.configure(with: alert)
alertCell.configure(with: alert, overrideBackgroundColorName: "notifications_nwsalert_background")
return alertCell
case .forecastOffice:
let forecastOfficeCell = dequeueReusableCell(type: NWSForecastOfficeTableViewCell.self, tableView: tableView, indexPath: indexPath)
......
......@@ -10,9 +10,12 @@ import UIKit
class NWSAlertInfoBlockTableViewCell: UITableViewCell {
let titleLabel = UILabel()
let detailsLabel = UILabel()
let containerView = UIView()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
prepareSelf()
prepareContainer()
}
@available(*, unavailable)
......@@ -21,37 +24,76 @@ class NWSAlertInfoBlockTableViewCell: UITableViewCell {
}
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 {
if info.title?.isEmpty == false {
titleLabel.text = info.title
vStack.addSubview(titleLabel)
containerView.addSubview(titleLabel)
}
if info.text?.isEmpty ?? false {
if info.text?.isEmpty == false {
detailsLabel.text = info.text
vStack.addSubview(detailsLabel)
containerView.addSubview(detailsLabel)
}
prepareLabels() // this has to be here
vStack.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
if containerView.subviews.count == 1, let subview = containerView.subviews.first {
subview.snp.makeConstraints { (make) in
make.leading.equalToSuperview().inset(8)
make.trailing.equalToSuperview().inset(8)
make.top.equalToSuperview().inset(12)
make.bottom.equalToSuperview().inset(14)
}
}
else if containerView.subviews.count == 2 {
titleLabel.snp.makeConstraints { (make) in
make.leading.equalToSuperview().inset(8)
make.trailing.equalToSuperview().inset(8)
make.top.equalToSuperview().inset(12)
}
detailsLabel.snp.makeConstraints { (make) in
make.leading.equalToSuperview().inset(8)
make.trailing.equalToSuperview().inset(8)
make.top.equalTo(titleLabel.snp.bottom).offset(8)
make.bottom.equalToSuperview().inset(14)
}
}
self.layoutIfNeeded()
}
}
// MARK: - UI Setup
extension NWSAlertInfoBlockTableViewCell {
func prepareSelf() {
self.backgroundColor = UIColor(named: "notifications_nwsalert_background")
self.contentView.backgroundColor = UIColor(named: "notifications_nwsalert_background")
self.selectionStyle = .none
}
func prepareContainer() {
contentView.addSubview(containerView)
containerView.snp.makeConstraints { (make) in
make.top.equalToSuperview().inset(18)
make.left.equalToSuperview().inset(18)
make.right.equalToSuperview().inset(18)
make.bottom.equalToSuperview()
}
containerView.layer.cornerRadius = 8
containerView.backgroundColor = UIColor(named: "notifications_nwsalert_tile_background")
}
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")
titleLabel.translatesAutoresizingMaskIntoConstraints = false
detailsLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.setContentCompressionResistancePriority(.required, for: .vertical)
detailsLabel.setContentCompressionResistancePriority(.required, for: .vertical)
titleLabel.numberOfLines = 0
detailsLabel.numberOfLines = 0
titleLabel.lineBreakMode = .byWordWrapping
detailsLabel.lineBreakMode = .byWordWrapping
}
}
......@@ -11,14 +11,19 @@ import SnapKit
class NWSForecastOfficeTableViewCell: UITableViewCell {
var alert: NWSAlert?
private let containerView = UIView()
private let officeTitleLabel = UILabel()
private let sentLabel = UILabel()
private let expiresLabel = UILabel()
private let separatorView = UIView()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
prepareSubviews()
prepareSelf()
prepareContainer()
prepareLabels()
prepareSeparator()
}
@available(*, unavailable)
......@@ -27,10 +32,71 @@ class NWSForecastOfficeTableViewCell: UITableViewCell {
}
func configure(with alert: NWSAlert) {
officeTitleLabel.text = alert.extendedInfo?.issuer ?? "--"
}
var primaryTextColor: UIColor! {
// TODO: use ThemeManager here.
UIColor(named: "notifications_primary_text")
}
func prepareSubviews() {
private func prepareSelf() {
self.backgroundColor = UIColor(named: "notifications_nwsalert_background")
self.contentView.backgroundColor = UIColor(named: "notifications_nwsalert_background")
self.selectionStyle = .none
}
private func prepareLabels() {
let forecastOfficeLabel = UILabel()
forecastOfficeLabel.font = AppFont.SFPro.bold(size: 18)
forecastOfficeLabel.textColor = primaryTextColor
forecastOfficeLabel.text = "notifications.nwsAlert.forecastOffice".localized()
officeTitleLabel.font = AppFont.SFPro.regular(size: 14)
officeTitleLabel.textColor = primaryTextColor
officeTitleLabel.numberOfLines = 0
officeTitleLabel.lineBreakMode = .byWordWrapping
containerView.addSubview(forecastOfficeLabel)
containerView.addSubview(officeTitleLabel)
forecastOfficeLabel.snp.makeConstraints { (make) in
make.top.equalToSuperview().inset(12)
make.left.equalToSuperview().inset(8)
make.right.equalToSuperview().inset(8)
}
officeTitleLabel.snp.makeConstraints { (make) in
make.top.equalTo(forecastOfficeLabel.snp.bottom).offset(8)
make.left.equalToSuperview().inset(8)
make.right.equalToSuperview().inset(8)
}
}
private func prepareSeparator() {
separatorView.backgroundColor = UIColor(named: "notifications_nwsalert_separator")
separatorView.isUserInteractionEnabled = false
separatorView.isOpaque = true
separatorView.isHidden = true
containerView.addSubview(separatorView)
separatorView.snp.makeConstraints { (make) in
make.height.equalTo(0.5)
make.left.equalToSuperview().inset(8)
make.right.equalToSuperview().inset(8)
make.top.equalTo(officeTitleLabel.snp.bottom).offset(4)
make.bottom.equalToSuperview().inset(4) // temporary
}
}
private func prepareContainer() {
contentView.addSubview(containerView)
containerView.snp.makeConstraints { (make) in
make.top.equalToSuperview().inset(18)
make.left.equalToSuperview().inset(18)
make.right.equalToSuperview().inset(18)
make.bottom.equalToSuperview()
}
containerView.layer.cornerRadius = 8
containerView.backgroundColor = UIColor(named: "notifications_nwsalert_tile_background")
}
}
......@@ -51,8 +51,7 @@ class NWSAlertViewController: UIViewController {
//MARK: - UI Setup
extension NWSAlertViewController {
func prepareViewController() {
view.backgroundColor = ThemeManager.currentTheme.baseBackgroundColor
view.backgroundColor = UIColor(named: "notifications_nwsalert_background")
let closeButton = UIBarButtonItem(title: "general.close".localized().capitalized,
style: .done,
target: self,
......@@ -107,4 +106,8 @@ extension NWSAlertViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 160
}
}
......@@ -62,9 +62,12 @@ class NWSAlertCell: UITableViewCell {
return NWSAlertCell.issueDateFormatter // it's always used from the same thread, so it's OK.
}
public func configure(with alert: NWSAlert) {
public func configure(with alert: NWSAlert, overrideBackgroundColorName: String? = nil) {
self.alert = alert
let backgroundColorName = alert.read ? "notifications_background_read" : "notifications_background_unread"
var backgroundColorName = alert.read ? "notifications_background_read" : "notifications_background_unread"
if let overrideBackgroundColorName = overrideBackgroundColorName {
backgroundColorName = overrideBackgroundColorName
}
self.backgroundColor = UIColor(named: backgroundColorName)
self.contentView.backgroundColor = UIColor(named: backgroundColorName)
......@@ -78,11 +81,14 @@ class NWSAlertCell: UITableViewCell {
}
headerActiveExpiredLabel.isHidden = false
let expiryString = expiryDateFormatter(timeZone: alert.timeZone).string(from: alert.expires)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 10
let attributedText = NSMutableAttributedString(string: "\(alert.description) \("notifications.nwsCell.remainsInEffectUntil".localized()) \(expiryString)",
attributes: [
.font: AppFont.SFPro.regular(size: 14),
.foregroundColor: primaryTextColor as Any
.foregroundColor: primaryTextColor as Any,
.paragraphStyle: paragraphStyle
])
let nsText = attributedText.string as NSString
let boldRange = nsText.range(of: alert.description)
......@@ -154,7 +160,7 @@ private extension NWSAlertCell {
addSubview(alertTextLabel)
alertTextLabel.snp.makeConstraints { (make) in
make.left.equalToSuperview().offset(offsetToSuperview)
make.top.equalTo(alertIconImageView.snp.bottom).offset(4)
make.top.equalTo(alertIconImageView.snp.bottom).offset(8)
make.right.equalToSuperview().inset(offsetToSuperview)
}
}
......@@ -176,7 +182,7 @@ private extension NWSAlertCell {
}
alertLocationLabel.snp.makeConstraints { (make) in
make.top.equalTo(alertTextLabel.snp.bottom)
make.top.equalTo(alertTextLabel.snp.bottom).offset(8)
make.left.equalTo(locationIconImageView.snp.right).offset(6)
make.right.equalToSuperview().inset(offsetToSuperview)
make.bottom.equalToSuperview().inset(offsetToSuperview)
......
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