Add image descriptions
This commit is contained in:
parent
3f8e86905e
commit
ce68e0164f
|
@ -1 +1 @@
|
|||
Subproject commit b3653523af6b15fae5e3f8d425304c93d9bef9c7
|
||||
Subproject commit cfece3083acfeda2f124a84dc35f268682681d49
|
|
@ -98,6 +98,7 @@ class ComposeViewController: UIViewController {
|
|||
|
||||
func addMedia(for image: UIImage) {
|
||||
let mediaView = ComposeMediaView(image: image)
|
||||
mediaView.delegate = self
|
||||
mediaStackView.addArrangedSubview(mediaView)
|
||||
}
|
||||
|
||||
|
@ -184,13 +185,13 @@ class ComposeViewController: UIViewController {
|
|||
var attachments: [Attachment?] = []
|
||||
let group = DispatchGroup()
|
||||
for view in mediaStackView.arrangedSubviews {
|
||||
guard let imageView = view as? UIImageView,
|
||||
let image = imageView.image,
|
||||
guard let mediaView = view as? ComposeMediaView,
|
||||
let image = mediaView.image,
|
||||
let data = image.pngData() else { continue }
|
||||
let index = attachments.count
|
||||
attachments.append(nil)
|
||||
group.enter()
|
||||
let req = Media.upload(media: .png(data))
|
||||
let req = Media.upload(media: .png(data), description: mediaView.mediaDescription)
|
||||
MastodonController.shared.client.run(req) { result in
|
||||
guard case let .success(attachment, _) = result else { fatalError() }
|
||||
attachments[index] = attachment
|
||||
|
@ -243,3 +244,18 @@ extension ComposeViewController: UIImagePickerControllerDelegate, UINavigationCo
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ComposeViewController: ComposeMediaViewDelegate {
|
||||
func editDescription(for media: ComposeMediaView) {
|
||||
let alertController = UIAlertController(title: "Media Description", message: nil, preferredStyle: .alert)
|
||||
alertController.addTextField { textField in
|
||||
textField.text = media.mediaDescription
|
||||
}
|
||||
alertController.addAction(UIAlertAction(title: "Confirm", style: .default, handler: { _ in
|
||||
let description = alertController.textFields![0].text
|
||||
media.mediaDescription = description
|
||||
}))
|
||||
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
|
||||
present(alertController, animated: true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,18 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
protocol ComposeMediaViewDelegate {
|
||||
func editDescription(for media: ComposeMediaView)
|
||||
}
|
||||
|
||||
class ComposeMediaView: UIImageView {
|
||||
|
||||
var delegate: ComposeMediaViewDelegate?
|
||||
|
||||
var remove: UIImageView
|
||||
|
||||
var mediaDescription: String?
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
return nil
|
||||
}
|
||||
|
@ -25,6 +33,7 @@ class ComposeMediaView: UIImageView {
|
|||
layer.cornerRadius = 5
|
||||
layer.masksToBounds = true
|
||||
isUserInteractionEnabled = true
|
||||
addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(longPressed)))
|
||||
|
||||
remove.isUserInteractionEnabled = true
|
||||
remove.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(removePressed)))
|
||||
|
@ -41,4 +50,8 @@ class ComposeMediaView: UIImageView {
|
|||
removeFromSuperview()
|
||||
}
|
||||
|
||||
@objc func longPressed() {
|
||||
delegate?.editDescription(for: self)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue