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

Merge pull request #449 from deltachat/user_avatar_fixes

fix user avatar issues
björn petersen 5 éve
szülő
commit
3594b9ff16

+ 13 - 11
deltachat-ios/Controller/ChatViewController.swift

@@ -129,16 +129,6 @@ class ChatViewController: MessagesViewController {
         let chat = DcChat(id: chatId)
         if showCustomNavBar {
             updateTitle(chat: chat)
-
-            let badge: InitialsBadge
-            if let image = chat.profileImage {
-                badge =  InitialsBadge(image: image, size: 28)
-            } else {
-                badge =  InitialsBadge(name: chat.name, color: chat.color, size: 28)
-            }
-            badge.setVerified(chat.isVerified)
-            badge.accessibilityTraits = .button
-            navigationItem.rightBarButtonItem = UIBarButtonItem(customView: badge)
         }
 
         configureMessageMenu()
@@ -161,7 +151,7 @@ class ChatViewController: MessagesViewController {
                         self.refreshMessages()
                     }
                 }
-                if (self.showCustomNavBar) {
+                if self.showCustomNavBar {
                     self.updateTitle(chat: chat)
                 }
             }
@@ -234,8 +224,20 @@ class ChatViewController: MessagesViewController {
                 subtitle = DcContact(id: chatContactIds[0]).email
             }
         }
+        
         titleView.updateTitleView(title: chat.name, subtitle: subtitle)
         navigationItem.titleView = titleView
+
+        let badge: InitialsBadge
+        if let image = chat.profileImage {
+            badge =  InitialsBadge(image: image, size: 28)
+        } else {
+            badge =  InitialsBadge(name: chat.name, color: chat.color, size: 28)
+            badge.setLabelFont(UIFont.systemFont(ofSize: 14))
+        }
+        badge.setVerified(chat.isVerified)
+        badge.accessibilityTraits = .button
+        navigationItem.rightBarButtonItem = UIBarButtonItem(customView: badge)
     }
 
     @objc

+ 4 - 7
deltachat-ios/Helper/Utils.swift

@@ -16,14 +16,11 @@ struct Utils {
     }
 
     static func getInitials(inputName: String) -> String {
-        var nameParts = inputName.split(separator: " ")
-        // this limits initials to max 2, otherwise just takes first letter to avoid messy badges
-        if nameParts.count > 2 {
-            nameParts = [nameParts[0]]
+        if let firstLetter = inputName.first {
+            return firstLetter.uppercased()
+        } else {
+            return ""
         }
-        let initials: [Character] = nameParts.compactMap { part in part.capitalized.first }
-        let initialsString: String = String(initials)
-        return initialsString
     }
 
     static func copyAndFreeArray(inputArray: OpaquePointer?) -> [Int] {

+ 1 - 2
deltachat-ios/View/ContactCell.swift

@@ -128,9 +128,8 @@ class ContactCell: UITableViewCell {
     }
 
     func setBackupImage(name: String, color: UIColor) {
-        let text = Utils.getInitials(inputName: name)
         avatar.setColor(color)
-        avatar.setName(text)
+        avatar.setName(name)
     }
 
     func setUnreadMessageCounter(_ count: Int) {

+ 5 - 1
deltachat-ios/View/InitialsBadge.swift

@@ -7,7 +7,7 @@ class InitialsBadge: UIView {
 
     private var label: UILabel = {
         let label = UILabel()
-        label.adjustsFontSizeToFitWidth = true
+        label.font = UIFont.systemFont(ofSize: 26)
         label.textAlignment = NSTextAlignment.center
         label.textColor = UIColor.white
         label.translatesAutoresizingMaskIntoConstraints = false
@@ -86,6 +86,10 @@ class InitialsBadge: UIView {
         accessibilityLabel = "avatar \(name)"
     }
 
+    func setLabelFont(_ font: UIFont) {
+        label.font = font
+    }
+
     func setImage(_ image: UIImage, downscale: CGFloat? = nil) {
         var scale = downscale ?? 1
         if scale > 1 {