Selaa lähdekoodia

Merge pull request #311 from deltachat/verified_group_icn

Verified icons
björn petersen 5 vuotta sitten
vanhempi
commit
a7012df66c

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

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

BIN
deltachat-ios/Assets.xcassets/verified.imageset/verified@1x.png


BIN
deltachat-ios/Assets.xcassets/verified.imageset/verified@2x.png


BIN
deltachat-ios/Assets.xcassets/verified.imageset/verified@3x.png


+ 1 - 0
deltachat-ios/Controller/ChatViewController.swift

@@ -91,6 +91,7 @@ class ChatViewController: MessagesViewController {
             } else {
                 badge =  InitialsBadge(name: chat.name, color: chat.color, size: 28)
             }
+            badge.setVerified(chat.isVerified)
             navigationItem.rightBarButtonItem = UIBarButtonItem(customView: badge)
         }
 

+ 1 - 0
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -185,6 +185,7 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
                     contactCell.emailLabel.text = contact.email
                     contactCell.initialsLabel.text = Utils.getInitials(inputName: displayName)
                     contactCell.setColor(contact.color)
+                    contactCell.setVerified(isVerified: chat.isVerified)
                 }
                 return cell
             }

+ 4 - 6
deltachat-ios/View/ContactCell.swift

@@ -22,7 +22,7 @@ class ContactCell: UITableViewCell {
     weak var delegate: ContactCellDelegate?
     var rowIndex = -1
     private let initialsLabelSize: CGFloat = 54
-    private let imgSize: CGFloat = 25
+    private let imgSize: CGFloat = 20
 
     let avatar: UIView = {
         let avatar = UIView()
@@ -31,7 +31,7 @@ class ContactCell: UITableViewCell {
 
     lazy var imgView: UIImageView = {
         let imgView = UIImageView()
-        let img = UIImage(named: "approval")!.withRenderingMode(.alwaysTemplate)
+        let img = UIImage(named: "verified")
         imgView.isHidden = true
         imgView.image = img
         imgView.bounds = CGRect(
@@ -158,12 +158,10 @@ class ContactCell: UITableViewCell {
         myStackView.addArrangedSubview(toplineStackView)
         myStackView.addArrangedSubview(bottomLineStackView)
 
-        imgView.tintColor = DcColors.primary
-
         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
+        imgView.center.x = avatar.center.x + (avatar.frame.width / 2) + imgSize
+        imgView.center.y = avatar.center.y + (avatar.frame.height / 2) + imgSize
 
         if delegate != nil {
             let tap = UITapGestureRecognizer(target: self, action: #selector(onAvatarTapped))

+ 41 - 9
deltachat-ios/View/InitialsBadge.swift

@@ -2,14 +2,33 @@ import UIKit
 
 class InitialsBadge: UIView {
 
+    private let verificationViewPadding = CGFloat(2)
+
     private var label: UILabel = {
         let label = UILabel()
         label.adjustsFontSizeToFitWidth = true
         label.textAlignment = NSTextAlignment.center
         label.textColor = UIColor.white
+        label.translatesAutoresizingMaskIntoConstraints = false
         return label
     }()
 
+    private var verifiedView: UIImageView = {
+           let imgView = UIImageView()
+           let img = UIImage(named: "verified")
+           imgView.isHidden = true
+           imgView.image = img
+           imgView.translatesAutoresizingMaskIntoConstraints = false
+           return imgView
+    }()
+
+    private var imageView: UIImageView = {
+        let imageViewContainer = UIImageView()
+        imageViewContainer.clipsToBounds = true
+        imageViewContainer.translatesAutoresizingMaskIntoConstraints = false
+        return imageViewContainer
+    }()
+
     convenience init(name: String, color: UIColor, size: CGFloat) {
         self.init(size: size)
         setName(name)
@@ -23,21 +42,32 @@ class InitialsBadge: UIView {
 
     init(size: CGFloat) {
         super.init(frame: CGRect(x: 0, y: 0, width: size, height: size))
-        let initialsLabelCornerRadius = size / 2
-        layer.cornerRadius = initialsLabelCornerRadius
+        let radius = size / 2
+        layer.cornerRadius = radius
         translatesAutoresizingMaskIntoConstraints = false
         heightAnchor.constraint(equalToConstant: size).isActive = true
         widthAnchor.constraint(equalToConstant: size).isActive = true
-        clipsToBounds = true
-        setupSubviews()
+        setupSubviews(with: radius)
     }
 
-    private func setupSubviews() {
+    private func setupSubviews(with radius: CGFloat) {
+        addSubview(imageView)
+        imageView.layer.cornerRadius = radius
+        imageView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
+        imageView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
+        imageView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
+
         addSubview(label)
-        label.translatesAutoresizingMaskIntoConstraints = false
         label.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
         label.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
         label.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
+
+        addSubview(verifiedView)
+        let imgViewConstraints = [verifiedView.constraintAlignBottomTo(self, paddingBottom: -verificationViewPadding),
+                                  verifiedView.constraintAlignTrailingTo(self, paddingTrailing: -verificationViewPadding),
+                                  verifiedView.constraintAlignTopTo(self, paddingTop: radius + verificationViewPadding),
+                                  verifiedView.constraintAlignLeadingTo(self, paddingLeading: radius + verificationViewPadding)]
+        addConstraints(imgViewConstraints)
     }
 
     required init?(coder _: NSCoder) {
@@ -50,13 +80,15 @@ class InitialsBadge: UIView {
 
     func setImage(_ image: UIImage) {
         if let resizedImg = image.resizeImage(targetSize: CGSize(width: self.frame.width, height: self.frame.height)) {
-            let attachment = NSTextAttachment()
-            attachment.image = resizedImg
-            label.attributedText = NSAttributedString(attachment: attachment)
+            self.imageView.image = resizedImg
         }
     }
 
     func setColor(_ color: UIColor) {
         backgroundColor = color
     }
+
+    func setVerified(_ verified: Bool) {
+        verifiedView.isHidden = !verified
+    }
 }