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

add GithubAccess btn to noNewNotifications cell #2085

Closed
Closed
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
30 changes: 29 additions & 1 deletion 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 reviewGithubAccessButton = UIButton()
let shadow = CAShapeLayer()
weak var reviewGithubAccessDelegate: ReviewGithubAccessDelegate?

override init(frame: CGRect) {
super.init(frame: frame)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -119,5 +143,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 @@ -14,6 +14,7 @@ final class NoNewNotificationSectionController: ListSwiftSectionController<Strin

private let layoutInsets: UIEdgeInsets
private let client = NotificationEmptyMessageClient()
weak var reviewGithubAccessDelegate: ReviewGithubAccessDelegate?

enum State {
case loading
Expand All @@ -22,9 +23,10 @@ final class NoNewNotificationSectionController: ListSwiftSectionController<Strin
}
private var state: State = .loading

init(layoutInsets: UIEdgeInsets) {
init(layoutInsets: UIEdgeInsets, reviewGithubAccessDelegate: ReviewGithubAccessDelegate) {
self.layoutInsets = layoutInsets
super.init()
self.reviewGithubAccessDelegate = reviewGithubAccessDelegate
client.fetch { [weak self] (result) in
self?.handleFinished(result)
}
Expand Down Expand Up @@ -54,8 +56,12 @@ final class NoNewNotificationSectionController: ListSwiftSectionController<Strin
private func configure(_ cell: NoNewNotificationsCell) {
switch state {
case .loading: break
case .success(let message): cell.configure(emoji: message.emoji, message: message.text)
case .error: cell.configure(emoji: "🎉", message: NSLocalizedString("Inbox zero!", comment: ""))
case .success(let message): cell.configure(emoji: message.emoji,
message: message.text,
delegate: reviewGithubAccessDelegate)
case .error: cell.configure(emoji: "🎉",
message: NSLocalizedString("Inbox zero!", comment: ""),
delegate: reviewGithubAccessDelegate)
}
}

Expand Down
16 changes: 14 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,8 @@ 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 +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)
}
}
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