From 978f099ea500f57424f297d7b8933bd5ca7e3ac7 Mon Sep 17 00:00:00 2001 From: Brian Litwin Date: Sat, 11 Aug 2018 12:11:00 -0400 Subject: [PATCH 1/4] add GithubAccess btn to noNewNotifications cell --- .../NoNewNotificationsCell.swift | 30 ++++++++++++++++++- .../NoNewNotificationsSectionController.swift | 12 ++++++-- .../NotificationsViewController.swift | 16 ++++++++-- Classes/Views/Styles.swift | 1 + 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/Classes/Notifications/NoNewNotificationsCell.swift b/Classes/Notifications/NoNewNotificationsCell.swift index 7ffa2f3bd..ca54de27c 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("Review GitHub access...", 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, options: [:]) + } } 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) From 4d44b50e315c68cb5e8464d6a35204edf667213d Mon Sep 17 00:00:00 2001 From: BrianLitwin Date: Sat, 11 Aug 2018 12:27:13 -0400 Subject: [PATCH 2/4] Update NoNewNotificationsCell.swift --- Classes/Notifications/NoNewNotificationsCell.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Notifications/NoNewNotificationsCell.swift b/Classes/Notifications/NoNewNotificationsCell.swift index ca54de27c..49832866f 100644 --- a/Classes/Notifications/NoNewNotificationsCell.swift +++ b/Classes/Notifications/NoNewNotificationsCell.swift @@ -48,7 +48,7 @@ final class NoNewNotificationsCell: UICollectionViewCell { make.top.equalTo(emojiLabel.snp.bottom).offset(Styles.Sizes.tableSectionSpacing) } - reviewGithubAccessButton.setTitle("Review GitHub access...", for: .normal) + reviewGithubAccessButton.setTitle("Review GitHub Access...", for: .normal) reviewGithubAccessButton.isAccessibilityElement = false reviewGithubAccessButton.titleLabel?.textAlignment = .center reviewGithubAccessButton.backgroundColor = .clear From a81b054b3c3d9eb75efc44f8d550bdb5d9865577 Mon Sep 17 00:00:00 2001 From: BrianLitwin Date: Sat, 11 Aug 2018 20:55:10 -0400 Subject: [PATCH 3/4] replaces raw string title with NSLocalizedString --- Classes/Notifications/NoNewNotificationsCell.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Notifications/NoNewNotificationsCell.swift b/Classes/Notifications/NoNewNotificationsCell.swift index 49832866f..194a121d9 100644 --- a/Classes/Notifications/NoNewNotificationsCell.swift +++ b/Classes/Notifications/NoNewNotificationsCell.swift @@ -48,7 +48,7 @@ final class NoNewNotificationsCell: UICollectionViewCell { make.top.equalTo(emojiLabel.snp.bottom).offset(Styles.Sizes.tableSectionSpacing) } - reviewGithubAccessButton.setTitle("Review GitHub Access...", for: .normal) + reviewGithubAccessButton.setTitle(NSLocalizedString("Review GitHub Access", comment: ""), for: .normal) reviewGithubAccessButton.isAccessibilityElement = false reviewGithubAccessButton.titleLabel?.textAlignment = .center reviewGithubAccessButton.backgroundColor = .clear From 3b554fd5e764a85a73e29077666d4f4f96f3382a Mon Sep 17 00:00:00 2001 From: BrianLitwin Date: Sat, 11 Aug 2018 20:56:50 -0400 Subject: [PATCH 4/4] removes empty [:] parameter --- Classes/Notifications/NotificationsViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Notifications/NotificationsViewController.swift b/Classes/Notifications/NotificationsViewController.swift index ef89b64a8..e2b2c05c0 100644 --- a/Classes/Notifications/NotificationsViewController.swift +++ b/Classes/Notifications/NotificationsViewController.swift @@ -314,6 +314,6 @@ ReviewGithubAccessDelegate 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, options: [:]) + UIApplication.shared.open(url) } }