Browse Source

Merge pull request #445 from deltachat/delete_profile_image

add option to delete avatar image (and fix code formatting) #433
björn petersen 5 years ago
parent
commit
d917c4db84
1 changed files with 23 additions and 12 deletions
  1. 23 12
      deltachat-ios/Controller/EditSettingsController.swift

+ 23 - 12
deltachat-ios/Controller/EditSettingsController.swift

@@ -140,30 +140,41 @@ class EditSettingsController: UITableViewController, MediaPickerDelegate {
         }
     }
 
-
-      private func galleryButtonPressed(_ action: UIAlertAction) {
+    private func galleryButtonPressed(_ action: UIAlertAction) {
         coordinator?.showPhotoPicker(delegate: self)
-      }
+    }
 
-      private func cameraButtonPressed(_ action: UIAlertAction) {
+    private func cameraButtonPressed(_ action: UIAlertAction) {
         coordinator?.showCamera(delegate: self)
-      }
+    }
 
-    private func onAvatarTapped() {
-        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
-                 let photoAction = PhotoPickerAlertAction(title: String.localized("gallery"), style: .default, handler: galleryButtonPressed(_:))
-                 let videoAction = PhotoPickerAlertAction(title: String.localized("camera"), style: .default, handler: cameraButtonPressed(_:))
+    private func deleteProfileIconPressed(_ action: UIAlertAction) {
+        DcConfig.selfavatar = nil
+        updateAvatarAndNameCell()
+    }
 
-                 alert.addAction(photoAction)
-                 alert.addAction(videoAction)
-                 alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
+    private func onAvatarTapped() {
+        let alert = UIAlertController(title: String.localized("pref_profile_photo"), message: nil, preferredStyle: .actionSheet)
+        let photoAction = PhotoPickerAlertAction(title: String.localized("gallery"), style: .default, handler: galleryButtonPressed(_:))
+        let videoAction = PhotoPickerAlertAction(title: String.localized("camera"), style: .default, handler: cameraButtonPressed(_:))
+        let deleteAction = UIAlertAction(title: String.localized("delete"), style: .destructive, handler: deleteProfileIconPressed(_:))
+
+        alert.addAction(photoAction)
+        alert.addAction(videoAction)
+        if dcContext.getSelfAvatarImage() != nil {
+            alert.addAction(deleteAction)
+        }
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
 
         self.present(alert, animated: true, completion: nil)
     }
 
     func onImageSelected(image: UIImage) {
         AvatarHelper.saveSelfAvatarImage(image: image)
+        updateAvatarAndNameCell()
+    }
 
+    private func updateAvatarAndNameCell() {
         self.avatarSelectionCell = createPictureAndNameCell()
         self.avatarSelectionCell.onAvatarTapped = onAvatarTapped