diff --git a/Classes/Notifications/NoNewNotificationsCell.swift b/Classes/Notifications/NoNewNotificationsCell.swift index 7ffa2f3bd..194a121d9 100644 --- a/Classes/Notifications/NoNewNotificationsCell.swift +++ b/Classes/Notifications/NoNewNotificationsCell.swift @@ -9,11 +9,17 @@ import UIKit import SnapKit +protocol ReviewGithubAccessDelegate: class { + func reviewGithubAccessButtonTapped() +} + final class NoNewNotificationsCell: UICollectionViewCell { let emojiLabel = UILabel() let messageLabel = UILabel() + let reviewGithubAccessButton = UIButton() let shadow = CAShapeLayer() + weak var reviewGithubAccessDelegate: ReviewGithubAccessDelegate? override init(frame: CGRect) { super.init(frame: frame) @@ -42,6 +48,23 @@ final class NoNewNotificationsCell: UICollectionViewCell { make.top.equalTo(emojiLabel.snp.bottom).offset(Styles.Sizes.tableSectionSpacing) } + reviewGithubAccessButton.setTitle(NSLocalizedString("Review GitHub Access", comment: ""), for: .normal) + reviewGithubAccessButton.isAccessibilityElement = false + reviewGithubAccessButton.titleLabel?.textAlignment = .center + reviewGithubAccessButton.backgroundColor = .clear + reviewGithubAccessButton.titleLabel?.font = Styles.Text.finePrint.preferredFont + reviewGithubAccessButton.setTitleColor(Styles.Colors.Gray.light.color, for: .normal) + reviewGithubAccessButton.addTarget(self, action: #selector(reviewGithubAccessButtonTapped), for: .touchUpInside) + contentView.addSubview(reviewGithubAccessButton) + let buttonWidth = (reviewGithubAccessButton.titleLabel?.intrinsicContentSize.width ?? 0) + Styles.Sizes.gutter + let buttonHeight = (reviewGithubAccessButton.titleLabel?.intrinsicContentSize.height ?? 0) + Styles.Sizes.gutter + reviewGithubAccessButton.snp.makeConstraints { make in + make.centerX.equalTo(messageLabel) + make.width.equalTo(buttonWidth) + make.height.equalTo(buttonHeight) + make.bottom.equalTo(contentView.snp.bottom).offset(-Styles.Sizes.tableSectionSpacing) + } + resetAnimations() // CAAnimations will be removed from layers on background. restore when foregrounding. @@ -89,9 +112,10 @@ final class NoNewNotificationsCell: UICollectionViewCell { // MARK: Public API - func configure(emoji: String, message: String) { + func configure(emoji: String, message: String, delegate: ReviewGithubAccessDelegate?) { emojiLabel.text = emoji messageLabel.text = message + reviewGithubAccessDelegate = delegate } // MARK: Private API @@ -119,5 +143,9 @@ final class NoNewNotificationsCell: UICollectionViewCell { shadow.add(shadowScale, forKey: "nonewnotificationscell.shadow") } + + @objc func reviewGithubAccessButtonTapped() { + reviewGithubAccessDelegate?.reviewGithubAccessButtonTapped() + } } diff --git a/Classes/Notifications/NoNewNotificationsSectionController.swift b/Classes/Notifications/NoNewNotificationsSectionController.swift index ed274b171..6c5dc3243 100644 --- a/Classes/Notifications/NoNewNotificationsSectionController.swift +++ b/Classes/Notifications/NoNewNotificationsSectionController.swift @@ -14,6 +14,7 @@ final class NoNewNotificationSectionController: ListSwiftSectionController ListSwiftPair { let layoutInsets = view.safeAreaInsets return ListSwiftPair.pair("empty-notification-value", { - return NoNewNotificationSectionController(layoutInsets: layoutInsets) + return NoNewNotificationSectionController(layoutInsets: layoutInsets, + reviewGithubAccessDelegate: self) }) } @@ -304,4 +307,13 @@ BaseListViewController2EmptyDataSource { func didDoubleTapTab() { didSingleTapTab() } + + // MARK: ReviewGithubAccessDelegate + func reviewGithubAccessButtonTapped() { + //copied/pasted from SettingsViewController .. could consolidate + guard let url = URL(string: "https://github.com/settings/connections/applications/\(Secrets.GitHub.clientId)") + else { fatalError("Should always create GitHub issue URL") } + // iOS 11 login uses SFAuthenticationSession which shares credentials with Safari.app + UIApplication.shared.open(url) + } } diff --git a/Classes/Views/Styles.swift b/Classes/Views/Styles.swift index a24a872b3..ee7f81ab0 100644 --- a/Classes/Views/Styles.swift +++ b/Classes/Views/Styles.swift @@ -67,6 +67,7 @@ enum Styles { static let code = TextStyle(font: .name("Courier"), size: 16) static let codeBold = TextStyle(font: .name("Courier-Bold"), size: 16) static let secondaryCode = TextStyle(font: .name("Courier"), size: 13) + static let finePrint = TextStyle(size: 12) static let h1 = TextStyle(font: .system(.bold), size: 24) static let h2 = TextStyle(font: .system(.bold), size: 20)