Prepopulate caption field with URL.

pull/1/head
Matthew Chen 8 years ago
parent 9c4ce3d304
commit 085975ebe9

@ -129,7 +129,9 @@ public class AttachmentApprovalViewController: OWSViewController, CaptioningTool
scrollView.autoPinEdgesToSuperviewEdges() scrollView.autoPinEdgesToSuperviewEdges()
let backgroundColor = UIColor.black let defaultCaption = self.defaultCaption()
let isUrlShare = defaultCaption != nil
let backgroundColor = isUrlShare ? UIColor.ows_signalBrandBlue : UIColor.black
self.view.backgroundColor = backgroundColor self.view.backgroundColor = backgroundColor
// Create full screen container view so the scrollView // Create full screen container view so the scrollView
@ -168,9 +170,7 @@ public class AttachmentApprovalViewController: OWSViewController, CaptioningTool
topToolbar.items = [cancelButton] topToolbar.items = [cancelButton]
// Bottom Toolbar // Bottom Toolbar
// let captioningToolbar = CaptioningToolbar(defaultCaption:defaultCaption)
// Don't add a caption to text messages.
let captioningToolbar = CaptioningToolbar(allowCaptions:!self.attachment.isOversizeText)
captioningToolbar.captioningToolbarDelegate = self captioningToolbar.captioningToolbarDelegate = self
self.bottomToolbar = captioningToolbar self.bottomToolbar = captioningToolbar
@ -236,6 +236,18 @@ public class AttachmentApprovalViewController: OWSViewController, CaptioningTool
self.pauseVideo() self.pauseVideo()
} }
private func defaultCaption() -> String? {
guard self.attachment.isUrl else {
return nil
}
let data = self.attachment.data
guard let messageText = String(data: data, encoding: String.Encoding.utf8) else {
Logger.error("\(self.logTag) Couldn't load url strubg")
return nil
}
return messageText
}
override public var inputAccessoryView: UIView? { override public var inputAccessoryView: UIView? {
self.bottomToolbar.layoutIfNeeded() self.bottomToolbar.layoutIfNeeded()
return self.bottomToolbar return self.bottomToolbar
@ -559,7 +571,6 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
private let sendButton: UIButton private let sendButton: UIButton
private let textView: UITextView private let textView: UITextView
private let bottomGradient: GradientView private let bottomGradient: GradientView
private let allowCaptions: Bool
// Layout Constants // Layout Constants
var maxTextViewHeight: CGFloat { var maxTextViewHeight: CGFloat {
@ -590,12 +601,11 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
} }
let kSendButtonShadowOffset: CGFloat = 1 let kSendButtonShadowOffset: CGFloat = 1
init(allowCaptions: Bool) { init(defaultCaption: String?) {
self.sendButton = UIButton(type: .system) self.sendButton = UIButton(type: .system)
self.bottomGradient = GradientView(from: UIColor.clear, to: UIColor.black) self.bottomGradient = GradientView(from: UIColor.clear, to: UIColor.black)
self.textView = MessageTextView() self.textView = MessageTextView()
self.textViewHeight = kMinTextViewHeight self.textViewHeight = kMinTextViewHeight
self.allowCaptions = allowCaptions
super.init(frame: CGRect.zero) super.init(frame: CGRect.zero)
@ -607,8 +617,8 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
textView.addBorder(with: UIColor.lightGray) textView.addBorder(with: UIColor.lightGray)
textView.font = UIFont.ows_dynamicTypeBody() textView.font = UIFont.ows_dynamicTypeBody()
textView.returnKeyType = .done textView.returnKeyType = .done
if !allowCaptions { if let defaultCaption = defaultCaption {
textView.isHidden = true textView.text = defaultCaption
} }
let sendTitle = NSLocalizedString("ATTACHMENT_APPROVAL_SEND_BUTTON", comment: "Label for 'send' button in the 'attachment approval' dialog.") let sendTitle = NSLocalizedString("ATTACHMENT_APPROVAL_SEND_BUTTON", comment: "Label for 'send' button in the 'attachment approval' dialog.")

@ -112,6 +112,8 @@ public class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate {
createAudioPreview() createAudioPreview()
} else if attachment.isOversizeText { } else if attachment.isOversizeText {
createTextPreview() createTextPreview()
} else if attachment.isUrl {
createUrlPreview()
} else { } else {
createGenericPreview() createGenericPreview()
} }
@ -306,7 +308,7 @@ public class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate {
let messageTextView = UITextView() let messageTextView = UITextView()
messageTextView.font = UIFont.ows_dynamicTypeBody() messageTextView.font = UIFont.ows_dynamicTypeBody()
messageTextView.backgroundColor = UIColor.clear messageTextView.backgroundColor = UIColor.clear
messageTextView.isOpaque = false messageTextView.isOpaque = false
messageTextView.isEditable = false messageTextView.isEditable = false
messageTextView.isSelectable = false messageTextView.isSelectable = false
@ -320,7 +322,7 @@ public class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate {
messageTextView.linkTextAttributes = [NSForegroundColorAttributeName : textColor, messageTextView.linkTextAttributes = [NSForegroundColorAttributeName : textColor,
NSUnderlineStyleAttributeName : [NSUnderlineStyle.styleSingle, NSUnderlineStyleAttributeName : [NSUnderlineStyle.styleSingle,
NSUnderlineStyle.patternSolid] NSUnderlineStyle.patternSolid]
] ]
messageTextView.dataDetectorTypes = [.link, .address, .calendarEvent] messageTextView.dataDetectorTypes = [.link, .address, .calendarEvent]
messageTextView.text = messageText messageTextView.text = messageText
@ -340,6 +342,18 @@ public class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate {
messageTextView.autoPinTrailingToSuperview(withMargin:15) messageTextView.autoPinTrailingToSuperview(withMargin:15)
} }
private func createUrlPreview() {
let data = attachment.data
guard let messageText = String(data: data, encoding: String.Encoding.utf8) else {
createGenericPreview()
return
}
// Show nothing; URLs should only appear in the attachment approval view
// of the SAE and in this context the URL will be placed in the caption field.
}
private func createGenericPreview() { private func createGenericPreview() {
var subviews = [UIView]() var subviews = [UIView]()

@ -419,6 +419,11 @@ public class SignalAttachment: NSObject {
return dataUTI == kOversizeTextAttachmentUTI return dataUTI == kOversizeTextAttachmentUTI
} }
@objc
public var isUrl: Bool {
return dataUTI == (kUTTypeURL as String)
}
@objc @objc
public class func pasteboardHasPossibleAttachment() -> Bool { public class func pasteboardHasPossibleAttachment() -> Bool {
return UIPasteboard.general.numberOfItems > 0 return UIPasteboard.general.numberOfItems > 0

@ -605,9 +605,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
// start with base utiType, but it might be something generic like "image" // start with base utiType, but it might be something generic like "image"
var specificUTIType = utiType var specificUTIType = utiType
if utiType == (kUTTypeURL as String) { if utiType == (kUTTypeURL as String) {
// Share URLs as oversize text messages whose text content is the URL. // Use kUTTypeURL for URLs.
Logger.debug("\(self.logTag) using text UTI type for URL.")
specificUTIType = kOversizeTextAttachmentUTI as String
} else if url.pathExtension.count > 0 { } else if url.pathExtension.count > 0 {
// Determine a more specific utiType based on file extension // Determine a more specific utiType based on file extension
if let typeExtension = MIMETypeUtil.utiType(forFileExtension: url.pathExtension) { if let typeExtension = MIMETypeUtil.utiType(forFileExtension: url.pathExtension) {

Loading…
Cancel
Save