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

adds review GitHubAccess button to notifications view controller #2176

Merged
merged 1 commit into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions Classes/Notifications/NoNewNotificationsCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
import UIKit
import SnapKit

protocol ReviewGitHubAccessDelegate: class {
func reviewGitHubAccessButtonTapped()
}

final class NoNewNotificationsCell: UICollectionViewCell {

let emojiLabel = UILabel()
let messageLabel = UILabel()
let shadow = CAShapeLayer()
let reviewGitHubAccessButton = UIButton()
weak var reviewGitHubAccessDelegate: ReviewGitHubAccessDelegate?

override init(frame: CGRect) {
super.init(frame: frame)
Expand Down Expand Up @@ -54,6 +60,27 @@ final class NoNewNotificationsCell: UICollectionViewCell {

contentView.isAccessibilityElement = true
contentView.accessibilityLabel = NSLocalizedString("You have no new notifications!", comment: "Inbox Zero Accessibility Label")


//configure reviewGitHubAcess button
reviewGitHubAccessButton.setTitle(Constants.Strings.reviewGitHubAccess, 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)
}

}

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

// MARK: Public API

func configure(emoji: String, message: String) {
func configure(emoji: String,
message: String,
reviewGitHubAccessDelegate: ReviewGitHubAccessDelegate?)
{
emojiLabel.text = emoji
messageLabel.text = message
self.reviewGitHubAccessDelegate = reviewGitHubAccessDelegate
}

// MARK: Private API
Expand Down Expand Up @@ -119,5 +150,9 @@ final class NoNewNotificationsCell: UICollectionViewCell {

shadow.add(shadowScale, forKey: "nonewnotificationscell.shadow")
}


@objc func reviewGitHubAccessButtonTapped() {
reviewGitHubAccessDelegate?.reviewGitHubAccessButtonTapped()
}

}
12 changes: 9 additions & 3 deletions Classes/Notifications/NoNewNotificationsSectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ final class NoNewNotificationSectionController: ListSwiftSectionController<Strin

private let layoutInsets: UIEdgeInsets
private let loader = InboxZeroLoader()
weak var reviewGitHubAccessDelegate: ReviewGitHubAccessDelegate?

init(layoutInsets: UIEdgeInsets) {
init(layoutInsets: UIEdgeInsets, reviewGitHubAccessDelegate: ReviewGitHubAccessDelegate) {
self.layoutInsets = layoutInsets
super.init()
self.reviewGitHubAccessDelegate = reviewGitHubAccessDelegate
loader.load { [weak self] success in
if success {
self?.update()
Expand All @@ -36,10 +38,14 @@ final class NoNewNotificationSectionController: ListSwiftSectionController<Strin
height: $0.collection.containerSize.height - layoutInsets.top - layoutInsets.bottom
)
},
configure: {
configure: { [weak self] in
guard let strongSelf = self else { return }
// TODO accessing the value seems to be required for this to compile
print($1.value)
$0.configure(emoji: latest.emoji, message: latest.message)
$0.configure(emoji: latest.emoji,
message: latest.message,
reviewGitHubAccessDelegate: strongSelf.reviewGitHubAccessDelegate
)
})
]
}
Expand Down
19 changes: 17 additions & 2 deletions Classes/Notifications/NotificationsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ BaseListViewController2DataSource,
ForegroundHandlerDelegate,
FlatCacheListener,
TabNavRootViewControllerType,
BaseListViewController2EmptyDataSource {
BaseListViewController2EmptyDataSource,
ReviewGitHubAccessDelegate
{

private let modelController: NotificationModelController
private let foreground = ForegroundHandler(threshold: 5 * 60)
Expand Down Expand Up @@ -278,7 +280,10 @@ BaseListViewController2EmptyDataSource {
func emptyModel(for adapter: ListSwiftAdapter) -> ListSwiftPair {
let layoutInsets = view.safeAreaInsets
return ListSwiftPair.pair("empty-notification-value", {
return NoNewNotificationSectionController(layoutInsets: layoutInsets)
return NoNewNotificationSectionController(
layoutInsets: layoutInsets,
reviewGitHubAccessDelegate: self
)
})
}

Expand All @@ -304,4 +309,14 @@ 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)
}

}
1 change: 1 addition & 0 deletions Classes/Views/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ enum Constants {
static let milestone = NSLocalizedString("Milestone", comment: "")
static let assignees = NSLocalizedString("Assignees", comment: "")
static let reviewers = NSLocalizedString("Reviewers", comment: "")
static let reviewGitHubAccess = NSLocalizedString("Review GitHub Access", comment: "")
}
}
1 change: 1 addition & 0 deletions Classes/Views/Styles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down