Forráskód Böngészése

show verified marker behind chat title

cyberta 2 éve
szülő
commit
6ae7096e65

+ 1 - 2
deltachat-ios/Chat/ChatViewController.swift

@@ -1031,7 +1031,7 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
                 subtitle = dcContext.getContact(id: chatContactIds[0]).email
             }
 
-            titleView.updateTitleView(title: dcChat.name, subtitle: subtitle)
+            titleView.updateTitleView(title: dcChat.name, subtitle: subtitle, isVerified: dcChat.isProtected)
             navigationItem.titleView = titleView
             self.navigationItem.setLeftBarButton(nil, animated: true)
         }
@@ -1042,7 +1042,6 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
             initialsBadge.setName(dcChat.name)
             initialsBadge.setColor(dcChat.color)
         }
-        initialsBadge.setVerified(dcChat.isProtected)
 
         let recentlySeen = DcUtils.showRecentlySeen(context: dcContext, chat: dcChat)
         initialsBadge.setRecentlySeen(recentlySeen)

+ 34 - 14
deltachat-ios/View/ChatTitleView.swift

@@ -3,15 +3,35 @@ import DcCore
 
 class ChatTitleView: UIView {
 
-    private var titleLabel: UILabel = {
+    private lazy var titleLabel: UILabel = {
         let titleLabel = UILabel()
         titleLabel.translatesAutoresizingMaskIntoConstraints = false
         titleLabel.backgroundColor = UIColor.clear
         titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
         titleLabel.textAlignment = .center
+        titleLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal)
         return titleLabel
     }()
 
+    private lazy var verifiedView: UIImageView = {
+        let imgView = UIImageView()
+        let img = UIImage(named: "verified")?.scaleDownImage(toMax: 18)
+        imgView.isHidden = true
+        imgView.image = img
+        imgView.translatesAutoresizingMaskIntoConstraints = false
+        imgView.setContentCompressionResistancePriority(.required, for: .horizontal)
+        return imgView
+    }()
+
+    private lazy var titleContainer: UIStackView = {
+        let stackView = UIStackView(arrangedSubviews: [titleLabel, verifiedView])
+        stackView.axis = .horizontal
+        stackView.alignment = .firstBaseline
+        stackView.spacing = 3
+        stackView.translatesAutoresizingMaskIntoConstraints = false
+        return stackView
+    }()
+
     private var subtitleLabel: UILabel = {
         let subtitleLabel = UILabel()
         subtitleLabel.translatesAutoresizingMaskIntoConstraints = false
@@ -37,30 +57,30 @@ class ChatTitleView: UIView {
         let containerView = UIView()
         containerView.translatesAutoresizingMaskIntoConstraints = false
         addSubview(containerView)
+        containerView.addSubview(titleContainer)
+        containerView.addSubview(subtitleLabel)
 
         addConstraints([ containerView.constraintAlignTopTo(self),
                          containerView.constraintAlignBottomTo(self),
                          containerView.constraintCenterXTo(self),
                          containerView.constraintAlignLeadingTo(self),
-                         containerView.constraintAlignTrailingTo(self)
+                         containerView.constraintAlignTrailingTo(self),
+                         titleContainer.constraintAlignLeadingTo(containerView),
+                         titleContainer.constraintAlignTrailingTo(containerView),
+                         titleContainer.constraintAlignTopTo(containerView),
+                         subtitleLabel.constraintToBottomOf(titleContainer),
+                         subtitleLabel.constraintAlignLeadingTo(containerView),
+                         subtitleLabel.constraintAlignTrailingTo(containerView),
+                         subtitleLabel.constraintAlignBottomTo(containerView),
+                         verifiedView.widthAnchor.constraint(equalTo: verifiedView.heightAnchor)
         ])
-
-        containerView.addSubview(titleLabel)
-        containerView.addConstraints([ titleLabel.constraintAlignLeadingTo(containerView),
-                                       titleLabel.constraintAlignTrailingTo(containerView),
-                                       titleLabel.constraintAlignTopTo(containerView) ])
-
-        containerView.addSubview(subtitleLabel)
-        containerView.addConstraints([ subtitleLabel.constraintToBottomOf(titleLabel),
-                                       subtitleLabel.constraintAlignLeadingTo(containerView),
-                                       subtitleLabel.constraintAlignTrailingTo(containerView),
-                                       subtitleLabel.constraintAlignBottomTo(containerView)])
     }
 
-    func updateTitleView(title: String, subtitle: String?, baseColor: UIColor = DcColors.defaultTextColor) {
+    func updateTitleView(title: String, subtitle: String?, baseColor: UIColor = DcColors.defaultTextColor, isVerified: Bool) {
         subtitleLabel.textColor = baseColor.withAlphaComponent(0.95)
         titleLabel.textColor = baseColor
         titleLabel.text = title
         subtitleLabel.text = subtitle
+        verifiedView.isHidden = !isVerified
     }
 }