Show "add attachment caption" button for non-media attachments; only show if more than one attachment.

pull/2/head
Matthew Chen 6 years ago
parent 0813ebe16d
commit 7ee38f808d

@ -48,6 +48,10 @@ class AttachmentItemCollection {
func remove(item: SignalAttachmentItem) {
attachmentItems = attachmentItems.filter { $0 != item }
}
func count() -> Int {
return attachmentItems.count
}
}
// MARK: -
@ -618,6 +622,10 @@ extension AttachmentApprovalViewController: AttachmentPrepViewControllerDelegate
func prepViewControllerUpdateNavigationBar() {
self.updateNavigationBar()
}
func prepViewControllerAttachmentCount() -> Int {
return attachmentItemCollection.count()
}
}
// MARK: GalleryRail
@ -671,6 +679,8 @@ protocol AttachmentPrepViewControllerDelegate: class {
func prepViewController(_ prepViewController: AttachmentPrepViewController, didUpdateCaptionForAttachmentItem attachmentItem: SignalAttachmentItem)
func prepViewControllerUpdateNavigationBar()
func prepViewControllerAttachmentCount() -> Int
}
public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarDelegate, OWSVideoPlayerDelegate {
@ -884,11 +894,25 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
public func navigationBarItems() -> [UIView] {
guard let imageEditorView = imageEditorView else {
// Show the "add caption" button for non-image attachments if
// there is more than one attachment.
if let prepDelegate = prepDelegate,
prepDelegate.prepViewControllerAttachmentCount() > 1 {
let captionButton = navigationBarButton(imageName: "image_editor_caption",
selector: #selector(didTapCaption(sender:)))
return [captionButton]
}
return []
}
return imageEditorView.navigationBarItems()
}
@objc func didTapCaption(sender: UIButton) {
Logger.verbose("")
imageEditorPresentCaptionView()
}
// MARK: - Event Handlers
@objc
@ -1165,6 +1189,14 @@ extension AttachmentPrepViewController: ImageEditorViewDelegate {
public func imageEditorUpdateNavigationBar() {
prepDelegate?.prepViewControllerUpdateNavigationBar()
}
public func imageEditorAttachmentCount() -> Int {
guard let prepDelegate = prepDelegate else {
owsFailDebug("Missing prepDelegate.")
return 0
}
return prepDelegate.prepViewControllerAttachmentCount()
}
}
// MARK: -

@ -10,6 +10,7 @@ public protocol ImageEditorViewDelegate: class {
withNavigation: Bool)
func imageEditorPresentCaptionView()
func imageEditorUpdateNavigationBar()
func imageEditorAttachmentCount() -> Int
}
// MARK: -
@ -102,11 +103,20 @@ public class ImageEditorView: UIView {
let captionButton = navigationBarButton(imageName: "image_editor_caption",
selector: #selector(didTapCaption(sender:)))
var buttons: [UIView]
if model.canUndo() {
return [undoButton, newTextButton, brushButton, cropButton, captionButton]
buttons = [undoButton, newTextButton, brushButton, cropButton]
} else {
return [newTextButton, brushButton, cropButton, captionButton]
buttons = [newTextButton, brushButton, cropButton]
}
// Show the "add caption" button for non-image attachments if
// there is more than one attachment.
if let delegate = delegate,
delegate.imageEditorAttachmentCount() > 1 {
buttons.append(captionButton)
}
return buttons
}
// MARK: - Actions

Loading…
Cancel
Save