Selaa lähdekoodia

handle memojis and pasted images as stickers

cyberta 4 vuotta sitten
vanhempi
commit
f65b4bdabb

+ 4 - 0
deltachat-ios.xcodeproj/project.pbxproj

@@ -57,6 +57,7 @@
 		3060119C22DDE24000C1CE6F /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3060119E22DDE24000C1CE6F /* Localizable.strings */; };
 		306011B622E5E7FB00C1CE6F /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 306011B422E5E7FB00C1CE6F /* Localizable.stringsdict */; };
 		30653081254358B10093E196 /* QuoteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30653080254358B10093E196 /* QuoteView.swift */; };
+		3067AA4C2666310E00525036 /* ChatInputTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3067AA4B2666310E00525036 /* ChatInputTextView.swift */; };
 		306C32322445CDE9001D89F3 /* DcLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 306C32312445CDE9001D89F3 /* DcLogger.swift */; };
 		30734326249A280B00BF9AD1 /* MediaQualityController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30734325249A280B00BF9AD1 /* MediaQualityController.swift */; };
 		307A82CC25B8D26700748B57 /* ChatEditingBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 307A82CB25B8D26700748B57 /* ChatEditingBar.swift */; };
@@ -300,6 +301,7 @@
 		306011C822E5E83100C1CE6F /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
 		306011C922E5E83500C1CE6F /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = uk; path = uk.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
 		30653080254358B10093E196 /* QuoteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuoteView.swift; sourceTree = "<group>"; };
+		3067AA4B2666310E00525036 /* ChatInputTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatInputTextView.swift; sourceTree = "<group>"; };
 		306C32312445CDE9001D89F3 /* DcLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DcLogger.swift; sourceTree = "<group>"; };
 		30734325249A280B00BF9AD1 /* MediaQualityController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaQualityController.swift; sourceTree = "<group>"; };
 		307A82CB25B8D26700748B57 /* ChatEditingBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatEditingBar.swift; sourceTree = "<group>"; };
@@ -588,6 +590,7 @@
 				30FDB6B624D193DD0066C48D /* Cells */,
 				30E348DE24F3F819005C93D1 /* ChatTableView.swift */,
 				303492CE2587C2DC00A523D0 /* ChatInputBar.swift */,
+				3067AA4B2666310E00525036 /* ChatInputTextView.swift */,
 				307A82CB25B8D26700748B57 /* ChatEditingBar.swift */,
 				302E1BB3252B5AB4008F4264 /* PlayButtonView.swift */,
 				30F8817524DA97DA0023780E /* BackgroundContainer.swift */,
@@ -1323,6 +1326,7 @@
 				AEFBE22F23FEF23D0045327A /* ProviderInfoCell.swift in Sources */,
 				AE6EC5242497663200A400E4 /* UIImageView+Extensions.swift in Sources */,
 				30F8817624DA97DA0023780E /* BackgroundContainer.swift in Sources */,
+				3067AA4C2666310E00525036 /* ChatInputTextView.swift in Sources */,
 				30B0ACFA24AB5B99004D5E29 /* SettingsEphemeralMessageController.swift in Sources */,
 				B20462E42440A4A600367A57 /* SettingsAutodelOverviewController.swift in Sources */,
 				305962102346154D00C80F33 /* String+Extension.swift in Sources */,

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

@@ -890,6 +890,9 @@ class ChatViewController: UITableViewController {
         messageInputBar.inputTextView.scrollIndicatorInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
         configureInputBarItems()
         messageInputBar.inputTextView.delegate = self
+        if let inputTextView = messageInputBar.inputTextView as? ChatInputTextView {
+            inputTextView.imagePasteDelegate = self
+        }
     }
 
     private func evaluateInputBar(draft: DraftModel) {
@@ -1262,6 +1265,14 @@ class ChatViewController: UITableViewController {
         }
     }
 
+    private func sendSticker(_ image: UIImage) {
+        DispatchQueue.global().async {
+            if let path = DcUtils.saveImage(image: image) {
+                self.sendAttachmentMessage(viewType: DC_MSG_STICKER, filePath: path, message: nil)
+            }
+        }
+    }
+
     private func sendAttachmentMessage(viewType: Int32, filePath: String, message: String? = nil, quoteMessage: DcMsg? = nil) {
         let msg = DcMsg(viewType: viewType)
         msg.setFile(filepath: filePath)
@@ -1645,3 +1656,10 @@ extension ChatViewController: UITextViewDelegate {
         return true
     }
 }
+
+// MARK: - InputBarImagePasteDelegate
+extension ChatViewController: ChatInputTextViewPasteDelegate {
+    func onImagePasted(image: UIImage) {
+        sendSticker(image)
+    }
+}

+ 11 - 0
deltachat-ios/Chat/Views/ChatInputBar.swift

@@ -24,6 +24,17 @@ public class ChatInputBar: InputBarAccessoryView {
         backgroundColor = DcColors.chatBackgroundColor
     }
 
+    override open func setup() {
+        replaceInputBar()
+        super.setup()
+    }
+
+    func replaceInputBar() {
+        inputTextView = ChatInputTextView()
+        inputTextView.translatesAutoresizingMaskIntoConstraints = false
+        inputTextView.inputBarAccessoryView = self
+    }
+
     func setupKeyboardObserver() {
         NotificationCenter.default.addObserver(
             self,

+ 27 - 0
deltachat-ios/Chat/Views/ChatInputTextView.swift

@@ -0,0 +1,27 @@
+import Foundation
+import InputBarAccessoryView
+
+public class ChatInputTextView: InputTextView {
+
+    public weak var imagePasteDelegate: ChatInputTextViewPasteDelegate?
+
+    // MARK: - Image Paste Support
+    open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
+        if action == NSSelectorFromString("paste:") && UIPasteboard.general.image != nil {
+            return true
+        }
+        return super.canPerformAction(action, withSender: sender)
+    }
+
+    open override func paste(_ sender: Any?) {
+        guard let image = UIPasteboard.general.image else {
+            return super.paste(sender)
+        }
+        imagePasteDelegate?.onImagePasted(image: image)
+    }
+}
+
+
+public protocol ChatInputTextViewPasteDelegate: class {
+    func onImagePasted(image: UIImage)
+}