Sfoglia il codice sorgente

improved cancelling of chat long tap context menu, reimplemented contact requests view ask to chat

cyberta 4 anni fa
parent
commit
d1707b3029

+ 24 - 7
deltachat-ios/Chat/ChatViewControllerNew.swift

@@ -331,7 +331,7 @@ class ChatViewControllerNew: UITableViewController {
     }
 
     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-        UIMenuController.shared.setMenuVisible(false, animated: true)
+        _ = handleUIMenu()
 
         let id = messageIds[indexPath.row]
         let message = DcMsg(id: id)
@@ -410,7 +410,7 @@ class ChatViewControllerNew: UITableViewController {
             message.type == DC_MSG_VOICE {
             showMediaGalleryFor(message: message)
         }
-        UIMenuController.shared.setMenuVisible(false, animated: true)
+        _ = handleUIMenu()
     }
 
     func configureAvatarVisibility(for message: DcMsg, at indexPath: IndexPath) -> Bool {
@@ -1057,19 +1057,34 @@ class ChatViewControllerNew: UITableViewController {
         navigationController?.present(inputDlg, animated: true, completion: nil)
     }
 
+    func handleUIMenu() -> Bool {
+        if UIMenuController.shared.isMenuVisible {
+            UIMenuController.shared.setMenuVisible(false, animated: true)
+            return true
+        }
+        return false
+    }
 }
 
 // MARK: - BaseMessageCellDelegate
 extension ChatViewControllerNew: BaseMessageCellDelegate {
-    func phoneNumberTapped(number: String) {
+
+    @objc func textTapped(indexPath: IndexPath) {
+        _ = handleUIMenu()
+    }
+
+    @objc func phoneNumberTapped(number: String) {
+        if handleUIMenu() { return }
         logger.debug("phone number tapped \(number)")
     }
 
-    func commandTapped(command: String) {
+    @objc func commandTapped(command: String) {
+        if handleUIMenu() { return }
         logger.debug("command tapped \(command)")
     }
 
-    func urlTapped(url: URL) {
+    @objc func urlTapped(url: URL) {
+        if handleUIMenu() { return }
         if Utils.isEmail(url: url) {
             logger.debug("tapped on contact")
             let email = Utils.getEmailFrom(url)
@@ -1080,10 +1095,12 @@ extension ChatViewControllerNew: BaseMessageCellDelegate {
         }
     }
 
-    func imageTapped(indexPath: IndexPath) {
+    @objc func imageTapped(indexPath: IndexPath) {
+        if handleUIMenu() { return }
         showMediaGalleryFor(indexPath: indexPath)
     }
-    func avatarTapped(indexPath: IndexPath) {
+
+    @objc func avatarTapped(indexPath: IndexPath) {
         let message = DcMsg(id: messageIds[indexPath.row])
         let contactDetailController = ContactDetailViewController(dcContext: dcContext, contactId: message.fromContactId)
         navigationController?.pushViewController(contactDetailController, animated: true)

+ 6 - 4
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -72,7 +72,7 @@ public class BaseMessageCell: UITableViewCell {
 
     public weak var baseDelegate: BaseMessageCellDelegate?
 
-    lazy var messageLabel: PaddingTextView = {
+    public lazy var messageLabel: PaddingTextView = {
         let view = PaddingTextView()
         view.translatesAutoresizingMaskIntoConstraints = false
         view.setContentHuggingPriority(.defaultLow, for: .vertical)
@@ -210,9 +210,11 @@ public class BaseMessageCell: UITableViewCell {
     @objc
     open func handleTapGesture(_ gesture: UIGestureRecognizer) {
         guard gesture.state == .ended else { return }
-
         let touchLocation = gesture.location(in: messageLabel)
-        _ = messageLabel.label.handleGesture(touchLocation)
+        let isHandled = messageLabel.label.handleGesture(touchLocation)
+        if !isHandled, let tableView = self.superview as? UITableView, let indexPath = tableView.indexPath(for: self) {
+            self.baseDelegate?.textTapped(indexPath: indexPath)
+        }
     }
 
     @objc func onAvatarTapped() {
@@ -409,5 +411,5 @@ public protocol BaseMessageCellDelegate: class {
     func urlTapped(url: URL) // url is eg. `https://foo.bar`
     func imageTapped(indexPath: IndexPath)
     func avatarTapped(indexPath: IndexPath)
-
+    func textTapped(indexPath: IndexPath)
 }

+ 28 - 32
deltachat-ios/Controller/MailboxViewController.swift

@@ -16,47 +16,43 @@ class MailboxViewController: ChatViewControllerNew {
     override func viewDidLoad() {
         super.viewDidLoad()
         navigationItem.title = String.localized("menu_deaddrop")
-
     }
 
-    override func viewWillAppear(_ animated: Bool) {
-        super.viewWillAppear(animated)
+    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        askToChat(messageId: messageIds[indexPath.row])
     }
 
-   /* override func didTapMessage(in cell: MessageCollectionViewCell) {
-        askToChat(cell: cell)
+    override func phoneNumberTapped(number: String) {}
+    override func commandTapped(command: String) {}
+    override func urlTapped(url: URL) {}
+    override func imageTapped(indexPath: IndexPath) {
+        askToChat(messageId: messageIds[indexPath.row])
     }
-
-    override func didTapCellTopLabel(in cell: MessageCollectionViewCell) {
-        askToChat(cell: cell)
+    override func avatarTapped(indexPath: IndexPath) {
+        askToChat(messageId: messageIds[indexPath.row])
     }
-
-    override func didTapAvatar(in cell: MessageCollectionViewCell) {
-        askToChat(cell: cell)
-    }
-
-    override func didTapBackground(in cell: MessageCollectionViewCell) {
-        askToChat(cell: cell)
+    override func textTapped(indexPath: IndexPath) {
+        askToChat(messageId: messageIds[indexPath.row])
     }
-*/
 
-/*    private func askToChat(cell: MessageCollectionViewCell) {
-        if let indexPath = messagesCollectionView.indexPath(for: cell) {
 
-            let message = messageList[indexPath.section]
-            let dcContact = message.fromContact
-            let title = String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr)
-            let alert = UIAlertController(title: title, message: nil, preferredStyle: .safeActionSheet)
-            alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
-                let chat = self.dcContext.createChatByMessageId(message.id)
-                self.showChat(chatId: chat.id)
-            }))
-            alert.addAction(UIAlertAction(title: String.localized("menu_block_contact"), style: .destructive, handler: { _ in
-                dcContact.block()
-            }))
-            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
-            present(alert, animated: true, completion: nil)
+    func askToChat(messageId: Int) {
+        if handleUIMenu() { return }
+        let message = DcMsg(id: messageId)
+        if message.isInfo {
+            return
         }
+        let dcContact = message.fromContact
+        let title = String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr)
+        let alert = UIAlertController(title: title, message: nil, preferredStyle: .safeActionSheet)
+        alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
+            let chat = self.dcContext.createChatByMessageId(messageId)
+            self.showChat(chatId: chat.id)
+        }))
+        alert.addAction(UIAlertAction(title: String.localized("menu_block_contact"), style: .destructive, handler: { _ in
+            dcContact.block()
+        }))
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
+        present(alert, animated: true, completion: nil)
     }
- */
 }