Add image descriptions

This commit is contained in:
Shadowfacts 2018-08-31 12:39:39 -04:00
parent fc69b9684b
commit 3170b83b82
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 33 additions and 4 deletions

@ -1 +1 @@
Subproject commit b3653523af6b15fae5e3f8d425304c93d9bef9c7
Subproject commit cfece3083acfeda2f124a84dc35f268682681d49

View File

@ -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)
}
}

View File

@ -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)
}
}