Эх сурвалжийг харах

let AvatarSelectionCell take a simple image parameter, don't make me think

B. Petersen 5 жил өмнө
parent
commit
4b0ec12644

+ 2 - 3
deltachat-ios/Controller/EditGroupViewController.swift

@@ -38,7 +38,7 @@ class EditGroupViewController: UITableViewController, MediaPickerDelegate {
     init(dcContext: DcContext, chat: DcChat) {
         self.dcContext = dcContext
         self.chat = chat
-        self.avatarSelectionCell = AvatarSelectionCell(chat: chat)
+        self.avatarSelectionCell = AvatarSelectionCell(image: chat.profileImage)
         super.init(style: .grouped)
         self.avatarSelectionCell.hintLabel.text = String.localized("group_avatar")
         self.avatarSelectionCell.onAvatarTapped = onAvatarTapped
@@ -86,7 +86,6 @@ class EditGroupViewController: UITableViewController, MediaPickerDelegate {
     }
 
     private func groupNameEdited(_ textField: UITextField) {
-        avatarSelectionCell.onInitialsChanged(text: textField.text)
         doneButton.isEnabled = true
     }
 
@@ -112,7 +111,7 @@ class EditGroupViewController: UITableViewController, MediaPickerDelegate {
         groupImage = image
         doneButton.isEnabled = true
 
-        avatarSelectionCell = AvatarSelectionCell(context: nil, with: groupImage)
+        avatarSelectionCell = AvatarSelectionCell(image: groupImage)
         avatarSelectionCell.hintLabel.text = String.localized("group_avatar")
         avatarSelectionCell.onAvatarTapped = onAvatarTapped
 

+ 1 - 1
deltachat-ios/Controller/EditSettingsController.swift

@@ -169,7 +169,7 @@ class EditSettingsController: UITableViewController, MediaPickerDelegate {
     }
 
     private func createPictureAndNameCell() -> AvatarSelectionCell {
-        let cell = AvatarSelectionCell(context: dcContext)
+        let cell = AvatarSelectionCell(image: dcContext.getSelfAvatarImage())
         return cell
     }
 

+ 2 - 2
deltachat-ios/Controller/NewGroupController.swift

@@ -39,7 +39,7 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
     }()
 
     lazy var avatarSelectionCell: AvatarSelectionCell = {
-        let cell = AvatarSelectionCell(context: nil)
+        let cell = AvatarSelectionCell(image: nil)
         cell.hintLabel.text = String.localized("group_avatar")
         cell.onAvatarTapped = onAvatarTapped
         return cell
@@ -301,7 +301,7 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
     func onImageSelected(image: UIImage) {
         groupImage = image
 
-        avatarSelectionCell = AvatarSelectionCell(context: nil, with: groupImage)
+        avatarSelectionCell = AvatarSelectionCell(image: groupImage)
         avatarSelectionCell.hintLabel.text = String.localized("group_avatar")
         avatarSelectionCell.onAvatarTapped = onAvatarTapped
 

+ 2 - 2
deltachat-ios/Controller/ProfileInfoViewController.swift

@@ -22,7 +22,7 @@ class ProfileInfoViewController: UITableViewController {
     }()
 
     private lazy var avatarCell: AvatarSelectionCell = {
-        let cell = AvatarSelectionCell(context: self.dcContext)
+        let cell = AvatarSelectionCell(image: dcContext.getSelfAvatarImage())
         cell.onAvatarTapped = avatarTapped
         return cell
     }()
@@ -76,7 +76,7 @@ class ProfileInfoViewController: UITableViewController {
     // MARK: - updates
     private func updateAvatarCell() {
         if let avatarImage = dcContext.getSelfAvatarImage() {
-            avatarCell.updateAvatar(image: avatarImage)
+            avatarCell.setAvatar(image: avatarImage)
         }
         self.tableView.beginUpdates()
         let indexPath = IndexPath(row: 1, section: 0)

+ 5 - 33
deltachat-ios/View/AvatarSelectionCell.swift

@@ -29,16 +29,9 @@ class AvatarSelectionCell: UITableViewCell {
         return label
     }()
 
-    init(chat: DcChat) {
+    init(image: UIImage?) {
         super.init(style: .default, reuseIdentifier: nil)
-        setAvatar(for: chat)
-        setupSubviews()
-    }
-
-    init(context: DcContext?, with defaultImage: UIImage? = nil) {
-        super.init(style: .default, reuseIdentifier: nil)
-        setAvatar(image: context?.getSelfAvatarImage(),
-                  with: defaultImage ?? self.defaultImage)
+        setAvatar(image: image)
         setupSubviews()
     }
 
@@ -69,12 +62,6 @@ class AvatarSelectionCell: UITableViewCell {
         selectionStyle = .none
     }
 
-    func onInitialsChanged(text: String?) {
-        if badge.showsInitials() {
-            badge.setName(text ?? "")
-        }
-    }
-
     @objc func onBadgeTouched(gesture: UILongPressGestureRecognizer) {
         switch gesture.state {
         case .began:
@@ -89,27 +76,12 @@ class AvatarSelectionCell: UITableViewCell {
         }
     }
 
-    // I think this is no good, we should rather update badge than overwriting it.
-    func setAvatar(for chat: DcChat) {
-        if let image = chat.profileImage {
-            badge = InitialsBadge(image: image, size: badgeSize)
-        } else {
-            badge = InitialsBadge(name: chat.name, color: chat.color, size: badgeSize)
-        }
-        badge.setVerified(chat.isVerified)
-    }
-
-    // I think this is no good, we should rather update badge than overwriting it.
-    func setAvatar(image: UIImage?, with defaultImage: UIImage?) {
+    func setAvatar(image: UIImage?) {
         if let image = image {
-            badge = InitialsBadge(image: image, size: badgeSize)
-        } else if let defaultImage = defaultImage {
+            badge.setImage(image)
+        } else {
             badge = InitialsBadge(image: defaultImage, size: badgeSize)
             badge.backgroundColor = DcColors.grayTextColor
         }
     }
-
-    func updateAvatar(image: UIImage) {
-        badge.setImage(image)
-    }
 }