Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit fd2ed27

Browse files
BrianLitwinrnystrom
authored andcommitted
adds review GitHubAccess button to notifications view controller (#2176)
1 parent 966cb1a commit fd2ed27

File tree

5 files changed

+65
-7
lines changed

5 files changed

+65
-7
lines changed

Classes/Notifications/NoNewNotificationsCell.swift

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@
99
import UIKit
1010
import SnapKit
1111

12+
protocol ReviewGitHubAccessDelegate: class {
13+
func reviewGitHubAccessButtonTapped()
14+
}
15+
1216
final class NoNewNotificationsCell: UICollectionViewCell {
1317

1418
let emojiLabel = UILabel()
1519
let messageLabel = UILabel()
1620
let shadow = CAShapeLayer()
21+
let reviewGitHubAccessButton = UIButton()
22+
weak var reviewGitHubAccessDelegate: ReviewGitHubAccessDelegate?
1723

1824
override init(frame: CGRect) {
1925
super.init(frame: frame)
@@ -54,6 +60,27 @@ final class NoNewNotificationsCell: UICollectionViewCell {
5460

5561
contentView.isAccessibilityElement = true
5662
contentView.accessibilityLabel = NSLocalizedString("You have no new notifications!", comment: "Inbox Zero Accessibility Label")
63+
64+
65+
//configure reviewGitHubAcess button
66+
reviewGitHubAccessButton.setTitle(Constants.Strings.reviewGitHubAccess, for: .normal)
67+
reviewGitHubAccessButton.isAccessibilityElement = false
68+
reviewGitHubAccessButton.titleLabel?.textAlignment = .center
69+
reviewGitHubAccessButton.backgroundColor = .clear
70+
reviewGitHubAccessButton.titleLabel?.font = Styles.Text.finePrint.preferredFont
71+
reviewGitHubAccessButton.setTitleColor(Styles.Colors.Gray.light.color, for: .normal)
72+
reviewGitHubAccessButton.addTarget(self, action: #selector(reviewGitHubAccessButtonTapped),
73+
for: .touchUpInside)
74+
contentView.addSubview(reviewGitHubAccessButton)
75+
let buttonWidth = (reviewGitHubAccessButton.titleLabel?.intrinsicContentSize.width ?? 0) + Styles.Sizes.gutter
76+
let buttonHeight = (reviewGitHubAccessButton.titleLabel?.intrinsicContentSize.height ?? 0) + Styles.Sizes.gutter
77+
reviewGitHubAccessButton.snp.makeConstraints { make in
78+
make.centerX.equalTo(messageLabel)
79+
make.width.equalTo(buttonWidth)
80+
make.height.equalTo(buttonHeight)
81+
make.bottom.equalTo(contentView.snp.bottom).offset(-Styles.Sizes.tableSectionSpacing)
82+
}
83+
5784
}
5885

5986
required init?(coder aDecoder: NSCoder) {
@@ -89,9 +116,13 @@ final class NoNewNotificationsCell: UICollectionViewCell {
89116

90117
// MARK: Public API
91118

92-
func configure(emoji: String, message: String) {
119+
func configure(emoji: String,
120+
message: String,
121+
reviewGitHubAccessDelegate: ReviewGitHubAccessDelegate?)
122+
{
93123
emojiLabel.text = emoji
94124
messageLabel.text = message
125+
self.reviewGitHubAccessDelegate = reviewGitHubAccessDelegate
95126
}
96127

97128
// MARK: Private API
@@ -119,5 +150,9 @@ final class NoNewNotificationsCell: UICollectionViewCell {
119150

120151
shadow.add(shadowScale, forKey: "nonewnotificationscell.shadow")
121152
}
122-
153+
154+
@objc func reviewGitHubAccessButtonTapped() {
155+
reviewGitHubAccessDelegate?.reviewGitHubAccessButtonTapped()
156+
}
157+
123158
}

Classes/Notifications/NoNewNotificationsSectionController.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ final class NoNewNotificationSectionController: ListSwiftSectionController<Strin
1313

1414
private let layoutInsets: UIEdgeInsets
1515
private let loader = InboxZeroLoader()
16+
weak var reviewGitHubAccessDelegate: ReviewGitHubAccessDelegate?
1617

17-
init(layoutInsets: UIEdgeInsets) {
18+
init(layoutInsets: UIEdgeInsets, reviewGitHubAccessDelegate: ReviewGitHubAccessDelegate) {
1819
self.layoutInsets = layoutInsets
1920
super.init()
21+
self.reviewGitHubAccessDelegate = reviewGitHubAccessDelegate
2022
loader.load { [weak self] success in
2123
if success {
2224
self?.update()
@@ -36,10 +38,14 @@ final class NoNewNotificationSectionController: ListSwiftSectionController<Strin
3638
height: $0.collection.containerSize.height - layoutInsets.top - layoutInsets.bottom
3739
)
3840
},
39-
configure: {
41+
configure: { [weak self] in
42+
guard let strongSelf = self else { return }
4043
// TODO accessing the value seems to be required for this to compile
4144
print($1.value)
42-
$0.configure(emoji: latest.emoji, message: latest.message)
45+
$0.configure(emoji: latest.emoji,
46+
message: latest.message,
47+
reviewGitHubAccessDelegate: strongSelf.reviewGitHubAccessDelegate
48+
)
4349
})
4450
]
4551
}

Classes/Notifications/NotificationsViewController.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ BaseListViewController2DataSource,
1616
ForegroundHandlerDelegate,
1717
FlatCacheListener,
1818
TabNavRootViewControllerType,
19-
BaseListViewController2EmptyDataSource {
19+
BaseListViewController2EmptyDataSource,
20+
ReviewGitHubAccessDelegate
21+
{
2022

2123
private let modelController: NotificationModelController
2224
private let foreground = ForegroundHandler(threshold: 5 * 60)
@@ -278,7 +280,10 @@ BaseListViewController2EmptyDataSource {
278280
func emptyModel(for adapter: ListSwiftAdapter) -> ListSwiftPair {
279281
let layoutInsets = view.safeAreaInsets
280282
return ListSwiftPair.pair("empty-notification-value", {
281-
return NoNewNotificationSectionController(layoutInsets: layoutInsets)
283+
return NoNewNotificationSectionController(
284+
layoutInsets: layoutInsets,
285+
reviewGitHubAccessDelegate: self
286+
)
282287
})
283288
}
284289

@@ -304,4 +309,14 @@ BaseListViewController2EmptyDataSource {
304309
func didDoubleTapTab() {
305310
didSingleTapTab()
306311
}
312+
313+
// MARK: ReviewGitHubAccessDelegate
314+
func reviewGitHubAccessButtonTapped() {
315+
//copied/pasted from SettingsViewController... could consolidate
316+
guard let url = URL(string: "https://github.com/settings/connections/applications/\(Secrets.GitHub.clientId)")
317+
else { fatalError("Should always create GitHub issue URL") }
318+
// iOS 11 login uses SFAuthenticationSession which shares credentials with Safari.app
319+
UIApplication.shared.open(url)
320+
}
321+
307322
}

Classes/Views/Constants.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ enum Constants {
5353
static let milestone = NSLocalizedString("Milestone", comment: "")
5454
static let assignees = NSLocalizedString("Assignees", comment: "")
5555
static let reviewers = NSLocalizedString("Reviewers", comment: "")
56+
static let reviewGitHubAccess = NSLocalizedString("Review GitHub Access", comment: "")
5657
}
5758
}

Classes/Views/Styles.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ enum Styles {
6767
static let code = TextStyle(font: .name("Courier"), size: 16)
6868
static let codeBold = TextStyle(font: .name("Courier-Bold"), size: 16)
6969
static let secondaryCode = TextStyle(font: .name("Courier"), size: 13)
70+
static let finePrint = TextStyle(size: 12)
7071

7172
static let h1 = TextStyle(font: .system(.bold), size: 24)
7273
static let h2 = TextStyle(font: .system(.bold), size: 20)

0 commit comments

Comments
 (0)