Respond to CR.

pull/2/head
Matthew Chen 7 years ago
parent 919e886eb7
commit 9be84fc912

@ -49,7 +49,7 @@ class AttachmentItemCollection {
attachmentItems = attachmentItems.filter { $0 != item } attachmentItems = attachmentItems.filter { $0 != item }
} }
func count() -> Int { var count: Int {
return attachmentItems.count return attachmentItems.count
} }
} }
@ -624,7 +624,7 @@ extension AttachmentApprovalViewController: AttachmentPrepViewControllerDelegate
} }
func prepViewControllerAttachmentCount() -> Int { func prepViewControllerAttachmentCount() -> Int {
return attachmentItemCollection.count() return attachmentItemCollection.count
} }
} }
@ -893,24 +893,52 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
// MARK: - Navigation Bar // MARK: - Navigation Bar
public func navigationBarItems() -> [UIView] { public func navigationBarItems() -> [UIView] {
let captionButton = navigationBarButton(imageName: "image_editor_caption",
selector: #selector(didTapCaption(sender:)))
guard let imageEditorView = imageEditorView else { guard let imageEditorView = imageEditorView else {
// Show the "add caption" button for non-image attachments if // Show the "add caption" button for non-image attachments if
// there is more than one attachment. // there is more than one attachment.
if let prepDelegate = prepDelegate, if let prepDelegate = prepDelegate,
prepDelegate.prepViewControllerAttachmentCount() > 1 { prepDelegate.prepViewControllerAttachmentCount() > 1 {
let captionButton = navigationBarButton(imageName: "image_editor_caption",
selector: #selector(didTapCaption(sender:)))
return [captionButton] return [captionButton]
} }
return [] return []
} }
return imageEditorView.navigationBarItems() var navigationBarItems = imageEditorView.navigationBarItems()
// Show the caption UI if there's more than one attachment
// OR if the attachment already has a caption.
var shouldShowCaptionUI = attachmentCount() > 0
if let captionText = attachmentItem.captionText, captionText.count > 0 {
shouldShowCaptionUI = true
}
if shouldShowCaptionUI {
navigationBarItems.append(captionButton)
}
return navigationBarItems
}
private func attachmentCount() -> Int {
guard let prepDelegate = prepDelegate else {
owsFailDebug("Missing prepDelegate.")
return 0
}
return prepDelegate.prepViewControllerAttachmentCount()
} }
@objc func didTapCaption(sender: UIButton) { @objc func didTapCaption(sender: UIButton) {
Logger.verbose("") Logger.verbose("")
imageEditorPresentCaptionView() presentCaptionView()
}
private func presentCaptionView() {
let view = AttachmentCaptionViewController(delegate: self, attachmentItem: attachmentItem)
self.imageEditor(presentFullScreenView: view, isTransparent: true)
isShowingCaptionView = true
} }
// MARK: - Event Handlers // MARK: - Event Handlers
@ -1175,24 +1203,9 @@ extension AttachmentPrepViewController: ImageEditorViewDelegate {
} }
} }
public func imageEditorPresentCaptionView() {
let view = AttachmentCaptionViewController(delegate: self, attachmentItem: attachmentItem)
self.imageEditor(presentFullScreenView: view, isTransparent: true)
isShowingCaptionView = true
}
public func imageEditorUpdateNavigationBar() { public func imageEditorUpdateNavigationBar() {
prepDelegate?.prepViewControllerUpdateNavigationBar() prepDelegate?.prepViewControllerUpdateNavigationBar()
} }
public func imageEditorAttachmentCount() -> Int {
guard let prepDelegate = prepDelegate else {
owsFailDebug("Missing prepDelegate.")
return 0
}
return prepDelegate.prepViewControllerAttachmentCount()
}
} }
// MARK: - // MARK: -

@ -8,9 +8,7 @@ import UIKit
public protocol ImageEditorViewDelegate: class { public protocol ImageEditorViewDelegate: class {
func imageEditor(presentFullScreenView viewController: UIViewController, func imageEditor(presentFullScreenView viewController: UIViewController,
isTransparent: Bool) isTransparent: Bool)
func imageEditorPresentCaptionView()
func imageEditorUpdateNavigationBar() func imageEditorUpdateNavigationBar()
func imageEditorAttachmentCount() -> Int
} }
// MARK: - // MARK: -
@ -100,8 +98,6 @@ public class ImageEditorView: UIView {
selector: #selector(didTapCrop(sender:))) selector: #selector(didTapCrop(sender:)))
let newTextButton = navigationBarButton(imageName: "image_editor_text", let newTextButton = navigationBarButton(imageName: "image_editor_text",
selector: #selector(didTapNewText(sender:))) selector: #selector(didTapNewText(sender:)))
let captionButton = navigationBarButton(imageName: "image_editor_caption",
selector: #selector(didTapCaption(sender:)))
var buttons: [UIView] var buttons: [UIView]
if model.canUndo() { if model.canUndo() {
@ -110,12 +106,6 @@ public class ImageEditorView: UIView {
buttons = [newTextButton, brushButton, cropButton] 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 return buttons
} }
@ -162,12 +152,6 @@ public class ImageEditorView: UIView {
edit(textItem: textItem) edit(textItem: textItem)
} }
@objc func didTapCaption(sender: UIButton) {
Logger.verbose("")
delegate?.imageEditorPresentCaptionView()
}
@objc func didTapDone(sender: UIButton) { @objc func didTapDone(sender: UIButton) {
Logger.verbose("") Logger.verbose("")
} }

Loading…
Cancel
Save