diff --git a/CTNotificationContent/CTNotificationViewController.m b/CTNotificationContent/CTNotificationViewController.m index b067399..6c3c7a9 100644 --- a/CTNotificationContent/CTNotificationViewController.m +++ b/CTNotificationContent/CTNotificationViewController.m @@ -127,6 +127,7 @@ - (void)didReceiveNotification:(UNNotification *)notification { break; case CTNotificationContentTypeTimerTemplate: { CTTimerTemplateController *contentController = [[CTTimerTemplateController alloc] init]; + [contentController setNotificationDeliveryDate:notification.date]; [self setupContentController:contentController]; } break; diff --git a/CTNotificationContent/Templates/Rating/Controller/CTRatingsViewController.swift b/CTNotificationContent/Templates/Rating/Controller/CTRatingsViewController.swift index a37329b..df4bedf 100644 --- a/CTNotificationContent/Templates/Rating/Controller/CTRatingsViewController.swift +++ b/CTNotificationContent/Templates/Rating/Controller/CTRatingsViewController.swift @@ -431,14 +431,13 @@ import SDWebImage func setupConstraints() { NSLayoutConstraint.activate([ - titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8), - titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: Constraints.kCaptionLeftPadding), + titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 16), + titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16), titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -Constraints.kCaptionLeftPadding), titleLabel.heightAnchor.constraint(equalToConstant: Constraints.kCaptionHeight), - titleLabel.bottomAnchor.constraint(equalTo: subTitleLabel.topAnchor, constant: -8), - + subTitleLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 8), - subTitleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: Constraints.kCaptionLeftPadding), + subTitleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16), subTitleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -Constraints.kCaptionLeftPadding), subTitleLabel.heightAnchor.constraint(equalToConstant: Constraints.kSubCaptionHeight)]) } diff --git a/CTNotificationContent/Templates/Timer/Controller/CTTimerTemplateController.swift b/CTNotificationContent/Templates/Timer/Controller/CTTimerTemplateController.swift index ddc23c6..05455dc 100644 --- a/CTNotificationContent/Templates/Timer/Controller/CTTimerTemplateController.swift +++ b/CTNotificationContent/Templates/Timer/Controller/CTTimerTemplateController.swift @@ -8,7 +8,8 @@ import SDWebImage @objc public var templateCaption: String = "" @objc public var templateSubcaption: String = "" @objc public var deeplinkURL: String = "" - + @objc public var notificationDeliveryDate: Date? + var bgColor: String = ConstantKeys.kDefaultColor var captionColor: String = ConstantKeys.kHexBlackColor var subcaptionColor: String = ConstantKeys.kHexLightGrayColor @@ -104,13 +105,15 @@ import SDWebImage return } if let threshold = jsonContent.pt_timer_threshold { - thresholdSeconds = threshold - } else { - if let endTime = jsonContent.pt_timer_end { - let date = NSDate() - let currentTime = date.timeIntervalSince1970 - thresholdSeconds = endTime - Int(currentTime) + if let deliveredAt = notificationDeliveryDate { + let elapsed = Int(Date().timeIntervalSince(deliveredAt)) + thresholdSeconds = max(0, threshold - elapsed) + } else { + thresholdSeconds = threshold } + } else if let endTime = jsonContent.pt_timer_end { + let currentTime = Date().timeIntervalSince1970 + thresholdSeconds = endTime - Int(currentTime) } if let title = jsonContent.pt_title, !title.isEmpty { @@ -210,15 +213,19 @@ import SDWebImage } func setupConstraints() { + let timerLabelWidth: CGFloat = thresholdSeconds >= 3600 + ? Constraints.kTimerLabelWidthWithHours + : Constraints.kTimerLabelWidth + NSLayoutConstraint.activate([ captionLabel.topAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -(CTUtiltiy.getCaptionHeight() - Constraints.kCaptionTopPadding)), captionLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: Constraints.kCaptionLeftPadding), - captionLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -Constraints.kTimerLabelWidth), + captionLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -timerLabelWidth), captionLabel.heightAnchor.constraint(equalToConstant: Constraints.kCaptionHeight), - + subcaptionLabel.topAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -(Constraints.kSubCaptionHeight + Constraints.kSubCaptionTopPadding)), subcaptionLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: Constraints.kCaptionLeftPadding), - subcaptionLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -Constraints.kTimerLabelWidth), + subcaptionLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -timerLabelWidth), subcaptionLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -Constraints.kSubCaptionTopPadding), subcaptionLabel.heightAnchor.constraint(equalToConstant: Constraints.kSubCaptionHeight), diff --git a/CTNotificationContent/Templates/Utility/GlobalConstants.swift b/CTNotificationContent/Templates/Utility/GlobalConstants.swift index a66e420..3c45147 100644 --- a/CTNotificationContent/Templates/Utility/GlobalConstants.swift +++ b/CTNotificationContent/Templates/Utility/GlobalConstants.swift @@ -9,12 +9,13 @@ enum Constraints { static let kSubCaptionHeight: CGFloat = 20.0 static let kSubCaptionTopPadding: CGFloat = 8.0 static let kBottomPadding: CGFloat = 18.0 - static let kCaptionLeftPadding: CGFloat = 10.0 + static let kCaptionLeftPadding: CGFloat = 16.0 static let kCaptionTopPadding: CGFloat = 8.0 static let kImageBorderWidth: CGFloat = 1.0 static let kImageLayerBorderWidth: CGFloat = 0.4 static let kPageControlViewHeight: CGFloat = 20.0 static let kTimerLabelWidth: CGFloat = 100.0 + static let kTimerLabelWidthWithHours: CGFloat = 130.0 static let kLandscapeMultiplier: CGFloat = 0.5625 // 16:9 in landscape static let kPortraitMultiplier: CGFloat = 1.777 // 16:9 in portrait } diff --git a/CTNotificationContent/Templates/ZeroBezel/Controller/CTZeroBezelController.swift b/CTNotificationContent/Templates/ZeroBezel/Controller/CTZeroBezelController.swift index 79fbb2c..51d548c 100644 --- a/CTNotificationContent/Templates/ZeroBezel/Controller/CTZeroBezelController.swift +++ b/CTNotificationContent/Templates/ZeroBezel/Controller/CTZeroBezelController.swift @@ -16,8 +16,8 @@ import SDWebImage @objc public var templateSubcaption: String = "" @objc public var deeplinkURL: String = "" - var captionColor: String = ConstantKeys.kHexBlackColor - var subcaptionColor: String = ConstantKeys.kHexLightGrayColor + var captionColor: String = ConstantKeys.kHexWhiteColor + var subcaptionColor: String = ConstantKeys.kHexWhiteColor // Dark mode colors var captionColorDark: String = ConstantKeys.kHexWhiteColor @@ -54,6 +54,19 @@ import SDWebImage bigImageView.translatesAutoresizingMaskIntoConstraints = false return bigImageView }() + private let scrimView: UIView = { + let v = UIView() + v.translatesAutoresizingMaskIntoConstraints = false + v.isUserInteractionEnabled = false + return v + }() + private let scrimLayer: CAGradientLayer = { + let g = CAGradientLayer() + g.colors = [UIColor.clear.cgColor, UIColor.black.withAlphaComponent(0.65).cgColor] + g.startPoint = CGPoint(x: 0.5, y: 0) + g.endPoint = CGPoint(x: 0.5, y: 1) + return g + }() @objc public override func viewDidLoad() { super.viewDidLoad() @@ -100,6 +113,8 @@ import SDWebImage func createView() { createFrameWithoutImage() contentView.addSubview(bigImageView) + contentView.addSubview(scrimView) + scrimView.layer.addSublayer(scrimLayer) contentView.addSubview(subTitleLabel) contentView.addSubview(titleLabel) @@ -161,8 +176,18 @@ import SDWebImage } + public override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + scrimLayer.frame = scrimView.bounds + } + func setupConstraints() { NSLayoutConstraint.activate([ + scrimView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + scrimView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + scrimView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), + scrimView.heightAnchor.constraint(equalTo: contentView.heightAnchor, multiplier: 0.3), + titleLabel.topAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -(CTUtiltiy.getCaptionHeight() - Constraints.kCaptionTopPadding)), titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: Constraints.kCaptionLeftPadding), titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -Constraints.kCaptionLeftPadding),