diff --git a/Classes/Issues/IssuesViewController.swift b/Classes/Issues/IssuesViewController.swift index 2a60c1c83..e163294a8 100644 --- a/Classes/Issues/IssuesViewController.swift +++ b/Classes/Issues/IssuesViewController.swift @@ -34,7 +34,9 @@ final class IssuesViewController: MessageViewController, IssueCommentSectionControllerDelegate, IssueTextActionsViewSendDelegate, EmptyViewDelegate, - MessageTextViewListener { + MessageTextViewListener, + IssueLabelTapSectionControllerDelegate +{ private let client: GithubClient private let model: IssueDetailsModel @@ -451,7 +453,7 @@ final class IssuesViewController: MessageViewController, switch object { // header and metadata case is IssueTitleModel: return IssueTitleSectionController() - case is IssueLabelsModel: return IssueLabelsSectionController(issue: model) + case is IssueLabelsModel: return IssueLabelsSectionController(issue: model, tapDelegate: self) case is IssueAssigneesModel: return IssueAssigneesSectionController() case is Milestone: return IssueMilestoneSectionController(issueModel: model) case is IssueFileChangesModel: return IssueViewFilesSectionController(issueModel: model, client: client) @@ -465,7 +467,7 @@ final class IssuesViewController: MessageViewController, autocomplete: autocompleteController.autocomplete.copy, issueCommentDelegate: self ) - case is IssueLabeledModel: return IssueLabeledSectionController(issueModel: model) + case is IssueLabeledModel: return IssueLabeledSectionController(issueModel: model, tapDelegate: self) case is IssueStatusEventModel: return IssueStatusEventSectionController(issueModel: model) case is IssueReferencedModel: return IssueReferencedSectionController(client: client) case is IssueReferencedCommitModel: return IssueReferencedCommitSectionController() @@ -631,5 +633,11 @@ final class IssuesViewController: MessageViewController, func didChangeSelection(textView: MessageTextView) {} func willChangeRange(textView: MessageTextView, to range: NSRange) {} + + // MARK: IssueLabelsSectionControllerDelegate + + func didTapIssueLabel(owner: String, repo: String, label: String) { + presentLabels(client: client, owner: owner, repo: repo, label: label) + } } diff --git a/Classes/Issues/Labeled/IssueLabeledSectionController.swift b/Classes/Issues/Labeled/IssueLabeledSectionController.swift index 23a160eba..f56fd5798 100644 --- a/Classes/Issues/Labeled/IssueLabeledSectionController.swift +++ b/Classes/Issues/Labeled/IssueLabeledSectionController.swift @@ -9,12 +9,16 @@ import Foundation import IGListKit -final class IssueLabeledSectionController: ListGenericSectionController { + + +final class IssueLabeledSectionController: ListGenericSectionController, MarkdownStyledTextViewDelegate { private let issueModel: IssueDetailsModel + private weak var tapDelegate: IssueLabelTapSectionControllerDelegate? - init(issueModel: IssueDetailsModel) { + init(issueModel: IssueDetailsModel, tapDelegate: IssueLabelTapSectionControllerDelegate) { self.issueModel = issueModel + self.tapDelegate = tapDelegate super.init() } @@ -28,8 +32,16 @@ final class IssueLabeledSectionController: ListGenericSectionController, ListBindingSectionControllerDataSource, ListBindingSectionControllerSelectionDelegate { @@ -16,9 +21,11 @@ ListBindingSectionControllerSelectionDelegate { private let issue: IssueDetailsModel private var sizeCache = [String: CGSize]() private let lockedModel = Constants.Strings.locked + private weak var tapDelegate: IssueLabelTapSectionControllerDelegate? - init(issue: IssueDetailsModel) { + init(issue: IssueDetailsModel, tapDelegate: IssueLabelTapSectionControllerDelegate) { self.issue = issue + self.tapDelegate = tapDelegate super.init() minimumInteritemSpacing = Styles.Sizes.labelSpacing minimumLineSpacing = Styles.Sizes.labelSpacing @@ -97,7 +104,7 @@ ListBindingSectionControllerSelectionDelegate { func sectionController(_ sectionController: ListBindingSectionController, didSelectItemAt index: Int, viewModel: Any) { guard let viewModel = viewModel as? RepositoryLabel else { return } - viewController?.presentLabels(owner: issue.owner, repo: issue.repo, label: viewModel.name) + tapDelegate?.didTapIssueLabel(owner: issue.owner, repo: issue.repo, label: viewModel.name) } } diff --git a/Classes/Repository/RepositoryIssuesViewController.swift b/Classes/Repository/RepositoryIssuesViewController.swift index bac4aa825..3a34fe552 100644 --- a/Classes/Repository/RepositoryIssuesViewController.swift +++ b/Classes/Repository/RepositoryIssuesViewController.swift @@ -19,17 +19,24 @@ BaseListViewControllerDataSource, SearchBarSectionControllerDelegate { private var models = [ListDiffable]() - private let repo: RepositoryDetails + private let owner: String + private let repo: String private let client: RepositoryClient private let type: RepositoryIssuesType private let searchKey: ListDiffable = "searchKey" as ListDiffable private let debouncer = Debouncer() private var previousSearchString = "is:open " + private var label: String? - init(client: GithubClient, repo: RepositoryDetails, type: RepositoryIssuesType) { + init(client: GithubClient, owner: String, repo: String, type: RepositoryIssuesType, label: String? = nil) { + self.owner = owner self.repo = repo - self.client = RepositoryClient(githubClient: client, owner: repo.owner, name: repo.name) + self.client = RepositoryClient(githubClient: client, owner: owner, name: repo) self.type = type + self.label = label + if let label = label { + previousSearchString += "label:\(label) " + } super.init( emptyErrorMessage: NSLocalizedString("Cannot load issues.", comment: "") @@ -51,10 +58,13 @@ SearchBarSectionControllerDelegate { super.viewDidLoad() makeBackBarItemEmpty() - - // set the frame in -viewDidLoad is required when working with TabMan - feed.collectionView.frame = view.bounds - feed.collectionView.contentInsetAdjustmentBehavior = .never + + let presentingInTabMan = label == nil + if presentingInTabMan { + // set the frame in -viewDidLoad is required when working with TabMan + feed.collectionView.frame = view.bounds + feed.collectionView.contentInsetAdjustmentBehavior = .never + } } // MARK: Overrides @@ -105,7 +115,7 @@ SearchBarSectionControllerDelegate { query: previousSearchString ) } - return RepositorySummarySectionController(client: client.githubClient, repo: repo) + return RepositorySummarySectionController(client: client.githubClient, owner: owner, repo: repo) } func emptySectionController(listAdapter: ListAdapter) -> ListSectionController { @@ -129,7 +139,7 @@ SearchBarSectionControllerDelegate { case .issues: typeQuery = "is:issue" case .pullRequests: typeQuery = "is:pr" } - return "repo:\(repo.owner)/\(repo.name) \(typeQuery) \(previousSearchString)" + return "repo:\(owner)/\(repo) \(typeQuery) \(previousSearchString)" } } diff --git a/Classes/Repository/RepositorySummarySectionController.swift b/Classes/Repository/RepositorySummarySectionController.swift index 831674d17..9cb87ad51 100644 --- a/Classes/Repository/RepositorySummarySectionController.swift +++ b/Classes/Repository/RepositorySummarySectionController.swift @@ -11,10 +11,12 @@ import IGListKit final class RepositorySummarySectionController: ListGenericSectionController { private let client: GithubClient - private let repo: RepositoryDetails + private let owner: String + private let repo: String - init(client: GithubClient, repo: RepositoryDetails) { + init(client: GithubClient, owner: String, repo: String) { self.client = client + self.owner = owner self.repo = repo super.init() } @@ -53,7 +55,7 @@ final class RepositorySummarySectionController: ListGenericSectionController