瀏覽代碼

feat: display verified icon on avatars

dignifiedquire 6 年之前
父節點
當前提交
1c51a63506

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

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

二進制
deltachat-ios/Assets.xcassets/approval.imageset/approval.png


二進制
deltachat-ios/Assets.xcassets/approval.imageset/approval@2x.png


二進制
deltachat-ios/Assets.xcassets/approval.imageset/approval@3x.png


+ 55 - 13
deltachat-ios/ContactCell.swift

@@ -9,7 +9,9 @@
 import UIKit
 
 class ContactCell: UITableViewCell {
-    let initialsLabel: UILabel = UILabel()
+    let avatar = UIView()
+    let imgView = UIImageView()
+    let initialsLabel = UILabel()
     let nameLabel = UILabel()
     let emailLabel = UILabel()
 
@@ -27,33 +29,47 @@ class ContactCell: UITableViewCell {
         super.init(style: style, reuseIdentifier: reuseIdentifier)
 
         // configure and layout initialsLabel
-        let initialsLabelSize: CGFloat = 48
-        let initialsLabelCornerRadius = initialsLabelSize / 2
+        let initialsLabelSize: CGFloat = 54
+        let initialsLabelCornerRadius = (initialsLabelSize - 6) / 2
         let margin: CGFloat = 15
+
         initialsLabel.textAlignment = NSTextAlignment.center
         initialsLabel.textColor = UIColor.white
         initialsLabel.font = UIFont.systemFont(ofSize: 22)
         initialsLabel.translatesAutoresizingMaskIntoConstraints = false
-        initialsLabel.widthAnchor.constraint(equalToConstant: initialsLabelSize).isActive = true
-        initialsLabel.heightAnchor.constraint(equalToConstant: initialsLabelSize).isActive = true
+        avatar.translatesAutoresizingMaskIntoConstraints = false
+        initialsLabel.widthAnchor.constraint(equalToConstant: initialsLabelSize - 6).isActive = true
+        initialsLabel.heightAnchor.constraint(equalToConstant: initialsLabelSize - 6).isActive = true
+        // avatar.backgroundColor = .red
+
+        avatar.widthAnchor.constraint(equalToConstant: initialsLabelSize).isActive = true
+        avatar.heightAnchor.constraint(equalToConstant: initialsLabelSize).isActive = true
+
         initialsLabel.backgroundColor = UIColor.green
 
         initialsLabel.layer.cornerRadius = initialsLabelCornerRadius
         initialsLabel.clipsToBounds = true
+        avatar.addSubview(initialsLabel)
+        contentView.addSubview(avatar)
+
+        initialsLabel.topAnchor.constraint(equalTo: avatar.topAnchor, constant: 3).isActive = true
+        initialsLabel.leadingAnchor.constraint(equalTo: avatar.leadingAnchor, constant: 3).isActive = true
+        initialsLabel.trailingAnchor.constraint(equalTo: avatar.trailingAnchor, constant: -3).isActive = true
 
-        contentView.addSubview(initialsLabel)
-        initialsLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: margin).isActive = true
-        initialsLabel.center = contentView.center
-        initialsLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: margin).isActive = true
-        initialsLabel.bottomAnchor.constraint(lessThanOrEqualTo: contentView.bottomAnchor, constant: -margin).isActive = true
+        avatar.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: margin).isActive = true
+        avatar.center.y = contentView.center.y
+        avatar.center.x = avatar.center.x + initialsLabelSize / 2
+        avatar.topAnchor.constraint(equalTo: contentView.topAnchor, constant: margin).isActive = true
+        avatar.bottomAnchor.constraint(lessThanOrEqualTo: contentView.bottomAnchor, constant: -margin).isActive = true
+        initialsLabel.center = avatar.center
 
         let myStackView = UIStackView()
         myStackView.translatesAutoresizingMaskIntoConstraints = false
         myStackView.clipsToBounds = true
 
         contentView.addSubview(myStackView)
-        myStackView.leadingAnchor.constraint(equalTo: initialsLabel.trailingAnchor, constant: margin).isActive = true
-        myStackView.centerYAnchor.constraint(equalTo: initialsLabel.centerYAnchor).isActive = true
+        myStackView.leadingAnchor.constraint(equalTo: avatar.trailingAnchor, constant: margin).isActive = true
+        myStackView.centerYAnchor.constraint(equalTo: avatar.centerYAnchor).isActive = true
         myStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -margin).isActive = true
         myStackView.axis = .vertical
         myStackView.addArrangedSubview(nameLabel)
@@ -66,16 +82,42 @@ class ContactCell: UITableViewCell {
         emailLabel.font = UIFont.systemFont(ofSize: 14)
         emailLabel.textColor = UIColor(hexString: "848ba7")
         emailLabel.lineBreakMode = .byTruncatingTail
+
+        let img = UIImage(named: "approval")!.withRenderingMode(.alwaysTemplate)
+        let imgSize: CGFloat = 25
+
+        imgView.isHidden = true
+        imgView.image = img
+        imgView.bounds = CGRect(
+            x: 0,
+            y: 0,
+            width: imgSize, height: imgSize
+        )
+        imgView.tintColor = Constants.primaryColor
+
+        avatar.addSubview(imgView)
+
+        imgView.center.x = avatar.center.x + (avatar.frame.width / 2) + imgSize - 5
+        imgView.center.y = avatar.center.y + (avatar.frame.height / 2) + imgSize - 5
+    }
+
+    func setVerified(isVerified: Bool) {
+        imgView.isHidden = !isVerified
     }
 
     func setImage(_ img: UIImage) {
         let attachment = NSTextAttachment()
         attachment.image = img
+
         initialsLabel.attributedText = NSAttributedString(attachment: attachment)
     }
 
     func setBackupImage(name: String, color: UIColor) {
-        initialsLabel.text = Utils.getInitials(inputName: name)
+        let text = Utils.getInitials(inputName: name)
+
+        initialsLabel.textAlignment = .center
+        initialsLabel.text = text
+
         setColor(color)
     }
 

+ 1 - 0
deltachat-ios/ContactProfileViewController.swift

@@ -114,6 +114,7 @@ class ContactProfileViewController: UITableViewController {
             } else {
                 contactCell.setBackupImage(name: contact.name, color: contact.color)
             }
+            contactCell.setVerified(isVerified: contact.isVerified)
 
             return contactCell
         }

+ 1 - 0
deltachat-ios/TopViews/ChatListController.swift

@@ -166,6 +166,7 @@ class ChatTableDataSource: NSObject, UITableViewDataSource {
         } else {
             cell.setBackupImage(name: chat.name, color: chat.color)
         }
+        cell.setVerified(isVerified: chat.isVerified)
 
         let result1 = summary.text1 ?? ""
         let result2 = summary.text2 ?? ""

+ 1 - 1
deltachat-ios/TopViews/ContactListController.swift

@@ -58,7 +58,7 @@ class ContactListController: UITableViewController {
         } else {
             cell.setBackupImage(name: contact.name, color: contact.color)
         }
-
+        cell.setVerified(isVerified: contact.isVerified)
         return cell
     }
 

+ 1 - 1
deltachat-ios/TopViews/ProfileViewController.swift

@@ -135,7 +135,7 @@ class ProfileViewController: UITableViewController {
             } else {
                 contactCell.setBackupImage(name: contact.name, color: contact.color)
             }
-
+            contactCell.setVerified(isVerified: contact.isVerified)
             return contactCell
         }
 

+ 5 - 2
deltachat-ios/Wrapper.swift

@@ -46,8 +46,7 @@ class MRContact {
             if path.isFileURL {
                 do {
                     let data = try Data(contentsOf: path)
-                    let image = UIImage(data: data)
-                    return image
+                    return UIImage(data: data)
                 } catch {
                     logger.warning("failed to load image: \(filename), \(error)")
                     return nil
@@ -200,6 +199,10 @@ class MRChat {
         return UIColor(netHex: Int(dc_chat_get_color(chatPointer)))
     }
 
+    var isVerified: Bool {
+        return dc_chat_is_verified(chatPointer) == 1
+    }
+
     lazy var profileImage: UIImage? = { [unowned self] in
         let file = dc_chat_get_profile_image(chatPointer)
         if let cFile = file {