Modify cells to show quoted messages.

pull/1/head
Matthew Chen 8 years ago
parent 22dc904283
commit f6f98369a6

@ -392,13 +392,18 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
[self.bubbleView addSubview:quotedMessageView]; [self.bubbleView addSubview:quotedMessageView];
CGFloat leadingMargin = self.quotedMessageHInset; CGFloat leadingMargin = self.quotedBubbleLeadingMargin;
CGFloat trailingMargin = self.quotedMessageHInset; CGFloat trailingMargin = self.quotedBubbleTrailingMargin;
if (self.isIncoming) {
leadingMargin += kBubbleThornSideInset; // CGFloat leadingMargin = self.quotedMessageHInset + self.textLeadingMargin;
} else { // CGFloat trailingMargin = self.quotedMessageHInset + self.textTrailingMargin;
trailingMargin += kBubbleThornSideInset; // CGFloat leadingMargin = self.quotedMessageHInset;
} // CGFloat trailingMargin = self.quotedMessageHInset;
// if (self.isIncoming) {
// leadingMargin += kBubbleThornSideInset;
// } else {
// trailingMargin += kBubbleThornSideInset;
// }
[self.viewConstraints addObjectsFromArray:@[ [self.viewConstraints addObjectsFromArray:@[
[quotedMessageView autoPinLeadingToSuperviewWithMargin:leadingMargin], [quotedMessageView autoPinLeadingToSuperviewWithMargin:leadingMargin],
@ -1285,7 +1290,9 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
return (int)floor(contentWidth * 0.8f); return (int)floor(contentWidth * 0.8f);
} }
- (CGSize)quotedMessageSizeForViewWidth:(int)viewWidth contentWidth:(int)contentWidth - (CGSize)quotedMessageSizeForViewWidth:(int)viewWidth
contentWidth:(int)contentWidth
includeMargins:(BOOL)includeMargins
{ {
OWSAssert(self.viewItem); OWSAssert(self.viewItem);
OWSAssert([self.viewItem.interaction isKindOfClass:[TSMessage class]]); OWSAssert([self.viewItem.interaction isKindOfClass:[TSMessage class]]);
@ -1314,10 +1321,15 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
result.width += self.quotedMessageHInset; result.width += self.quotedMessageHInset;
// Once we've determined everything _except_ the size of the text
// content (i.e. the quoted author and the quoted text (if any)),
// we can determine the size of the text content.
const int maxMessageWidth = [self maxMessageWidthForContentWidth:contentWidth]; const int maxMessageWidth = [self maxMessageWidthForContentWidth:contentWidth];
CGFloat maxContentWidth = (maxMessageWidth - (self.textTrailingMargin + self.textLeadingMargin + result.width)); CGFloat maxTextWidth = (maxMessageWidth - (self.textTrailingMargin + self.textLeadingMargin + result.width));
CGFloat textWidth = 0.f; CGFloat textWidth = 0.f;
DDLogInfo(@"%@ --- maxTextWidth: %f", self.logTag, maxTextWidth);
// Author // Author
{ {
OWSContactsManager *contactsManager = Environment.current.contactsManager; OWSContactsManager *contactsManager = Environment.current.contactsManager;
@ -1329,7 +1341,10 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
quotedAuthorLabel.lineBreakMode = NSLineBreakByTruncatingTail; quotedAuthorLabel.lineBreakMode = NSLineBreakByTruncatingTail;
quotedAuthorLabel.numberOfLines = 1; quotedAuthorLabel.numberOfLines = 1;
CGSize quotedAuthorSize = [quotedAuthorLabel sizeThatFits:CGSizeMake(maxContentWidth, CGFLOAT_MAX)]; CGSize quotedAuthorSize = CGSizeCeil([quotedAuthorLabel sizeThatFits:CGSizeMake(maxTextWidth, CGFLOAT_MAX)]);
DDLogInfo(@"%@ --- quotedAuthorSize.width: %f", self.logTag, quotedAuthorSize.width);
textWidth = MAX(textWidth, quotedAuthorSize.width); textWidth = MAX(textWidth, quotedAuthorSize.width);
result.height += self.quotedContentTopInset; result.height += self.quotedContentTopInset;
result.height += self.quotedAuthorHeight; result.height += self.quotedAuthorHeight;
@ -1338,18 +1353,31 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
if (self.hasQuotedText) { if (self.hasQuotedText) {
UILabel *quotedTextView = [self createQuotedTextView]; UILabel *quotedTextView = [self createQuotedTextView];
CGSize textSize = CGSizeCeil([quotedTextView sizeThatFits:CGSizeMake(maxContentWidth, CGFLOAT_MAX)]); CGSize textSize = CGSizeCeil([quotedTextView sizeThatFits:CGSizeMake(maxTextWidth, CGFLOAT_MAX)]);
DDLogInfo(@"%@ --- textSize.width: %f", self.logTag, textSize.width);
textWidth = MAX(textWidth, textSize.width); textWidth = MAX(textWidth, textSize.width);
result.height += self.quotedAuthorBottomSpacing; result.height += self.quotedAuthorBottomSpacing;
result.height += textSize.height; result.height += textSize.height;
} }
DDLogInfo(@"%@ --- textWidth: %f", self.logTag, textWidth);
DDLogInfo(@"%@ --- quotedMessageSizeForViewWidth 3: %@", self.logTag, NSStringFromCGSize(result));
result.width += textWidth; result.width += textWidth;
result.height += self.quotedContentBottomInset; result.height += self.quotedContentBottomInset;
result.height = MAX(result.height, thumbnailHeight); result.height = MAX(result.height, thumbnailHeight);
DDLogInfo(@"%@ --- quotedMessageSizeForViewWidth 4: %@", self.logTag, NSStringFromCGSize(result));
if (includeMargins) {
result.width += kBubbleThornSideInset;
}
DDLogInfo(@"%@ --- quotedMessageSizeForViewWidth 5: %@", self.logTag, NSStringFromCGSize(result));
return result; return result;
} }
@ -1360,15 +1388,19 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
CGSize cellSize = CGSizeZero; CGSize cellSize = CGSizeZero;
CGSize quotedMessageSize = [self quotedMessageSizeForViewWidth:viewWidth contentWidth:contentWidth]; CGSize quotedMessageSize =
[self quotedMessageSizeForViewWidth:viewWidth contentWidth:contentWidth includeMargins:YES];
DDLogInfo(@"%@ --- quotedMessageSize: %@", self.logTag, NSStringFromCGSize(quotedMessageSize));
cellSize.width = MAX(cellSize.width, quotedMessageSize.width); cellSize.width = MAX(cellSize.width, quotedMessageSize.width);
cellSize.height += quotedMessageSize.height; cellSize.height += quotedMessageSize.height;
CGSize mediaContentSize = [self bodyMediaSizeForContentWidth:contentWidth]; CGSize mediaContentSize = [self bodyMediaSizeForContentWidth:contentWidth];
DDLogInfo(@"%@ --- mediaContentSize: %@", self.logTag, NSStringFromCGSize(mediaContentSize));
cellSize.width = MAX(cellSize.width, mediaContentSize.width); cellSize.width = MAX(cellSize.width, mediaContentSize.width);
cellSize.height += mediaContentSize.height; cellSize.height += mediaContentSize.height;
CGSize textContentSize = [self bodyTextSizeForContentWidth:contentWidth includeMargins:YES]; CGSize textContentSize = [self bodyTextSizeForContentWidth:contentWidth includeMargins:YES];
DDLogInfo(@"%@ --- textContentSize: %@", self.logTag, NSStringFromCGSize(textContentSize));
cellSize.width = MAX(cellSize.width, textContentSize.width); cellSize.width = MAX(cellSize.width, textContentSize.width);
cellSize.height += textContentSize.height; cellSize.height += textContentSize.height;
@ -1386,6 +1418,8 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
cellSize = CGSizeCeil(cellSize); cellSize = CGSizeCeil(cellSize);
DDLogInfo(@"%@ --- cellSize: %@", self.logTag, NSStringFromCGSize(cellSize));
return cellSize; return cellSize;
} }
@ -1515,6 +1549,24 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
return result; return result;
} }
- (CGFloat)quotedBubbleLeadingMargin
{
CGFloat result = self.quotedMessageHInset;
if (self.isIncoming) {
result += kBubbleThornSideInset;
}
return result;
}
- (CGFloat)quotedBubbleTrailingMargin
{
CGFloat result = self.quotedMessageHInset;
if (!self.isIncoming) {
result += kBubbleThornSideInset;
}
return result;
}
- (CGFloat)textTopMargin - (CGFloat)textTopMargin
{ {
return kBubbleTextVInset; return kBubbleTextVInset;

@ -87,6 +87,7 @@ NS_ASSUME_NONNULL_BEGIN
[DebugUIMessages performActionNTimes:action]; [DebugUIMessages performActionNTimes:action];
}]]; }]];
} }
[items addObjectsFromArray:@[ [items addObjectsFromArray:@[
#pragma mark - Actions #pragma mark - Actions
@ -103,6 +104,10 @@ NS_ASSUME_NONNULL_BEGIN
actionBlock:^{ actionBlock:^{
[DebugUIMessages selectSendMediaAction:thread]; [DebugUIMessages selectSendMediaAction:thread];
}], }],
[OWSTableItem itemWithTitle:@"Select Quoted Reply"
actionBlock:^{
[DebugUIMessages selectQuotedReplyAction:thread];
}],
#pragma mark - Misc. #pragma mark - Misc.
@ -2464,6 +2469,14 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
subactions:[self allFakeQuotedReplyActions:thread includeLabels:YES]]; subactions:[self allFakeQuotedReplyActions:thread includeLabels:YES]];
} }
+ (void)selectQuotedReplyAction:(TSThread *)thread
{
OWSAssertIsOnMainThread();
OWSAssert(thread);
[self selectActionUI:[self allFakeQuotedReplyActions:thread includeLabels:NO] label:@"Select QuotedReply"];
}
+ (DebugUIMessagesAction *)randomQuotedReplyAction:(TSThread *)thread + (DebugUIMessagesAction *)randomQuotedReplyAction:(TSThread *)thread
{ {
OWSAssert(thread); OWSAssert(thread);

Loading…
Cancel
Save