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

Commit 80d1255

Browse files
BrianLitwinrnystrom
authored andcommitted
Search for labels in app (take two) (#2314)
* Created DidTap Protocol for label section controllers - created a protocol to route tap events to a delegate. The idea is that the delgate will have a reference to GithubClient and we can limit the baggage of passing around GithubClient * Refactor Repo VC and SC to use name and owner as parameters - Will make it easier to present RepoVC without needing a ref to RepositoryDetails. The only parameters being used from RepositoryDetails were owner and name * Added presentLabels extension to UIViewController * requested changes
1 parent b8552a9 commit 80d1255

10 files changed

+94
-29
lines changed

Classes/Issues/IssuesViewController.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ final class IssuesViewController: MessageViewController,
3434
IssueCommentSectionControllerDelegate,
3535
IssueTextActionsViewSendDelegate,
3636
EmptyViewDelegate,
37-
MessageTextViewListener {
37+
MessageTextViewListener,
38+
IssueLabelTapSectionControllerDelegate
39+
{
3840

3941
private let client: GithubClient
4042
private let model: IssueDetailsModel
@@ -451,7 +453,7 @@ final class IssuesViewController: MessageViewController,
451453
switch object {
452454
// header and metadata
453455
case is IssueTitleModel: return IssueTitleSectionController()
454-
case is IssueLabelsModel: return IssueLabelsSectionController(issue: model)
456+
case is IssueLabelsModel: return IssueLabelsSectionController(issue: model, tapDelegate: self)
455457
case is IssueAssigneesModel: return IssueAssigneesSectionController()
456458
case is Milestone: return IssueMilestoneSectionController(issueModel: model)
457459
case is IssueFileChangesModel: return IssueViewFilesSectionController(issueModel: model, client: client)
@@ -465,7 +467,7 @@ final class IssuesViewController: MessageViewController,
465467
autocomplete: autocompleteController.autocomplete.copy,
466468
issueCommentDelegate: self
467469
)
468-
case is IssueLabeledModel: return IssueLabeledSectionController(issueModel: model)
470+
case is IssueLabeledModel: return IssueLabeledSectionController(issueModel: model, tapDelegate: self)
469471
case is IssueStatusEventModel: return IssueStatusEventSectionController(issueModel: model)
470472
case is IssueReferencedModel: return IssueReferencedSectionController(client: client)
471473
case is IssueReferencedCommitModel: return IssueReferencedCommitSectionController()
@@ -631,5 +633,11 @@ final class IssuesViewController: MessageViewController,
631633

632634
func didChangeSelection(textView: MessageTextView) {}
633635
func willChangeRange(textView: MessageTextView, to range: NSRange) {}
636+
637+
// MARK: IssueLabelsSectionControllerDelegate
638+
639+
func didTapIssueLabel(owner: String, repo: String, label: String) {
640+
presentLabels(client: client, owner: owner, repo: repo, label: label)
641+
}
634642

635643
}

Classes/Issues/Labeled/IssueLabeledSectionController.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
import Foundation
1010
import IGListKit
1111

12-
final class IssueLabeledSectionController: ListGenericSectionController<IssueLabeledModel> {
12+
13+
14+
final class IssueLabeledSectionController: ListGenericSectionController<IssueLabeledModel>, MarkdownStyledTextViewDelegate {
1315

1416
private let issueModel: IssueDetailsModel
17+
private weak var tapDelegate: IssueLabelTapSectionControllerDelegate?
1518

16-
init(issueModel: IssueDetailsModel) {
19+
init(issueModel: IssueDetailsModel, tapDelegate: IssueLabelTapSectionControllerDelegate) {
1720
self.issueModel = issueModel
21+
self.tapDelegate = tapDelegate
1822
super.init()
1923
}
2024

@@ -28,8 +32,16 @@ final class IssueLabeledSectionController: ListGenericSectionController<IssueLab
2832
let object = self.object
2933
else { fatalError("Missing collection context, cell incorrect type, or object missing") }
3034
cell.configure(object)
31-
cell.delegate = viewController
35+
cell.delegate = self
3236
return cell
3337
}
34-
38+
39+
func didTap(cell: MarkdownStyledTextView, attribute: DetectedMarkdownAttribute) {
40+
if case .label(let label) = attribute {
41+
tapDelegate?.didTapIssueLabel(owner: label.owner, repo: label.repo, label: label.label)
42+
} else {
43+
viewController?.handle(attribute: attribute)
44+
}
45+
}
46+
3547
}

Classes/Issues/Labels/IssueLabelsSectionController.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,23 @@
99
import UIKit
1010
import IGListKit
1111

12+
13+
protocol IssueLabelTapSectionControllerDelegate: class {
14+
func didTapIssueLabel(owner: String, repo: String, label: String)
15+
}
16+
1217
final class IssueLabelsSectionController: ListBindingSectionController<IssueLabelsModel>,
1318
ListBindingSectionControllerDataSource,
1419
ListBindingSectionControllerSelectionDelegate {
1520

1621
private let issue: IssueDetailsModel
1722
private var sizeCache = [String: CGSize]()
1823
private let lockedModel = Constants.Strings.locked
24+
private weak var tapDelegate: IssueLabelTapSectionControllerDelegate?
1925

20-
init(issue: IssueDetailsModel) {
26+
init(issue: IssueDetailsModel, tapDelegate: IssueLabelTapSectionControllerDelegate) {
2127
self.issue = issue
28+
self.tapDelegate = tapDelegate
2229
super.init()
2330
minimumInteritemSpacing = Styles.Sizes.labelSpacing
2431
minimumLineSpacing = Styles.Sizes.labelSpacing
@@ -97,7 +104,7 @@ ListBindingSectionControllerSelectionDelegate {
97104

98105
func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>, didSelectItemAt index: Int, viewModel: Any) {
99106
guard let viewModel = viewModel as? RepositoryLabel else { return }
100-
viewController?.presentLabels(owner: issue.owner, repo: issue.repo, label: viewModel.name)
107+
tapDelegate?.didTapIssueLabel(owner: issue.owner, repo: issue.repo, label: viewModel.name)
101108
}
102109

103110
}

Classes/Repository/RepositoryIssuesViewController.swift

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,24 @@ BaseListViewControllerDataSource,
1919
SearchBarSectionControllerDelegate {
2020

2121
private var models = [ListDiffable]()
22-
private let repo: RepositoryDetails
22+
private let owner: String
23+
private let repo: String
2324
private let client: RepositoryClient
2425
private let type: RepositoryIssuesType
2526
private let searchKey: ListDiffable = "searchKey" as ListDiffable
2627
private let debouncer = Debouncer()
2728
private var previousSearchString = "is:open "
29+
private var label: String?
2830

29-
init(client: GithubClient, repo: RepositoryDetails, type: RepositoryIssuesType) {
31+
init(client: GithubClient, owner: String, repo: String, type: RepositoryIssuesType, label: String? = nil) {
32+
self.owner = owner
3033
self.repo = repo
31-
self.client = RepositoryClient(githubClient: client, owner: repo.owner, name: repo.name)
34+
self.client = RepositoryClient(githubClient: client, owner: owner, name: repo)
3235
self.type = type
36+
self.label = label
37+
if let label = label {
38+
previousSearchString += "label:\(label) "
39+
}
3340

3441
super.init(
3542
emptyErrorMessage: NSLocalizedString("Cannot load issues.", comment: "")
@@ -51,10 +58,13 @@ SearchBarSectionControllerDelegate {
5158
super.viewDidLoad()
5259

5360
makeBackBarItemEmpty()
54-
55-
// set the frame in -viewDidLoad is required when working with TabMan
56-
feed.collectionView.frame = view.bounds
57-
feed.collectionView.contentInsetAdjustmentBehavior = .never
61+
62+
let presentingInTabMan = label == nil
63+
if presentingInTabMan {
64+
// set the frame in -viewDidLoad is required when working with TabMan
65+
feed.collectionView.frame = view.bounds
66+
feed.collectionView.contentInsetAdjustmentBehavior = .never
67+
}
5868
}
5969

6070
// MARK: Overrides
@@ -105,7 +115,7 @@ SearchBarSectionControllerDelegate {
105115
query: previousSearchString
106116
)
107117
}
108-
return RepositorySummarySectionController(client: client.githubClient, repo: repo)
118+
return RepositorySummarySectionController(client: client.githubClient, owner: owner, repo: repo)
109119
}
110120

111121
func emptySectionController(listAdapter: ListAdapter) -> ListSectionController {
@@ -129,7 +139,7 @@ SearchBarSectionControllerDelegate {
129139
case .issues: typeQuery = "is:issue"
130140
case .pullRequests: typeQuery = "is:pr"
131141
}
132-
return "repo:\(repo.owner)/\(repo.name) \(typeQuery) \(previousSearchString)"
142+
return "repo:\(owner)/\(repo) \(typeQuery) \(previousSearchString)"
133143
}
134144

135145
}

Classes/Repository/RepositorySummarySectionController.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import IGListKit
1111
final class RepositorySummarySectionController: ListGenericSectionController<RepositoryIssueSummaryModel> {
1212

1313
private let client: GithubClient
14-
private let repo: RepositoryDetails
14+
private let owner: String
15+
private let repo: String
1516

16-
init(client: GithubClient, repo: RepositoryDetails) {
17+
init(client: GithubClient, owner: String, repo: String) {
1718
self.client = client
19+
self.owner = owner
1820
self.repo = repo
1921
super.init()
2022
}
@@ -53,7 +55,7 @@ final class RepositorySummarySectionController: ListGenericSectionController<Rep
5355

5456
override func didSelectItem(at index: Int) {
5557
guard let number = self.object?.number else { return }
56-
let issueModel = IssueDetailsModel(owner: repo.owner, repo: repo.name, number: number)
58+
let issueModel = IssueDetailsModel(owner: owner, repo: repo, number: number)
5759
let controller = IssuesViewController(client: client, model: issueModel)
5860
viewController?.view.endEditing(false) // resign keyboard if it was triggered to become active by SearchBar
5961
viewController?.navigationController?.pushViewController(controller, animated: trueUnlessReduceMotionEnabled)

Classes/Repository/RepositoryViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ ContextMenuDelegate {
4747

4848
var controllers: [UIViewController] = [RepositoryOverviewViewController(client: client, repo: repo)]
4949
if repo.hasIssuesEnabled {
50-
controllers.append(RepositoryIssuesViewController(client: client, repo: repo, type: .issues))
50+
controllers.append(RepositoryIssuesViewController(client: client, owner: repo.owner, repo: repo.name, type: .issues))
5151
}
5252
controllers += [
53-
RepositoryIssuesViewController(client: client, repo: repo, type: .pullRequests),
53+
RepositoryIssuesViewController(client: client, owner: repo.owner, repo: repo.name, type: .pullRequests),
5454
RepositoryCodeDirectoryViewController.createRoot(client: client, repo: repo, branch: repo.defaultBranch)
5555
]
5656
self.controllers = controllers

Classes/Utility/UIViewController+Routing.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ extension UIViewController {
1919
UIApplication.shared.open(url, options: [:], completionHandler: nil)
2020
}
2121
case .username(let username): presentProfile(login: username)
22-
case .label(let label): presentLabels(owner: label.owner, repo: label.repo, label: label.label)
2322
case .commit(let commit): presentCommit(owner: commit.owner, repo: commit.repo, hash: commit.hash)
2423
default: return false
2524
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// UIViewController+PresentLabels.swift
3+
// Freetime
4+
//
5+
// Created by B_Litwin on 10/19/18.
6+
// Copyright © 2018 Ryan Nystrom. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import GitHubAPI
11+
12+
extension UIViewController {
13+
func presentLabels(client: GithubClient, owner: String, repo: String, label: String) {
14+
let repositoryIssuesViewController =
15+
RepositoryIssuesViewController(
16+
client: client,
17+
owner: owner,
18+
repo: repo,
19+
type: .issues,
20+
label: label
21+
)
22+
23+
navigationController?.pushViewController(
24+
repositoryIssuesViewController,
25+
animated: true
26+
)
27+
}
28+
}

Classes/View Controllers/UIViewController+Safari.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ extension UIViewController {
3030
presentSafari(url: url)
3131
}
3232

33-
func presentLabels(owner: String, repo: String, label: String) {
34-
guard let url = URL(string: "https://github.com/\(owner)/\(repo)/labels/\(label)") else { return }
35-
presentSafari(url: url)
36-
}
37-
3833
func presentMilestone(owner: String, repo: String, milestone: Int) {
3934
guard let url = URL(string: "https://github.com/\(owner)/\(repo)/milestone/\(milestone)") else { return }
4035
presentSafari(url: url)

Freetime.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@
449449
98F9F4011F9CCFFE005A0266 /* ImgurClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98F9F3FE1F9CCFFE005A0266 /* ImgurClient.swift */; };
450450
98F9F4031F9CD006005A0266 /* Image+Base64.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98F9F4021F9CD006005A0266 /* Image+Base64.swift */; };
451451
BD3761B0209E032500401DFB /* BookmarkNavigationItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD3761AF209E032500401DFB /* BookmarkNavigationItemTests.swift */; };
452+
BD67495C217A47BC00E8E4FD /* UIViewController+PresentLabels.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD67495B217A47BC00E8E4FD /* UIViewController+PresentLabels.swift */; };
452453
BD89007E20B8844B0026013F /* NetworkingURLPathTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD89007D20B8844B0026013F /* NetworkingURLPathTests.swift */; };
453454
BDB6AA66215FBC35009BB73C /* RepositoryBranchesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDB6AA5F215FBC35009BB73C /* RepositoryBranchesViewModel.swift */; };
454455
BDB6AA67215FBC35009BB73C /* RepositoryBranchUpdatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDB6AA60215FBC35009BB73C /* RepositoryBranchUpdatable.swift */; };
@@ -999,6 +1000,7 @@
9991000
ACAE4A11E9671879046F0CE7 /* Pods-FreetimeWatch.testflight.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FreetimeWatch.testflight.xcconfig"; path = "Pods/Target Support Files/Pods-FreetimeWatch/Pods-FreetimeWatch.testflight.xcconfig"; sourceTree = "<group>"; };
10001001
B3C439BE890EECD7C0C692C5 /* Pods-Freetime.testflight.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Freetime.testflight.xcconfig"; path = "Pods/Target Support Files/Pods-Freetime/Pods-Freetime.testflight.xcconfig"; sourceTree = "<group>"; };
10011002
BD3761AF209E032500401DFB /* BookmarkNavigationItemTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkNavigationItemTests.swift; sourceTree = "<group>"; };
1003+
BD67495B217A47BC00E8E4FD /* UIViewController+PresentLabels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+PresentLabels.swift"; sourceTree = "<group>"; };
10021004
BD89007D20B8844B0026013F /* NetworkingURLPathTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkingURLPathTests.swift; sourceTree = "<group>"; };
10031005
BDB6AA5F215FBC35009BB73C /* RepositoryBranchesViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepositoryBranchesViewModel.swift; sourceTree = "<group>"; };
10041006
BDB6AA60215FBC35009BB73C /* RepositoryBranchUpdatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepositoryBranchUpdatable.swift; sourceTree = "<group>"; };
@@ -1743,6 +1745,7 @@
17431745
290056F2210028B20046EAE5 /* UIViewController+MenuDone.swift */,
17441746
29792B181FFB10A3007A0C57 /* UIViewController+MessageAutocompleteControllerLayoutDelegate.swift */,
17451747
292CD3D11F0DBEC000D3D57B /* UIViewController+Safari.swift */,
1748+
BD67495B217A47BC00E8E4FD /* UIViewController+PresentLabels.swift */,
17461749
290D2A3C1F044CB20082E6CC /* UIViewController+SmartDeselection.swift */,
17471750
299F63E3205E1CAB0015D901 /* UIViewController+StyledTextViewCellDelegate.swift */,
17481751
4920F1A71F72E27200131E9D /* UIViewController+UserActivity.swift */,
@@ -2762,6 +2765,7 @@
27622765
29459A6F1FE61E0500034A04 /* MarkdownCheckboxModel.swift in Sources */,
27632766
299997302031227E00995FFD /* IssueMergeButtonModel.swift in Sources */,
27642767
29CEA5CD1F84DB1B009827DB /* BaseListViewController.swift in Sources */,
2768+
BD67495C217A47BC00E8E4FD /* UIViewController+PresentLabels.swift in Sources */,
27652769
299F63E0205DDF6B0015D901 /* UIViewController+Routing.swift in Sources */,
27662770
98835BD41F1A17EE005BA24F /* Bundle+Version.swift in Sources */,
27672771
29316DB51ECC7DEB007CAE3F /* ButtonCell.swift in Sources */,

0 commit comments

Comments
 (0)