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

Simpler logic for review access button handling #2249

Merged
merged 1 commit into from
Oct 9, 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
25 changes: 13 additions & 12 deletions Classes/Notifications/NoNewNotificationsCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
import UIKit
import SnapKit

protocol ReviewGitHubAccessDelegate: class {
func reviewGitHubAccessButtonTapped()
protocol NoNewNotificationsCellReviewAccessDelegate: class {
func didTapReviewAccess(cell: NoNewNotificationsCell)
}

final class NoNewNotificationsCell: UICollectionViewCell {

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

override init(frame: CGRect) {
super.init(frame: frame)
Expand Down Expand Up @@ -116,10 +116,11 @@ final class NoNewNotificationsCell: UICollectionViewCell {

// MARK: Public API

func configure(emoji: String,
message: String,
reviewGitHubAccessDelegate: ReviewGitHubAccessDelegate?)
{
func configure(
emoji: String,
message: String,
reviewGitHubAccessDelegate: NoNewNotificationsCellReviewAccessDelegate?
) {
emojiLabel.text = emoji
messageLabel.text = message
self.reviewGitHubAccessDelegate = reviewGitHubAccessDelegate
Expand Down Expand Up @@ -152,7 +153,7 @@ final class NoNewNotificationsCell: UICollectionViewCell {
}

@objc func reviewGitHubAccessButtonTapped() {
reviewGitHubAccessDelegate?.reviewGitHubAccessButtonTapped()
reviewGitHubAccessDelegate?.didTapReviewAccess(cell: self)
}

}
24 changes: 17 additions & 7 deletions Classes/Notifications/NoNewNotificationsSectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
import UIKit
import IGListKit

final class NoNewNotificationSectionController: ListSwiftSectionController<String> {
final class NoNewNotificationSectionController: ListSwiftSectionController<String>,
NoNewNotificationsCellReviewAccessDelegate {

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

init(layoutInsets: UIEdgeInsets, reviewGitHubAccessDelegate: ReviewGitHubAccessDelegate) {
init(layoutInsets: UIEdgeInsets) {
self.layoutInsets = layoutInsets
super.init()
self.reviewGitHubAccessDelegate = reviewGitHubAccessDelegate
loader.load { [weak self] success in
if success {
self?.update()
Expand All @@ -42,12 +41,23 @@ final class NoNewNotificationSectionController: ListSwiftSectionController<Strin
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,
reviewGitHubAccessDelegate: strongSelf.reviewGitHubAccessDelegate
$0.configure(
emoji: latest.emoji,
message: latest.message,
reviewGitHubAccessDelegate: strongSelf
)
})
]
}

// MARK: NoNewNotificationsCellReviewAccessDelegate

func didTapReviewAccess(cell: NoNewNotificationsCell) {
//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)
}

}
17 changes: 2 additions & 15 deletions Classes/Notifications/NotificationsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ BaseListViewController2DataSource,
ForegroundHandlerDelegate,
FlatCacheListener,
TabNavRootViewControllerType,
BaseListViewController2EmptyDataSource,
ReviewGitHubAccessDelegate
BaseListViewController2EmptyDataSource
{

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

Expand All @@ -310,13 +306,4 @@ ReviewGitHubAccessDelegate
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)
}

}