11import Foundation
2+ import UIKit
23import SVProgressHUD
34
45@objc class PostSharingController : NSObject {
56
6- @objc func shareController( _ title: String ? , summary : String ? , link: String ? ) -> UIActivityViewController {
7+ @objc func shareController( _ title: String ? , link: String ? ) -> UIActivityViewController {
78 let url = link. flatMap ( URL . init ( string: ) )
8- let allItems : [ Any ? ] = [ title , summary , url]
9+ let allItems : [ Any ? ] = [ url]
910 let nonNilActivityItems = allItems. compactMap ( { $0 } )
1011
11- var activities : [ UIActivity ] = [ CopyLinkActivity ( ) ]
12- activities. append ( contentsOf: WPActivityDefaults . defaultActivities ( ) as! [ UIActivity ] )
12+ let activities = WPActivityDefaults . defaultActivities ( ) as! [ UIActivity ]
1313 let controller = UIActivityViewController ( activityItems: nonNilActivityItems, applicationActivities: activities)
1414
15- if let str = title {
16- controller. setValue ( str , forKey: " subject " )
15+ if let title {
16+ controller. setValue ( title , forKey: " subject " )
1717 }
1818 controller. completionWithItemsHandler = { ( activityType, completed, returnedItems, error) in
1919 if completed {
@@ -24,11 +24,8 @@ import SVProgressHUD
2424 return controller
2525 }
2626
27- @objc func sharePost( _ title: String , summary: String , link: String ? , fromBarButtonItem anchorBarButtonItem: UIBarButtonItem , inViewController viewController: UIViewController ) {
28- let controller = shareController (
29- title,
30- summary: summary,
31- link: link)
27+ @objc func sharePost( _ title: String , link: String ? , fromBarButtonItem anchorBarButtonItem: UIBarButtonItem , inViewController viewController: UIViewController ) {
28+ let controller = shareController ( title, link: link)
3229
3330 if !UIDevice. isPad ( ) {
3431 viewController. present ( controller, animated: true )
@@ -44,16 +41,12 @@ import SVProgressHUD
4441 }
4542 }
4643
47- @objc func sharePost( _ title: String ? , summary : String ? , link: String ? , fromView anchorView: UIView , inViewController viewController: UIViewController ) {
48- sharePost ( title, summary : summary , link: link, fromAnchor: . view( anchorView) , inViewController: viewController)
44+ @objc func sharePost( _ title: String ? , link: String ? , fromView anchorView: UIView , inViewController viewController: UIViewController ) {
45+ sharePost ( title, link: link, fromAnchor: . view( anchorView) , inViewController: viewController)
4946 }
5047
51- private func sharePost( _ title: String ? , summary: String ? , link: String ? , fromAnchor anchor: PopoverAnchor , inViewController viewController: UIViewController ) {
52- let controller = shareController (
53- title,
54- summary: summary,
55- link: link)
56-
48+ private func sharePost( _ title: String ? , link: String ? , fromAnchor anchor: PopoverAnchor , inViewController viewController: UIViewController ) {
49+ let controller = shareController ( title, link: link)
5750 if !UIDevice. isPad ( ) {
5851 viewController. present ( controller, animated: true )
5952 return
@@ -75,57 +68,47 @@ import SVProgressHUD
7568 }
7669
7770 @objc func sharePage( _ page: Page , fromView anchorView: UIView , inViewController viewController: UIViewController ) {
78-
7971 sharePost (
8072 page. titleForDisplay ( ) ,
81- summary: page. contentPreviewForDisplay ( ) ,
8273 link: page. permaLink,
8374 fromView: anchorView,
8475 inViewController: viewController)
8576 }
8677
8778 @objc func sharePost( _ post: Post , fromBarButtonItem anchorBarButtonItem: UIBarButtonItem , inViewController viewController: UIViewController ) {
88-
8979 sharePost (
9080 post. titleForDisplay ( ) ,
91- summary: post. contentPreviewForDisplay ( ) ,
9281 link: post. permaLink,
9382 fromBarButtonItem: anchorBarButtonItem,
9483 inViewController: viewController)
9584 }
9685
9786 @objc func sharePost( _ post: Post , fromView anchorView: UIView , inViewController viewController: UIViewController ) {
98-
9987 sharePost (
10088 post. titleForDisplay ( ) ,
101- summary: post. contentPreviewForDisplay ( ) ,
10289 link: post. permaLink,
10390 fromView: anchorView,
10491 inViewController: viewController)
10592 }
10693
10794 func shareReaderPost( _ post: ReaderPost , fromAnchor anchor: PopoverAnchor , inViewController viewController: UIViewController ) {
108-
10995 sharePost (
11096 post. titleForDisplay ( ) ,
111- summary: post. contentPreviewForDisplay ( ) ,
11297 link: post. permaLink,
11398 fromAnchor: anchor,
11499 inViewController: viewController)
115100 }
116101
117102 @objc func shareReaderPost( _ post: ReaderPost , fromView anchorView: UIView , inViewController viewController: UIViewController ) {
118-
119103 sharePost (
120104 post. titleForDisplay ( ) ,
121- summary: post. contentPreviewForDisplay ( ) ,
122105 link: post. permaLink,
123106 fromView: anchorView,
124107 inViewController: viewController)
125108 }
126109
127110 @objc func shareURL( url: NSURL , fromRect rect: CGRect , inView view: UIView , inViewController viewController: UIViewController ) {
128- let controller = shareController ( " " , summary : " " , link: url. absoluteString)
111+ let controller = shareController ( " " , link: url. absoluteString)
129112
130113 if !UIDevice. isPad ( ) {
131114 viewController. present ( controller, animated: true )
@@ -147,54 +130,3 @@ import SVProgressHUD
147130
148131 typealias PopoverAnchor = UIPopoverPresentationController . PopoverAnchor
149132}
150-
151- private class CopyLinkActivity : UIActivity {
152- var activityItems = [ Any] ( )
153- private var url = URL ( string: " " )
154-
155- override var activityTitle : String ? {
156- return NSLocalizedString (
157- " share.sheet.copy.link.title " ,
158- value: " Copy Link " ,
159- comment: " Title for the \" Copy Link \" action in Share Sheet. "
160- )
161- }
162-
163- override var activityImage : UIImage ? {
164- return UIImage ( systemName: " link " )
165- }
166-
167- override var activityType : UIActivity . ActivityType ? {
168- return UIActivity . ActivityType ( rawValue: " copy.link.activity " )
169- }
170-
171- override class var activityCategory : UIActivity . Category {
172- return . action
173- }
174-
175- override func canPerform( withActivityItems activityItems: [ Any ] ) -> Bool {
176- for activityItem in activityItems {
177- if let _ = activityItem as? URL {
178- return true
179- }
180- }
181- return false
182- }
183-
184- override func prepare( withActivityItems activityItems: [ Any ] ) {
185- for activityItem in activityItems {
186- if let url = activityItem as? URL {
187- self . url = url
188- }
189- }
190- self . activityItems = activityItems
191- }
192-
193- override func perform( ) {
194- guard let url else {
195- return
196- }
197- UIPasteboard . general. string = url. absoluteString
198- activityDidFinish ( true )
199- }
200- }
0 commit comments