فهرست منبع

Merge pull request #545 from deltachat/encryption_state_UI

show padlock if message was encrypted (#400)
bjoern 5 سال پیش
والد
کامیت
24bc3eec6d

+ 23 - 0
deltachat-ios/Assets.xcassets/ic_lock.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "ic_lock_lightergrey_1x.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "ic_lock_lightergrey_2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "ic_lock_lightergrey_3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
deltachat-ios/Assets.xcassets/ic_lock.imageset/ic_lock_lightergrey_1x.png


BIN
deltachat-ios/Assets.xcassets/ic_lock.imageset/ic_lock_lightergrey_2x.png


BIN
deltachat-ios/Assets.xcassets/ic_lock.imageset/ic_lock_lightergrey_3x.png


+ 21 - 3
deltachat-ios/Controller/ChatViewController.swift

@@ -780,12 +780,12 @@ extension ChatViewController: MessagesDataSource {
 
         var timestampAttributes: [NSAttributedString.Key: Any] = [
             .font: UIFont.systemFont(ofSize: 12),
-            .foregroundColor: UIColor.lightGray,
+            .foregroundColor: DcColors.grayDateColor,
             .paragraphStyle: NSParagraphStyle()
         ]
 
+        let text = NSMutableAttributedString()
         if isFromCurrentSender(message: message) {
-            let text = NSMutableAttributedString()
             if let style = NSMutableParagraphStyle.default.mutableCopy() as? NSMutableParagraphStyle {
                 style.alignment = .right
                 timestampAttributes[.paragraphStyle] = style
@@ -793,6 +793,10 @@ extension ChatViewController: MessagesDataSource {
 
             text.append(NSAttributedString(string: m.formattedSentDate(), attributes: timestampAttributes))
 
+            if m.showPadlock() {
+                attachPadlock(to: text)
+            }
+
             // TODO: this should be replaced by the respective icons,
             // for accessibility, the a11y strings should be added
             var stateDescription: String
@@ -827,7 +831,21 @@ extension ChatViewController: MessagesDataSource {
             }
         }
 
-        return NSAttributedString(string: m.formattedSentDate(), attributes: timestampAttributes)
+        text.append(NSAttributedString(string: m.formattedSentDate(), attributes: timestampAttributes))
+        if m.showPadlock() {
+            attachPadlock(to: text)
+        }
+        return text
+    }
+
+    private func attachPadlock(to text: NSMutableAttributedString) {
+        let imageAttachment = NSTextAttachment()
+        imageAttachment.image = UIImage(named: "ic_lock")
+        imageAttachment.image?.accessibilityIdentifier = String.localized("encrypted_message")
+        let imageString = NSMutableAttributedString(attachment: imageAttachment)
+        imageString.addAttributes([NSAttributedString.Key.baselineOffset: -1], range: NSRange(location: 0, length: 1))
+        text.append(NSAttributedString(string: " "))
+        text.append(imageString)
     }
 
     func updateMessage(_ messageId: Int) {

+ 4 - 0
deltachat-ios/DC/Wrapper.swift

@@ -859,6 +859,10 @@ class DcMsg: MessageType {
         return swiftString
     }
 
+    func showPadlock() -> Bool {
+        return dc_msg_get_showpadlock(messagePointer) == 1
+    }
+
     func createChat() -> DcChat {
         let chatId = dc_create_chat_by_msg_id(mailboxPointer, UInt32(id))
         return DcChat(id: Int(chatId))

+ 1 - 0
deltachat-ios/Helper/Colors.swift

@@ -13,6 +13,7 @@ struct DcColors {
     static let checkmarkGreen = UIColor.themeColor(light: UIColor.rgb(red: 112, green: 177, blue: 92))
     static let defaultTextColor = UIColor.themeColor(light: .darkText, dark: .white)
     static let grayTextColor = UIColor.themeColor(light: .darkGray, dark: .lightGray)
+    static let grayDateColor = UIColor.themeColor(lightHex: "999999", darkHex: "bbbbbb") // slight variations of lightGray (#aaaaaa)
     static let secondaryTextColor = UIColor.themeColor(lightHex: "848ba7", darkHex: "a5abc0")
     static let inputFieldColor =  UIColor.themeColor(light: UIColor(red: 245 / 255, green: 245 / 255, blue: 245 / 255, alpha: 1),
                                                      dark: UIColor(red: 10 / 255, green: 10 / 255, blue: 10 / 255, alpha: 1))