Fix some constraints, get other attachment types looking good

TODO
- [ ] message bubble sizes are not correct. Not always wide enough to
      fit their content.

// FREEBIE
pull/1/head
Michael Kirk 8 years ago committed by sdkjfhsdkjhfsdlkjhfsdf
parent 76ca52f33c
commit f8866c4e0b

@ -240,19 +240,21 @@ NS_ASSUME_NONNULL_BEGIN
self.dateHeaderLabel.hidden = YES; self.dateHeaderLabel.hidden = YES;
self.footerLabel.hidden = YES; self.footerLabel.hidden = YES;
// [self.payloadView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.dateHeaderLabel]; [self.myPayloadView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.dateHeaderLabel];
// [self.footerView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.payloadView]; [self.footerView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.myPayloadView];
[self.mediaMaskingView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.dateHeaderLabel]; [self.mediaMaskingView autoPinEdgeToSuperviewEdge:ALEdgeTop];
[self.mediaMaskingView autoPinEdgeToSuperviewEdge:ALEdgeLeading]; [self.mediaMaskingView autoPinEdgeToSuperviewEdge:ALEdgeLeading];
[self.mediaMaskingView autoPinEdgeToSuperviewEdge:ALEdgeTrailing]; [self.mediaMaskingView autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
[self.myBubbleImageView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.mediaMaskingView]; [self.myBubbleImageView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.mediaMaskingView];
[self.myBubbleImageView autoPinEdgeToSuperviewEdge:ALEdgeBottom];
// want sized to fit... // want sized to fit...
// [self.textMaskingView autoPinEdgeToSuperviewEdge:ALEdgeLeading]; // [self.textMaskingView autoPinEdgeToSuperviewEdge:ALEdgeLeading];
// [self.textMaskingView autoPinEdgeToSuperviewEdge:ALEdgeTrailing]; // [self.textMaskingView autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
// [self.footerView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.textMaskingView]; // [self.footerView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.textMaskingView];
[self.footerView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.myBubbleImageView]; // [self.footerView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.myBubbleImageView];
[self.footerView autoPinEdgeToSuperviewEdge:ALEdgeBottom]; [self.footerView autoPinEdgeToSuperviewEdge:ALEdgeBottom];
[self.footerView autoPinWidthToSuperview]; [self.footerView autoPinWidthToSuperview];
@ -431,10 +433,6 @@ NS_ASSUME_NONNULL_BEGIN
case OWSMessageCellType_AnimatedImage: case OWSMessageCellType_AnimatedImage:
OWSAssert(self.viewItem.attachmentStream); OWSAssert(self.viewItem.attachmentStream);
[self loadForAnimatedImageDisplay]; [self loadForAnimatedImageDisplay];
OWSAssert(self.animatedImageView);
if (self.viewItem.hasText) {
[self loadCaptionForAttachmentView:self.animatedImageView];
}
break; break;
case OWSMessageCellType_Audio: case OWSMessageCellType_Audio:
OWSAssert(self.viewItem.attachmentStream); OWSAssert(self.viewItem.attachmentStream);
@ -451,10 +449,12 @@ NS_ASSUME_NONNULL_BEGIN
[self.attachmentView createContents]; [self.attachmentView createContents];
[self replaceBubbleWithView:self.attachmentView]; [self replaceBubbleWithView:self.attachmentView];
[self addAttachmentUploadViewIfNecessary:self.attachmentView]; [self addAttachmentUploadViewIfNecessary:self.attachmentView];
[self addCaptionIfNecessary];
break; break;
} }
case OWSMessageCellType_DownloadingAttachment: { case OWSMessageCellType_DownloadingAttachment: {
[self loadForDownloadingAttachment]; [self loadForDownloadingAttachment];
[self addCaptionIfNecessary];
break; break;
} }
} }
@ -738,17 +738,17 @@ NS_ASSUME_NONNULL_BEGIN
return [UIFont systemFontOfSize:12.0f]; return [UIFont systemFontOfSize:12.0f];
} }
- (void)loadCaptionForAttachmentView:(UIView *)attachmentView - (void)loadCaptionForAttachmentView
{ {
OWSAssert(attachmentView);
[self loadForTextDisplay]; [self loadForTextDisplay];
NSMutableArray *accumulatedConstraints = [self.contentConstraints mutableCopy]; NSMutableArray *accumulatedConstraints = [self.contentConstraints mutableCopy];
[accumulatedConstraints addObjectsFromArray:@[ [accumulatedConstraints addObjectsFromArray:@[
[self.myBubbleImageView autoPinEdgeToSuperviewEdge:(self.isIncoming ? ALEdgeLeading : ALEdgeTrailing)], [self.myBubbleImageView autoPinEdgeToSuperviewEdge:(self.isIncoming ? ALEdgeLeading : ALEdgeTrailing)],
[self.myBubbleImageView autoPinEdgeToSuperviewEdge:(self.isIncoming ? ALEdgeTrailing : ALEdgeLeading) withInset:0 relation:NSLayoutRelationGreaterThanOrEqual],
[self.textView autoPinLeadingToSuperviewWithMargin:self.textLeadingMargin], [self.textView autoPinLeadingToSuperviewWithMargin:self.textLeadingMargin],
[self.textView autoPinTrailingToSuperviewWithMargin:self.textTrailingMargin], [self.textView autoPinTrailingToSuperviewWithMargin:self.textTrailingMargin],
[self.textView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:attachmentView withOffset:self.textVMargin], [self.textView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.textVMargin],
[self.textView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:self.textVMargin], [self.textView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:self.textVMargin],
]]; ]];
@ -780,6 +780,8 @@ NS_ASSUME_NONNULL_BEGIN
]; ];
} else { } else {
self.contentConstraints = @[ self.contentConstraints = @[
[self.myBubbleImageView autoPinEdgeToSuperviewEdge:(self.isIncoming ? ALEdgeLeading : ALEdgeTrailing)],
[self.myBubbleImageView autoPinEdgeToSuperviewEdge:(self.isIncoming ? ALEdgeTrailing : ALEdgeLeading) withInset:0 relation:NSLayoutRelationGreaterThanOrEqual],
[self.textView autoPinLeadingToSuperviewWithMargin:self.textLeadingMargin], [self.textView autoPinLeadingToSuperviewWithMargin:self.textLeadingMargin],
[self.textView autoPinTrailingToSuperviewWithMargin:self.textTrailingMargin], [self.textView autoPinTrailingToSuperviewWithMargin:self.textTrailingMargin],
[self.textView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.textVMargin], [self.textView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.textVMargin],
@ -832,6 +834,7 @@ NS_ASSUME_NONNULL_BEGIN
self.stillImageView.layer.magnificationFilter = kCAFilterTrilinear; self.stillImageView.layer.magnificationFilter = kCAFilterTrilinear;
[self replaceBubbleWithView:self.stillImageView]; [self replaceBubbleWithView:self.stillImageView];
[self addAttachmentUploadViewIfNecessary:self.stillImageView]; [self addAttachmentUploadViewIfNecessary:self.stillImageView];
[self addCaptionIfNecessary];
} }
- (void)loadForAnimatedImageDisplay - (void)loadForAnimatedImageDisplay
@ -845,6 +848,20 @@ NS_ASSUME_NONNULL_BEGIN
self.animatedImageView.contentMode = UIViewContentModeScaleAspectFill; self.animatedImageView.contentMode = UIViewContentModeScaleAspectFill;
[self replaceBubbleWithView:self.animatedImageView]; [self replaceBubbleWithView:self.animatedImageView];
[self addAttachmentUploadViewIfNecessary:self.animatedImageView]; [self addAttachmentUploadViewIfNecessary:self.animatedImageView];
[self addCaptionIfNecessary];
}
- (void)addCaptionIfNecessary
{
if (self.viewItem.hasText) {
[self loadCaptionForAttachmentView];
} else {
NSMutableArray *accumulatedConstraints = [self.contentConstraints mutableCopy];
[accumulatedConstraints addObjectsFromArray:@[
[self.myBubbleImageView autoSetDimension:ALDimensionHeight toSize:0]
]];
self.contentConstraints = [accumulatedConstraints copy];
}
} }
- (void)loadForAudioDisplay - (void)loadForAudioDisplay
@ -859,6 +876,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.audioMessageView createContents]; [self.audioMessageView createContents];
[self replaceBubbleWithView:self.audioMessageView]; [self replaceBubbleWithView:self.audioMessageView];
[self addAttachmentUploadViewIfNecessary:self.audioMessageView]; [self addAttachmentUploadViewIfNecessary:self.audioMessageView];
[self addCaptionIfNecessary];
} }
- (void)loadForVideoDisplay - (void)loadForVideoDisplay
@ -884,6 +902,7 @@ NS_ASSUME_NONNULL_BEGIN
attachmentStateCallback:^(BOOL isAttachmentReady) { attachmentStateCallback:^(BOOL isAttachmentReady) {
videoPlayButton.hidden = !isAttachmentReady; videoPlayButton.hidden = !isAttachmentReady;
}]; }];
[self addCaptionIfNecessary];
} }
- (void)loadForDownloadingAttachment - (void)loadForDownloadingAttachment
@ -911,6 +930,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.customView addSubview:self.attachmentPointerView]; [self.customView addSubview:self.attachmentPointerView];
[self.attachmentPointerView autoPinWidthToSuperviewWithMargin:20.f]; [self.attachmentPointerView autoPinWidthToSuperviewWithMargin:20.f];
[self.attachmentPointerView autoVCenterInSuperview]; [self.attachmentPointerView autoVCenterInSuperview];
[self addCaptionIfNecessary];
} }
- (void)replaceBubbleWithView:(UIView *)view - (void)replaceBubbleWithView:(UIView *)view

@ -669,6 +669,12 @@ NS_ASSUME_NONNULL_BEGIN
DataSource *_Nullable dataSource = DataSource *_Nullable dataSource =
[DataSourceValue dataSourceWithData:[self createRandomNSDataOfSize:length] utiType:uti]; [DataSourceValue dataSourceWithData:[self createRandomNSDataOfSize:length] utiType:uti];
SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:uti]; SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:uti];
if (arc4random_uniform(100) > 50) {
// give 1/2 our attachments captions, and add a hint that it's a caption since we style them indistinguishably
// from a separate text message.
attachment.captionText = [NSString stringWithFormat:@"%@ (caption)", [self randomText]];
}
[ThreadUtil sendMessageWithAttachment:attachment inThread:thread messageSender:messageSender ignoreErrors:YES]; [ThreadUtil sendMessageWithAttachment:attachment inThread:thread messageSender:messageSender ignoreErrors:YES];
} }
+ (OWSSignalServiceProtosEnvelope *)createEnvelopeForThread:(TSThread *)thread + (OWSSignalServiceProtosEnvelope *)createEnvelopeForThread:(TSThread *)thread

Loading…
Cancel
Save