Sfoglia il codice sorgente

improve updating of AvatarSelectionCells - no need to manually update corresponding table row anymore

cyberta 5 anni fa
parent
commit
b57d72c903

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

@@ -116,24 +116,13 @@ class EditGroupViewController: UITableViewController, MediaPickerDelegate {
         changeGroupImage = nil
         deleteGroupImage = true
         doneButton.isEnabled = true
-        updateAvatarRow(image: nil)
+        avatarSelectionCell.setAvatar(image: nil)
     }
 
     func onImageSelected(image: UIImage) {
         changeGroupImage = image
         deleteGroupImage = false
         doneButton.isEnabled = true
-        updateAvatarRow(image: changeGroupImage)
-    }
-
-    func updateAvatarRow(image: UIImage?) {
-        avatarSelectionCell = AvatarSelectionCell(image: image)
-        avatarSelectionCell.hintLabel.text = String.localized("group_avatar")
-        avatarSelectionCell.onAvatarTapped = onAvatarTapped
-
-        self.tableView.beginUpdates()
-        let indexPath = IndexPath(row: rowAvatar, section: 0)
-        self.tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
-        self.tableView.endUpdates()
+        avatarSelectionCell.setAvatar(image: changeGroupImage)
     }
 }

+ 9 - 14
deltachat-ios/Controller/EditSettingsController.swift

@@ -42,7 +42,7 @@ class EditSettingsController: UITableViewController, MediaPickerDelegate {
     }()
 
     private lazy var avatarSelectionCell: AvatarSelectionCell = {
-        return createPictureAndNameCell()
+        return AvatarSelectionCell(image: dcContext.getSelfAvatarImage())
     }()
 
     private lazy var nameCell: TextFieldCell = {
@@ -134,7 +134,7 @@ class EditSettingsController: UITableViewController, MediaPickerDelegate {
 
     private func deleteProfileIconPressed(_ action: UIAlertAction) {
         dcContext.selfavatar = nil
-        updateAvatarAndNameCell()
+        updateAvatarCell()
     }
 
     private func onAvatarTapped() {
@@ -151,22 +151,17 @@ class EditSettingsController: UITableViewController, MediaPickerDelegate {
 
     func onImageSelected(image: UIImage) {
         AvatarHelper.saveSelfAvatarImage(dcContext: dcContext, image: image)
-        updateAvatarAndNameCell()
+        updateAvatarCell()
     }
 
-    private func updateAvatarAndNameCell() {
-        self.avatarSelectionCell = createPictureAndNameCell()
-        self.avatarSelectionCell.onAvatarTapped = onAvatarTapped
-
-        self.tableView.beginUpdates()
-        let indexPath = IndexPath(row: section1Avatar, section: section1)
-        self.tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
-        self.tableView.endUpdates()
+    private func updateAvatarCell() {
+        self.avatarSelectionCell.setAvatar(image: dcContext.getSelfAvatarImage())
     }
 
-    private func createPictureAndNameCell() -> AvatarSelectionCell {
-        let cell = AvatarSelectionCell(image: dcContext.getSelfAvatarImage())
-        return cell
+    private func updateCells() {
+        updateAvatarCell()
+        statusCell.setText(text: dcContext.selfstatus)
+        nameCell.setText(text: dcContext.displayname)
     }
 
 }

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

@@ -307,24 +307,13 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
     private func deleteGroupAvatarPressed(_ action: UIAlertAction) {
         changeGroupImage = nil
         deleteGroupImage = true
-        updateAvatarRow(image: nil)
+        avatarSelectionCell.setAvatar(image: nil)
     }
 
     func onImageSelected(image: UIImage) {
         changeGroupImage = image
         deleteGroupImage = false
-        updateAvatarRow(image: changeGroupImage)
-    }
-
-    func updateAvatarRow(image: UIImage?) {
-        avatarSelectionCell = AvatarSelectionCell(image: image)
-        avatarSelectionCell.hintLabel.text = String.localized("group_avatar")
-        avatarSelectionCell.onAvatarTapped = onAvatarTapped
-
-        self.tableView.beginUpdates()
-        let indexPath = IndexPath(row: sectionGroupDetailsRowAvatar, section: sectionGroupDetails)
-        self.tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
-        self.tableView.endUpdates()
+        avatarSelectionCell.setAvatar(image: changeGroupImage)
     }
 
     func updateGroupContactIdsOnQRCodeInvite() {

+ 0 - 4
deltachat-ios/Controller/ProfileInfoViewController.swift

@@ -78,10 +78,6 @@ class ProfileInfoViewController: UITableViewController {
         if let avatarImage = dcContext.getSelfAvatarImage() {
             avatarCell.setAvatar(image: avatarImage)
         }
-        self.tableView.beginUpdates()
-        let indexPath = IndexPath(row: 1, section: 0)
-        self.tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
-        self.tableView.endUpdates()
     }
 
     // MARK: - actions

+ 1 - 1
deltachat-ios/View/AvatarSelectionCell.swift

@@ -88,7 +88,7 @@ class AvatarSelectionCell: UITableViewCell {
             badge.setImage(image)
             avatarSet = true
         } else {
-            badge = InitialsBadge(image: defaultImage, size: badgeSize)
+            badge.setImage(defaultImage)
             badge.backgroundColor = DcColors.grayTextColor
             avatarSet = false
         }