From e88210bbb751fc50c0b5a827981ccac278eea767 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 15 Aug 2019 15:19:23 -0500 Subject: [PATCH] Add copy url actions for feeds --- iOS/MasterFeed/MasterFeedViewController.swift | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index f7ef5fc9d..c16bf983c 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -612,6 +612,14 @@ private extension MasterFeedViewController { actions.append(homePageAction) } + if let copyFeedPageAction = self.copyFeedPageAction(indexPath: indexPath) { + actions.append(copyFeedPageAction) + } + + if let copyHomePageAction = self.copyHomePageAction(indexPath: indexPath) { + actions.append(copyHomePageAction) + } + if includeDeleteRename { actions.append(self.deleteAction(indexPath: indexPath)) actions.append(self.renameAction(indexPath: indexPath)) @@ -639,6 +647,35 @@ private extension MasterFeedViewController { return action } + func copyFeedPageAction(indexPath: IndexPath) -> UIAction? { + guard let node = coordinator.nodeFor(indexPath), + let feed = node.representedObject as? Feed, + let url = URL(string: feed.url) else { + return nil + } + + let title = NSLocalizedString("Copy Feed URL", comment: "Copy Feed URL") + let action = UIAction(title: title, image: UIImage(systemName: "doc.on.doc")) { action in + UIPasteboard.general.url = url + } + return action + } + + func copyHomePageAction(indexPath: IndexPath) -> UIAction? { + guard let node = coordinator.nodeFor(indexPath), + let feed = node.representedObject as? Feed, + let homePageURL = feed.homePageURL, + let url = URL(string: homePageURL) else { + return nil + } + + let title = NSLocalizedString("Copy Home Page URL", comment: "Copy Home Page URL") + let action = UIAction(title: title, image: UIImage(systemName: "doc.on.doc")) { action in + UIPasteboard.general.url = url + } + return action + } + func deleteAction(indexPath: IndexPath) -> UIAction { let title = NSLocalizedString("Delete", comment: "Delete") let action = UIAction(title: title, image: UIImage(systemName: "trash")) { action in