Show label when captioning limit has been reached.

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent 6b6f4f9336
commit d94709e13f

@ -82,6 +82,9 @@
/* No comment provided by engineer. */
"ATTACHMENT" = "Attachment";
/* One line label indicating the user can add no more text to the attachment caption. */
"ATTACHMENT_APPROVAL_CAPTION_LENGTH_LIMIT_REACHED" = "Message limit reached.";
/* Title for the 'attachment approval' dialog. */
"ATTACHMENT_APPROVAL_DIALOG_TITLE" = "Attachment";

@ -484,6 +484,7 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
private let sendButton: UIButton
private let textView: UITextView
private let bottomGradient: GradientView
private let lengthLimitLabel: UILabel
// Layout Constants
@ -523,6 +524,7 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
self.bottomGradient = GradientView(from: UIColor.clear, to: UIColor.black)
self.textView = MessageTextView()
self.textViewHeight = kMinTextViewHeight
self.lengthLimitLabel = UILabel()
super.init(frame: CGRect.zero)
@ -560,12 +562,24 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
// Increase hit area of send button
sendButton.contentEdgeInsets = UIEdgeInsets(top: 6, left: 8, bottom: 6, right: 8)
// Length Limit Label shown when the user inputs too long of a message
lengthLimitLabel.textColor = .white
lengthLimitLabel.text = NSLocalizedString("ATTACHMENT_APPROVAL_CAPTION_LENGTH_LIMIT_REACHED", comment: "One line label indicating the user can add no more text to the attachment caption.")
lengthLimitLabel.textAlignment = .center
// Add shadow in case overlayed on white content
lengthLimitLabel.layer.shadowColor = UIColor.black.cgColor
lengthLimitLabel.layer.shadowOffset = CGSize(width: 0.0, height: 0.0)
lengthLimitLabel.layer.shadowOpacity = 0.8
self.lengthLimitLabel.isHidden = true
let contentView = UIView()
addSubview(contentView)
contentView.autoPinEdgesToSuperviewEdges()
contentView.addSubview(bottomGradient)
contentView.addSubview(sendButton)
contentView.addSubview(textView)
contentView.addSubview(lengthLimitLabel)
// Layout
let kToolbarMargin: CGFloat = 8
@ -597,6 +611,12 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
sendButton.setContentHuggingHigh()
sendButton.setCompressionResistanceHigh()
lengthLimitLabel.autoPinEdge(toSuperviewMargin: .left)
lengthLimitLabel.autoPinEdge(toSuperviewMargin: .right)
lengthLimitLabel.autoPinEdge(.bottom, to: .top, of: textView, withOffset: -6)
lengthLimitLabel.setContentHuggingHigh()
lengthLimitLabel.setCompressionResistanceHigh()
let bottomGradientHeight = ScaleFromIPhone5(100)
bottomGradient.autoSetDimension(.height, toSize: bottomGradientHeight)
bottomGradient.autoPinEdgesToSuperviewEdges(with: .zero, excludingEdge: .top)
@ -619,6 +639,7 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
// Because the captioning interface doesn't allow newlines, in practice design pressures users to leave relatively short captions.
let maxCharacterCount = 2000
guard textView.text.count + text.count - range.length <= maxCharacterCount else {
self.lengthLimitLabel.isHidden = false
// Accept as much of the input as we can
let remainingSpace = maxCharacterCount - textView.text.count
if (remainingSpace) > 0 {
@ -628,6 +649,7 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
}
return false
}
self.lengthLimitLabel.isHidden = true
// Though we can wrap the text, we don't want to encourage multline captions, plus a "done" button
// allows the user to get the keyboard out of the way while in the attachment approval view.

@ -416,15 +416,17 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
OWSSignalServiceProtosDataMessageBuilder *builder = [OWSSignalServiceProtosDataMessageBuilder new];
[builder setTimestamp:self.timestamp];
if ([self.body lengthOfBytesUsingEncoding:NSUTF8StringEncoding] <= kOversizeTextMessageSizeThreshold) {
[builder setBody:self.body];
} else {
OWSFail(@"%@ message body length too long.", self.logTag);
NSMutableString *truncatedBody = [self.body mutableCopy];
while ([truncatedBody lengthOfBytesUsingEncoding:NSUTF8StringEncoding] > kOversizeTextMessageSizeThreshold) {
DDLogError(@"%@ truncating body which is too long: %tu", self.logTag, [truncatedBody lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
DDLogError(@"%@ truncating body which is too long: %tu",
self.logTag,
[truncatedBody lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
truncatedBody = [truncatedBody substringToIndex:truncatedBody.length / 2];
}
[builder setBody:truncatedBody];

Loading…
Cancel
Save