From 7ee38f808d358598a0555eff3d558424b0960996 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 28 Feb 2019 16:42:08 -0500 Subject: [PATCH] Show "add attachment caption" button for non-media attachments; only show if more than one attachment. --- .../AttachmentApprovalViewController.swift | 32 +++++++++++++++++++ .../Views/ImageEditor/ImageEditorView.swift | 14 ++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift b/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift index 776aa4295..4221b49f3 100644 --- a/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift +++ b/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift @@ -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: - diff --git a/SignalMessaging/Views/ImageEditor/ImageEditorView.swift b/SignalMessaging/Views/ImageEditor/ImageEditorView.swift index 0e9286845..3638d5d96 100644 --- a/SignalMessaging/Views/ImageEditor/ImageEditorView.swift +++ b/SignalMessaging/Views/ImageEditor/ImageEditorView.swift @@ -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