|
@@ -4,7 +4,9 @@ import DcCore
|
|
|
class EditGroupViewController: UITableViewController, MediaPickerDelegate {
|
|
|
private let dcContext: DcContext
|
|
|
private let chat: DcChat
|
|
|
- private var groupImage: UIImage?
|
|
|
+
|
|
|
+ private var changeGroupImage: UIImage?
|
|
|
+ private var deleteGroupImage: Bool = false
|
|
|
|
|
|
private let rowGroupName = 0
|
|
|
private let rowAvatar = 1
|
|
@@ -74,8 +76,10 @@ class EditGroupViewController: UITableViewController, MediaPickerDelegate {
|
|
|
|
|
|
@objc func saveContactButtonPressed() {
|
|
|
let newName = groupNameCell.getText()
|
|
|
- if let groupImage = groupImage {
|
|
|
- AvatarHelper.saveChatAvatar(dcContext: dcContext, image: groupImage, for: Int(chat.id))
|
|
|
+ if let groupImage = changeGroupImage {
|
|
|
+ AvatarHelper.saveChatAvatar(dcContext: dcContext, image: groupImage, for: chat.id)
|
|
|
+ } else if deleteGroupImage {
|
|
|
+ AvatarHelper.saveChatAvatar(dcContext: dcContext, image: nil, for: chat.id)
|
|
|
}
|
|
|
_ = dcContext.setChatName(chatId: chat.id, name: newName ?? "")
|
|
|
navigationController?.popViewController(animated: true)
|
|
@@ -93,8 +97,12 @@ class EditGroupViewController: UITableViewController, MediaPickerDelegate {
|
|
|
let alert = UIAlertController(title: String.localized("group_avatar"), message: nil, preferredStyle: .safeActionSheet)
|
|
|
let cameraAction = PhotoPickerAlertAction(title: String.localized("camera"), style: .default, handler: cameraButtonPressed(_:))
|
|
|
let galleryAction = PhotoPickerAlertAction(title: String.localized("gallery"), style: .default, handler: galleryButtonPressed(_:))
|
|
|
+ let deleteAction = UIAlertAction(title: String.localized("delete"), style: .destructive, handler: deleteGroupAvatarPressed(_:))
|
|
|
alert.addAction(cameraAction)
|
|
|
alert.addAction(galleryAction)
|
|
|
+ if avatarSelectionCell.isAvatarSet() {
|
|
|
+ alert.addAction(deleteAction)
|
|
|
+ }
|
|
|
alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
self.present(alert, animated: true, completion: nil)
|
|
|
}
|
|
@@ -107,11 +115,22 @@ class EditGroupViewController: UITableViewController, MediaPickerDelegate {
|
|
|
mediaPicker?.showCamera(allowCropping: true, supportedMediaTypes: .photo)
|
|
|
}
|
|
|
|
|
|
+ private func deleteGroupAvatarPressed(_ action: UIAlertAction) {
|
|
|
+ changeGroupImage = nil
|
|
|
+ deleteGroupImage = true
|
|
|
+ doneButton.isEnabled = true
|
|
|
+ updateAvatarRow(image: nil)
|
|
|
+ }
|
|
|
+
|
|
|
func onImageSelected(image: UIImage) {
|
|
|
- groupImage = image
|
|
|
+ changeGroupImage = image
|
|
|
+ deleteGroupImage = false
|
|
|
doneButton.isEnabled = true
|
|
|
+ updateAvatarRow(image: changeGroupImage)
|
|
|
+ }
|
|
|
|
|
|
- avatarSelectionCell = AvatarSelectionCell(image: groupImage)
|
|
|
+ func updateAvatarRow(image: UIImage?) {
|
|
|
+ avatarSelectionCell = AvatarSelectionCell(image: image)
|
|
|
avatarSelectionCell.hintLabel.text = String.localized("group_avatar")
|
|
|
avatarSelectionCell.onAvatarTapped = onAvatarTapped
|
|
|
|