|
@@ -1,10 +1,11 @@
|
|
|
import UIKit
|
|
|
|
|
|
-class EditGroupViewController: UITableViewController {
|
|
|
+class EditGroupViewController: UITableViewController, MediaPickerDelegate {
|
|
|
|
|
|
weak var coordinator: EditGroupCoordinator?
|
|
|
|
|
|
private let chat: DcChat
|
|
|
+ private var groupImage: UIImage?
|
|
|
|
|
|
private let rowAvatar = 0
|
|
|
private let rowGroupName = 1
|
|
@@ -34,6 +35,7 @@ class EditGroupViewController: UITableViewController {
|
|
|
self.avatarSelectionCell = AvatarSelectionCell(chat: chat)
|
|
|
super.init(style: .grouped)
|
|
|
self.avatarSelectionCell.hintLabel.text = String.localized("group_avatar")
|
|
|
+ self.avatarSelectionCell.onAvatarTapped = onAvatarTapped
|
|
|
title = String.localized("menu_edit_group")
|
|
|
}
|
|
|
|
|
@@ -72,6 +74,9 @@ class EditGroupViewController: UITableViewController {
|
|
|
|
|
|
@objc func saveContactButtonPressed() {
|
|
|
let newName = groupNameCell.getText()
|
|
|
+ if let groupImage = groupImage, let dcContext = coordinator?.dcContext {
|
|
|
+ AvatarHelper.saveChatAvatar(dcContext: dcContext, image: groupImage, for: Int(chat.id))
|
|
|
+ }
|
|
|
dc_set_chat_name(mailboxPointer, UInt32(chat.id), newName)
|
|
|
coordinator?.navigateBack()
|
|
|
}
|
|
@@ -84,4 +89,36 @@ class EditGroupViewController: UITableViewController {
|
|
|
avatarSelectionCell.onInitialsChanged(text: textField.text)
|
|
|
doneButton.isEnabled = true
|
|
|
}
|
|
|
+
|
|
|
+ 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(_:))
|
|
|
+ alert.addAction(photoAction)
|
|
|
+ alert.addAction(videoAction)
|
|
|
+ alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
+ self.present(alert, animated: true, completion: nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ private func galleryButtonPressed(_ action: UIAlertAction) {
|
|
|
+ coordinator?.showPhotoPicker(delegate: self)
|
|
|
+ }
|
|
|
+
|
|
|
+ private func cameraButtonPressed(_ action: UIAlertAction) {
|
|
|
+ coordinator?.showCamera(delegate: self)
|
|
|
+ }
|
|
|
+
|
|
|
+ func onImageSelected(image: UIImage) {
|
|
|
+ groupImage = image
|
|
|
+ doneButton.isEnabled = true
|
|
|
+
|
|
|
+ avatarSelectionCell = AvatarSelectionCell(context: nil, with: groupImage)
|
|
|
+ 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()
|
|
|
+ }
|
|
|
}
|