Kaynağa Gözat

Merge pull request #1190 from deltachat/location_icon_in_chat_bubble

Location icon in chat bubble
bjoern 4 yıl önce
ebeveyn
işleme
541153c4e0

+ 4 - 0
DcCore/DcCore/DC/Wrapper.swift

@@ -1044,6 +1044,10 @@ public class DcMsg {
     public var hasHtml: Bool {
         return dc_msg_has_html(messagePointer) == 1
     }
+    
+    public var hasLocation: Bool {
+        return dc_msg_has_location(messagePointer) == 1
+    }
 
     public var setupCodeBegin: String {
         guard let cString = dc_msg_get_setupcodebegin(messagePointer) else { return "" }

+ 25 - 1
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -403,6 +403,10 @@ public class BaseMessageCell: UITableViewCell {
             if message.showPadlock() {
                 attachPadlock(to: text, color: bottomCompactView ? nil : DcColors.checkmarkGreen)
             }
+            
+            if message.hasLocation {
+                attachLocation(to: text, color: bottomCompactView ? nil : DcColors.checkmarkGreen)
+            }
 
             attachSendingState(message.state, to: text)
             return text
@@ -412,9 +416,29 @@ public class BaseMessageCell: UITableViewCell {
         if message.showPadlock() {
             attachPadlock(to: text)
         }
+        
+        if message.hasLocation {
+            attachLocation(to: text)
+        }
+        
         return text
     }
 
+    private func attachLocation(to text: NSMutableAttributedString, color: UIColor? = nil) {
+        let imageAttachment = NSTextAttachment()
+        
+        if let color = color {
+            imageAttachment.image = UIImage(named: "ic_location")?.maskWithColor(color: color)?.scaleDownImage(toMax: 12)
+        } else {
+            imageAttachment.image = UIImage(named: "ic_location")?.maskWithColor(color: DcColors.grayDateColor)?.scaleDownImage(toMax: 12)
+        }
+        
+        let imageString = NSMutableAttributedString(attachment: imageAttachment)
+        imageString.addAttributes([NSAttributedString.Key.baselineOffset: -0.5], range: NSRange(location: 0, length: 1))
+        text.append(NSAttributedString(string: "\u{202F}"))
+        text.append(imageString)
+    }
+    
     private func attachPadlock(to text: NSMutableAttributedString, color: UIColor? = nil) {
         let imageAttachment = NSTextAttachment()
         if let color = color {
@@ -455,7 +479,7 @@ public class BaseMessageCell: UITableViewCell {
             offset = -3.5
         case DC_STATE_OUT_MDN_RCVD:
             imageAttachment.image = #imageLiteral(resourceName: "ic_done_all_36pt").scaleDownImage(toMax: 16)?.sd_croppedImage(with: CGRect(x: 0, y: 4, width: 16, height: 14))
-            text.append(NSAttributedString(string: " "))
+            text.append(NSAttributedString(string: "\u{202F}"))
             offset = -3.5
         case DC_STATE_OUT_FAILED:
             imageAttachment.image = #imageLiteral(resourceName: "ic_error_36pt").scaleDownImage(toMax: 14)