Browse Source

enable send button if attachment was added as draft

cyberta 4 years ago
parent
commit
a0907cea8b

+ 13 - 0
deltachat-ios/Chat/ChatViewController.swift

@@ -627,6 +627,10 @@ class ChatViewController: UITableViewController {
         configureInputBarItems()
         configureInputBarItems()
     }
     }
 
 
+    func evaluateInputBar(draft: DraftModel) {
+        let isEnabled = !(draft.draftText?.isEmpty ?? true) || draft.draftAttachment != nil
+        messageInputBar.sendButton.isEnabled = isEnabled
+    }
 
 
     private func configureInputBarItems() {
     private func configureInputBarItems() {
 
 
@@ -646,6 +650,7 @@ class ChatViewController: UITableViewController {
         messageInputBar.sendButton.contentEdgeInsets = UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)
         messageInputBar.sendButton.contentEdgeInsets = UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)
         messageInputBar.sendButton.setSize(CGSize(width: 40, height: 40), animated: false)
         messageInputBar.sendButton.setSize(CGSize(width: 40, height: 40), animated: false)
         messageInputBar.padding = UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 12)
         messageInputBar.padding = UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 12)
+        messageInputBar.shouldManageSendButtonEnabledState = false
 
 
         let leftItems = [
         let leftItems = [
             InputBarButtonItem()
             InputBarButtonItem()
@@ -1119,6 +1124,8 @@ class ChatViewController: UITableViewController {
         }
         }
         return false
         return false
     }
     }
+
+
 }
 }
 
 
 // MARK: - BaseMessageCellDelegate
 // MARK: - BaseMessageCellDelegate
@@ -1228,6 +1235,7 @@ extension ChatViewController: InputBarAccessoryViewDelegate {
 
 
     func inputBar(_ inputBar: InputBarAccessoryView, textViewTextDidChangeTo text: String) {
     func inputBar(_ inputBar: InputBarAccessoryView, textViewTextDidChangeTo text: String) {
         draft.draftText = text
         draft.draftText = text
+        evaluateInputBar(draft: draft)
     }
     }
 }
 }
 
 
@@ -1240,5 +1248,10 @@ extension ChatViewController: QuotePreviewDelegate, MediaPreviewDelegate {
     func onCancelAttachment() {
     func onCancelAttachment() {
         draft.setAttachment(viewType: nil, path: nil, mimetype: nil)
         draft.setAttachment(viewType: nil, path: nil, mimetype: nil)
         configureDraftArea(draft: draft)
         configureDraftArea(draft: draft)
+        evaluateInputBar(draft: draft)
+    }
+
+    func onAttachmentAdded() {
+        evaluateInputBar(draft: draft)
     }
     }
 }
 }

+ 4 - 0
deltachat-ios/Chat/DraftModel.swift

@@ -61,4 +61,8 @@ public class DraftModel {
         }
         }
         context.setDraft(chatId: chatId, message: draftMessage)
         context.setDraft(chatId: chatId, message: draftMessage)
     }
     }
+
+    public func canSend() -> Bool {
+        return !(draftText?.isEmpty ?? true) || draftAttachment != nil
+    }
 }
 }

+ 9 - 0
deltachat-ios/Chat/Views/DraftArea.swift

@@ -0,0 +1,9 @@
+//
+//  DraftArea.swift
+//  deltachat-ios
+//
+//  Created by Macci on 01.12.20.
+//  Copyright © 2020 Jonas Reinsch. All rights reserved.
+//
+
+import Foundation

+ 3 - 2
deltachat-ios/Chat/Views/MediaPreview.swift

@@ -3,6 +3,7 @@ import SDWebImage
 
 
 public protocol MediaPreviewDelegate: class {
 public protocol MediaPreviewDelegate: class {
     func onCancelAttachment()
     func onCancelAttachment()
+    func onAttachmentAdded()
 }
 }
 class MediaPreview: DraftPreview {
 class MediaPreview: DraftPreview {
     var imageWidthConstraint: NSLayoutConstraint?
     var imageWidthConstraint: NSLayoutConstraint?
@@ -34,9 +35,9 @@ class MediaPreview: DraftPreview {
                 if let error = error {
                 if let error = error {
                     logger.error("could not load draft image: \(error)")
                     logger.error("could not load draft image: \(error)")
                     self.cancel()
                     self.cancel()
-                }
-                if let image = image {
+                } else if let image = image {
                     self.setAspectRatio(image: image)
                     self.setAspectRatio(image: image)
+                    self.delegate?.onAttachmentAdded()
                 }
                 }
             })
             })