Add "Open in Safari" activity

This commit is contained in:
Justin Mazzocchi 2021-01-31 05:57:30 -08:00
parent 0188a65dc4
commit b0132640ab
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
4 changed files with 55 additions and 1 deletions

View file

@ -0,0 +1,39 @@
// Copyright © 2021 Metabolist. All rights reserved.
import UIKit
final class OpenInSafariActivity: UIActivity {
private var url: URL?
override var activityType: UIActivity.ActivityType? {
.init(String(describing: Self.self))
}
override var activityTitle: String? {
NSLocalizedString("Open in Safari", comment: "")
}
override var activityImage: UIImage? {
UIImage(systemName: "safari", withConfiguration: UIImage.SymbolConfiguration(scale: .large))
}
override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
activityItems.allSatisfy {
guard let url = $0 as? URL else { return false }
return UIApplication.shared.canOpenURL(url)
}
}
override func prepare(withActivityItems activityItems: [Any]) {
url = activityItems.first { $0 is URL } as? URL
}
override func perform() {
guard let url = url else { return }
UIApplication.shared.open(url) {
self.activityDidFinish($0)
}
}
}

View file

@ -28,6 +28,7 @@
"account.unblock.confirm-%@" = "Unblock %@?";
"account.unfollow" = "Unfollow";
"account.unmute" = "Unmute";
"activity.open-in-safari" = "Open in Safari";
"add" = "Add";
"apns-default-message" = "New notification";
"add-identity.instance-url" = "Instance URL";

View file

@ -57,6 +57,7 @@
D036EBC2259FE2AD00EC1CFC /* UIVIewController+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0E7AD3825870B13005F5E2D /* UIVIewController+Extensions.swift */; };
D03D87F425C23C44004DCBB2 /* SecondaryNavigationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D03D87F325C23C44004DCBB2 /* SecondaryNavigationTitleView.swift */; };
D0477F1525C68BAC005C5368 /* PrefetchRequestModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0477F1425C68BAC005C5368 /* PrefetchRequestModifier.swift */; };
D0477F2C25C6EBAD005C5368 /* OpenInSafariActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0477F2B25C6EBAD005C5368 /* OpenInSafariActivity.swift */; };
D04F9E8E259E9C950081B0C9 /* ViewModels in Frameworks */ = {isa = PBXBuildFile; productRef = D04F9E8D259E9C950081B0C9 /* ViewModels */; };
D05936CF25A8D79800754FDF /* EditAttachmentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05936CE25A8D79800754FDF /* EditAttachmentViewController.swift */; };
D05936D025A8D79800754FDF /* EditAttachmentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05936CE25A8D79800754FDF /* EditAttachmentViewController.swift */; };
@ -253,6 +254,7 @@
D036AA16254CA823009094DF /* StatusBodyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBodyView.swift; sourceTree = "<group>"; };
D03D87F325C23C44004DCBB2 /* SecondaryNavigationTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondaryNavigationTitleView.swift; sourceTree = "<group>"; };
D0477F1425C68BAC005C5368 /* PrefetchRequestModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefetchRequestModifier.swift; sourceTree = "<group>"; };
D0477F2B25C6EBAD005C5368 /* OpenInSafariActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenInSafariActivity.swift; sourceTree = "<group>"; };
D047FA8C24C3E21200AF17C5 /* Metatext.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Metatext.app; sourceTree = BUILT_PRODUCTS_DIR; };
D05936CE25A8D79800754FDF /* EditAttachmentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditAttachmentViewController.swift; sourceTree = "<group>"; };
D05936DD25A937EC00754FDF /* EditThumbnailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditThumbnailView.swift; sourceTree = "<group>"; };
@ -549,9 +551,18 @@
path = "View Repesentables";
sourceTree = "<group>";
};
D0477F2A25C6EB90005C5368 /* Activities */ = {
isa = PBXGroup;
children = (
D0477F2B25C6EBAD005C5368 /* OpenInSafariActivity.swift */,
);
path = Activities;
sourceTree = "<group>";
};
D047FA7F24C3E21000AF17C5 = {
isa = PBXGroup;
children = (
D0477F2A25C6EB90005C5368 /* Activities */,
D0C7D45224F76169001EBDBB /* Assets.xcassets */,
D0AD03552505814D0085A466 /* Base16 */,
D0FE1C9625368A15003EF1EB /* Caches */,
@ -969,6 +980,7 @@
D0C7D49A24F7616A001EBDBB /* TableView.swift in Sources */,
D08B8D622540DE3B00B1EBEF /* ZoomTransitionController.swift in Sources */,
D0F0B12E251A97E400942152 /* TableViewController.swift in Sources */,
D0477F2C25C6EBAD005C5368 /* OpenInSafariActivity.swift in Sources */,
D0DD50CB256B1F24004A04F7 /* ReportView.swift in Sources */,
D0477F1525C68BAC005C5368 /* PrefetchRequestModifier.swift in Sources */,
D097F41B25BE3E1A00859F2C /* SearchScope+Extensions.swift in Sources */,

View file

@ -513,7 +513,9 @@ private extension TableViewController {
}
func share(url: URL) {
let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
let activityViewController = UIActivityViewController(
activityItems: [url],
applicationActivities: [OpenInSafariActivity()])
if UIDevice.current.userInterfaceIdiom == .pad {
guard let sourceView = tableView.viewWithTag(url.hashValue) else { return }