ソースを参照

Merge pull request #1346 from deltachat/copy-addr-to-clipboard

add an option to copy a contact's email address to the clipboard
cyBerta 3 年 前
コミット
27e5a78736

+ 13 - 0
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -32,6 +32,13 @@ class ContactDetailViewController: UITableViewController {
         return cell
     }()
 
+    private lazy var copyToClipboardCell: ActionCell = {
+        let cell = ActionCell()
+        cell.actionTitle = String.localized("menu_copy_to_clipboard")
+        cell.actionColor = SystemColor.blue.uiColor
+        return cell
+    }()
+
     private lazy var blockContactCell: ActionCell = {
         let cell = ActionCell()
         cell.actionTitle = viewModel.contact.isBlocked ? String.localized("menu_unblock_contact") : String.localized("menu_block_contact")
@@ -169,6 +176,8 @@ class ContactDetailViewController: UITableViewController {
                 return archiveChatCell
             case .showEncrInfo:
                 return showEncrInfoCell
+            case .copyToClipboard:
+                return copyToClipboardCell
             case .blockContact:
                 return blockContactCell
             case .deleteChat:
@@ -254,6 +263,10 @@ class ContactDetailViewController: UITableViewController {
         case .showEncrInfo:
             tableView.deselectRow(at: indexPath, animated: false)
             showEncrInfoAlert()
+        case .copyToClipboard:
+            tableView.deselectRow(at: indexPath, animated: true)
+            let pasteboard = UIPasteboard.general
+            pasteboard.string = viewModel.contact.email
         case .blockContact:
             tableView.deselectRow(at: indexPath, animated: false)
             toggleBlockContact()

+ 3 - 1
deltachat-ios/ViewModel/ContactDetailViewModel.swift

@@ -23,6 +23,7 @@ class ContactDetailViewModel {
     enum ChatAction {
         case archiveChat
         case showEncrInfo
+        case copyToClipboard
         case blockContact
         case deleteChat
     }
@@ -84,12 +85,13 @@ class ContactDetailViewModel {
             chatActions = [.archiveChat]
             if !isDeviceTalk && !isSavedMessages {
                 chatActions.append(.showEncrInfo)
+                chatActions.append(.copyToClipboard)
                 chatActions.append(.blockContact)
             }
             chatActions.append(.deleteChat)
         } else {
             chatOptions = [.gallery, .documents, .startChat]
-            chatActions = [.showEncrInfo, .blockContact]
+            chatActions = [.showEncrInfo, .copyToClipboard, .blockContact]
         }
     }