Browse Source

Merge pull request #351 from deltachat/fix_edit_group_name

Fix edit group name
björn petersen 5 năm trước cách đây
mục cha
commit
954da21c60

+ 4 - 7
deltachat-ios/Controller/EditGroupViewController.swift

@@ -6,11 +6,7 @@ class EditGroupViewController: UITableViewController {
 
     private let chat: DcChat
 
-    lazy var groupNameCell: GroupLabelCell = {
-        let cell = GroupLabelCell(style: .default, reuseIdentifier: nil)
-        cell.onTextChanged = groupNameEdited(_:)
-        return cell
-    }()
+    var groupNameCell: GroupLabelCell
 
     lazy var doneButton: UIBarButtonItem = {
         let button = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(saveContactButtonPressed))
@@ -25,10 +21,11 @@ class EditGroupViewController: UITableViewController {
 
     init(chat: DcChat) {
         self.chat = chat
+        self.groupNameCell = GroupLabelCell(chat: chat)
         super.init(style: .grouped)
         groupNameCell.inputField.text = chat.name
-        groupNameCell.groupBadge.setName(chat.name)
-        groupNameCell.groupBadge.setColor(chat.color)
+        self.groupNameCell.onTextChanged = groupNameEdited(_:)
+        self.groupNameCell.selectionStyle = .none
     }
 
     required init?(coder aDecoder: NSCoder) {

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

@@ -77,6 +77,8 @@ class GroupChatDetailViewController: UIViewController {
         updateGroupMembers()
         chatDetailTable.reloadData() // to display updates
         editBarButtonItem.isEnabled = currentUser != nil
+        //update chat object, maybe chat name was edited
+        chat = DcChat(id: chat.id)
     }
 
     private func updateGroupMembers() {
@@ -114,7 +116,8 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
     func tableView(_: UITableView, viewForHeaderInSection section: Int) -> UIView? {
         if section == sectionConfig {
             let header = ContactDetailHeader()
-            header.updateDetails(title: chat.name, subtitle: String.localizedStringWithFormat(NSLocalizedString("n_members", comment: ""), chat.contactIds.count))
+            header.updateDetails(title: chat.name,
+                                 subtitle: String.localizedStringWithFormat(String.localized("n_members"), chat.contactIds.count))
             if let img = chat.profileImage {
                 header.setImage(img)
             } else {

+ 18 - 1
deltachat-ios/View/GroupNameCell.swift

@@ -23,6 +23,12 @@ class GroupLabelCell: UITableViewCell {
         return textField
     }()
 
+    init(chat: DcChat) {
+        super.init(style: .default, reuseIdentifier: nil)
+        setAvatar(for: chat)
+        setupSubviews()
+    }
+
     override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
         super.init(style: style, reuseIdentifier: reuseIdentifier)
         setupSubviews()
@@ -53,11 +59,22 @@ class GroupLabelCell: UITableViewCell {
 
     @objc func nameFieldChanged() {
         let groupName = inputField.text ?? ""
-        groupBadge.setName(groupName)
+        if groupBadge.showsInitials() {
+            groupBadge.setName(groupName)
+        }
         onTextChanged?(groupName)
     }
 
     func getGroupName() -> String {
         return inputField.text ?? ""
     }
+
+    func setAvatar(for chat: DcChat) {
+        if let image = chat.profileImage {
+            groupBadge = InitialsBadge(image: image, size: groupBadgeSize)
+        } else {
+            groupBadge =  InitialsBadge(name: chat.name, color: chat.color, size: groupBadgeSize)
+        }
+        groupBadge.setVerified(chat.isVerified)
+    }
 }

+ 8 - 0
deltachat-ios/View/InitialsBadge.swift

@@ -76,14 +76,22 @@ class InitialsBadge: UIView {
 
     func setName(_ name: String) {
         label.text = Utils.getInitials(inputName: name)
+        label.isHidden = false
+        imageView.isHidden = true
     }
 
     func setImage(_ image: UIImage) {
         if let resizedImg = image.resizeImage(targetSize: CGSize(width: self.frame.width, height: self.frame.height)) {
             self.imageView.image = resizedImg
+            self.imageView.isHidden = false
+            self.label.isHidden = true
         }
     }
 
+    func showsInitials() -> Bool {
+        return !label.isHidden
+    }
+
     func setColor(_ color: UIColor) {
         backgroundColor = color
     }