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

Commit 2cc5291

Browse files
viktoraslBasThomas
authored andcommitted
Add handoff support for code blob views (#2622)
* Add handoff support for code blob views * Github URL building w/ tests coverage
1 parent d66b0b9 commit 2cc5291

File tree

4 files changed

+66
-7
lines changed

4 files changed

+66
-7
lines changed

Classes/Repository/RepositoryCodeBlobViewController.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ final class RepositoryCodeBlobViewController: UIViewController, EmptyViewDelegat
2121
private let emptyView = EmptyView()
2222
private var sharingPayload: Any?
2323
private var repoUrl: URL? {
24-
let builder = URLBuilder.github()
25-
.add(path: repo.owner)
26-
.add(path: repo.name)
27-
.add(path: "blob")
28-
.add(path: branch)
29-
path.components.forEach { builder.add(path: $0) }
30-
return builder.url
24+
return GithubURL.codeBlob(repo: repo, branch: branch, path: path)
3125
}
3226

3327
private lazy var moreOptionsItem: UIBarButtonItem = {
@@ -79,6 +73,22 @@ final class RepositoryCodeBlobViewController: UIViewController, EmptyViewDelegat
7973
feedRefresh.beginRefreshing()
8074
}
8175

76+
override func viewDidAppear(_ animated: Bool) {
77+
super.viewDidAppear(animated)
78+
if let url = repoUrl {
79+
setupUserActivity(with: HandoffInformator(
80+
activityName: "viewCodeBlob",
81+
activityTitle: "\(repo.owner)/\(repo.name)/\(branch)/" + path.components.joined(separator: "/"),
82+
url: url
83+
))
84+
}
85+
}
86+
87+
override func viewDidDisappear(_ animated: Bool) {
88+
super.viewDidDisappear(animated)
89+
invalidateUserActivity()
90+
}
91+
8292
override func viewWillLayoutSubviews() {
8393
super.viewWillLayoutSubviews()
8494
let frame: CGRect

Classes/Utility/GithubURL.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// GithubURL.swift
3+
// Freetime
4+
//
5+
// Created by Viktoras Laukevicius on 20/02/2019.
6+
// Copyright © 2019 Ryan Nystrom. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
enum GithubURL {
12+
static func codeBlob(repo: RepositoryDetails, branch: String, path: FilePath) -> URL? {
13+
let builder = URLBuilder.github()
14+
.add(path: repo.owner)
15+
.add(path: repo.name)
16+
.add(path: "blob")
17+
.add(path: branch)
18+
path.components.forEach { builder.add(path: $0) }
19+
return builder.url
20+
}
21+
}

Freetime.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
03E8D824221D339200EB792A /* GithubURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E8D823221D339200EB792A /* GithubURL.swift */; };
11+
03E8D826221D358000EB792A /* GithubURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E8D825221D358000EB792A /* GithubURLTests.swift */; };
1012
03C127B8220993300062F7C9 /* InboxZeroLoaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C127B7220993300062F7C9 /* InboxZeroLoaderTests.swift */; };
1113
0F9440FD32236514CD7215E9 /* Pods_Freetime.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ECF622FFD773FDA73297C0D0 /* Pods_Freetime.framework */; };
1214
15F28F992108DBA6006421B6 /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F28F982108DBA6006421B6 /* SplashView.swift */; };
@@ -594,6 +596,8 @@
594596
/* End PBXCopyFilesBuildPhase section */
595597

596598
/* Begin PBXFileReference section */
599+
03E8D823221D339200EB792A /* GithubURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GithubURL.swift; sourceTree = "<group>"; };
600+
03E8D825221D358000EB792A /* GithubURLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GithubURLTests.swift; sourceTree = "<group>"; };
597601
03A0EC6221F8F60B008C9CE2 /* RepositoryOverviewHeaderViewModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RepositoryOverviewHeaderViewModels.swift; sourceTree = "<group>"; };
598602
03C127B7220993300062F7C9 /* InboxZeroLoaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InboxZeroLoaderTests.swift; sourceTree = "<group>"; };
599603
07C7DC5A7A907BE73BCA95AC /* Pods-FreetimeTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FreetimeTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FreetimeTests/Pods-FreetimeTests.debug.xcconfig"; sourceTree = "<group>"; };
@@ -1747,6 +1751,7 @@
17471751
295F52A61EF1B9D2000B53CF /* Test.md */,
17481752
291E987C21973FA700E5EED9 /* URLBuilderTests.swift */,
17491753
29827D7321AA5DA300A1B293 /* ViewControllerTestUtil.swift */,
1754+
03E8D825221D358000EB792A /* GithubURLTests.swift */,
17501755
03C127B7220993300062F7C9 /* InboxZeroLoaderTests.swift */,
17511756
);
17521757
path = FreetimeTests;
@@ -2295,6 +2300,7 @@
22952300
C0E3CD4A21BAE49B00185B57 /* NSRegularExpression+StaticString.swift */,
22962301
C0E3CD4C21BAE65000185B57 /* UIImage+StaticString.swift */,
22972302
298C7E2721D80BAF00DD2A60 /* Error+GraphQLForbidden.swift */,
2303+
03E8D823221D339200EB792A /* GithubURL.swift */,
22982304
);
22992305
path = Utility;
23002306
sourceTree = "<group>";
@@ -3015,6 +3021,7 @@
30153021
292FCAFD1EDFCC510026635E /* IssueCollapsedBodies.swift in Sources */,
30163022
290744B61F250A6800FD9E48 /* IssueCommentAutocomplete.swift in Sources */,
30173023
292FCAF61EDFCC510026635E /* IssueCommentCodeBlockCell.swift in Sources */,
3024+
03E8D824221D339200EB792A /* GithubURL.swift in Sources */,
30183025
292FCAF71EDFCC510026635E /* IssueCommentCodeBlockModel.swift in Sources */,
30193026
292FCAF91EDFCC510026635E /* IssueCommentDetailCell.swift in Sources */,
30203027
DC3238931F9BA29D007DD924 /* SearchQuery.swift in Sources */,
@@ -3412,6 +3419,7 @@
34123419
BD89007E20B8844B0026013F /* NetworkingURLPathTests.swift in Sources */,
34133420
291E988521976B5600E5EED9 /* ContentWidthUtilsTests.swift in Sources */,
34143421
2977D8BF215AE12D0073F737 /* LocalNotificationCacheTests.swift in Sources */,
3422+
03E8D826221D358000EB792A /* GithubURLTests.swift in Sources */,
34153423
DC5C02C51F9C6E3500E80B9F /* SearchQueryTests.swift in Sources */,
34163424
293A457E1F296BD500DD1006 /* API.swift in Sources */,
34173425
49AF91B1204B416500DFF325 /* MergeTests.swift in Sources */,

FreetimeTests/GithubURLTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// GithubURLTests.swift
3+
// FreetimeTests
4+
//
5+
// Created by Viktoras Laukevicius on 20/02/2019.
6+
// Copyright © 2019 Ryan Nystrom. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import Freetime
11+
12+
class GithubURLTests: XCTestCase {
13+
14+
func test_codeBlob() {
15+
let repo = RepositoryDetails(owner: "GitHawkApp", name: "GitHawk")
16+
let path = Freetime.FilePath(components: ["Classes", "Issues", "AddCommentClient.swift"])
17+
let url = GithubURL.codeBlob(repo: repo, branch: "master", path: path)!
18+
XCTAssertEqual(url.absoluteString, "https://github.com/GitHawkApp/GitHawk/blob/master/Classes/Issues/AddCommentClient.swift")
19+
}
20+
}

0 commit comments

Comments
 (0)