Fix attachment uploads.

// FREEBIE
pull/1/head
Matthew Chen 7 years ago
parent 9b57df67e0
commit 067b16903c

@ -16,7 +16,7 @@ typedef void (^AttachmentStateBlock)(BOOL isAttachmentReady);
// * Dim the media view using a mask layer.
// * Show and update a progress bar.
// * Disable any media view controls using a callback.
@interface AttachmentUploadView : NSObject
@interface AttachmentUploadView : UIView
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment
superview:(UIView *)superview

@ -3,9 +3,11 @@
//
#import "AttachmentUploadView.h"
#import "OWSBezierPathView.h"
#import "OWSProgressView.h"
#import "OWSUploadingService.h"
#import "TSAttachmentStream.h"
#import "UIView+OWS.h"
NS_ASSUME_NONNULL_BEGIN
@ -13,9 +15,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) TSAttachmentStream *attachment;
@property (nonatomic) OWSProgressView *progressView;
@property (nonatomic) OWSBezierPathView *bezierPathView;
@property (nonatomic) CALayer *maskLayer;
@property (nonatomic) OWSProgressView *progressView;
@property (nonatomic) AttachmentStateBlock _Nullable attachmentStateCallback;
@ -42,25 +44,23 @@ NS_ASSUME_NONNULL_BEGIN
self.attachment = attachment;
self.attachmentStateCallback = attachmentStateCallback;
_maskLayer = [CALayer layer];
[_maskLayer setBackgroundColor:[UIColor blackColor].CGColor];
[_maskLayer setOpacity:0.4f];
[_maskLayer setFrame:superview.frame];
[superview.layer addSublayer:_maskLayer];
const CGFloat progressWidth = round(superview.frame.size.width * 0.45f);
const CGFloat progressHeight = round(MIN(superview.frame.size.height * 0.5f, progressWidth * 0.09f));
CGRect progressFrame = CGRectMake(round((superview.frame.size.width - progressWidth) * 0.5f),
round((superview.frame.size.height - progressHeight) * 0.5f),
progressWidth,
progressHeight);
[superview addSubview:self];
[self autoPinToSuperviewEdges];
_bezierPathView = [OWSBezierPathView new];
self.bezierPathView.configureShapeLayerBlock = ^(CAShapeLayer *layer, CGRect bounds) {
layer.path = [UIBezierPath bezierPathWithRect:bounds].CGPath;
layer.fillColor = [UIColor colorWithWhite:0.f alpha:0.4f].CGColor;
};
[self addSubview:self.bezierPathView];
[self.bezierPathView autoPinToSuperviewEdges];
// The progress view is white. It will only be shown
// while the mask layer is visible, so it will show up
// even against all-white attachments.
_progressView = [OWSProgressView new];
_progressView.color = [UIColor whiteColor];
_progressView.frame = progressFrame;
[superview addSubview:_progressView];
self.progressView.color = [UIColor whiteColor];
[self addSubview:self.progressView];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(attachmentUploadProgress:)
@ -80,9 +80,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)dealloc
{
[_maskLayer removeFromSuperlayer];
[_progressView removeFromSuperview];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@ -110,8 +107,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)ensureViewState
{
_maskLayer.hidden = self.isAttachmentReady || self.lastProgress == 0;
_progressView.hidden = self.isAttachmentReady || self.lastProgress == 0;
self.bezierPathView.hidden = self.isAttachmentReady || self.lastProgress == 0;
self.progressView.hidden = self.isAttachmentReady || self.lastProgress == 0;
}
- (void)attachmentUploadProgress:(NSNotification *)notification
@ -121,7 +118,7 @@ NS_ASSUME_NONNULL_BEGIN
NSString *attachmentID = [userinfo objectForKey:kAttachmentUploadAttachmentIDKey];
if ([self.attachment.uniqueId isEqual:attachmentID]) {
if (!isnan(progress)) {
[_progressView setProgress:progress];
[self.progressView setProgress:progress];
self.lastProgress = progress;
self.isAttachmentReady = self.attachment.isUploaded;
} else {
@ -131,6 +128,35 @@ NS_ASSUME_NONNULL_BEGIN
}
}
- (void)setBounds:(CGRect)bounds
{
BOOL sizeDidChange = !CGSizeEqualToSize(bounds.size, self.bounds.size);
[super setBounds:bounds];
if (sizeDidChange) {
[self updateLayout];
}
}
- (void)setFrame:(CGRect)frame
{
BOOL sizeDidChange = !CGSizeEqualToSize(frame.size, self.frame.size);
[super setFrame:frame];
if (sizeDidChange) {
[self updateLayout];
}
}
- (void)updateLayout
{
const CGFloat progressWidth = round(self.bounds.size.width * 0.45f);
const CGFloat progressHeight = round(MIN(self.bounds.size.height * 0.5f, progressWidth * 0.09f));
CGRect progressFrame = CGRectMake(round((self.bounds.size.width - progressWidth) * 0.5f),
round((self.bounds.size.height - progressHeight) * 0.5f),
progressWidth,
progressHeight);
self.progressView.frame = progressFrame;
}
#pragma mark - Logging
+ (NSString *)tag

@ -224,8 +224,6 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(self.viewItem.interaction);
OWSAssert([self.viewItem.interaction isKindOfClass:[TSMessage class]]);
DDLogError(@"%p loadForDisplay: %@", self, NSStringForOWSMessageCellType(self.cellType));
JSQMessagesBubbleImage *bubbleImageData;
if ([self.viewItem.interaction isKindOfClass:[TSOutgoingMessage class]]) {
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)self.viewItem.interaction;
@ -245,22 +243,30 @@ NS_ASSUME_NONNULL_BEGIN
switch (self.cellType) {
case OWSMessageCellType_TextMessage:
[self loadForTextDisplay];
break;
case OWSMessageCellType_OversizeTextMessage:
OWSAssert(self.viewItem.attachmentStream);
[self loadForTextDisplay];
break;
case OWSMessageCellType_StillImage:
OWSAssert(self.viewItem.attachmentStream);
[self loadForStillImageDisplay];
break;
case OWSMessageCellType_AnimatedImage:
OWSAssert(self.viewItem.attachmentStream);
[self loadForAnimatedImageDisplay];
break;
case OWSMessageCellType_Audio:
OWSAssert(self.viewItem.attachmentStream);
[self loadForAudioDisplay];
break;
case OWSMessageCellType_Video:
OWSAssert(self.viewItem.attachmentStream);
[self loadForVideoDisplay];
break;
case OWSMessageCellType_GenericAttachment: {
OWSAssert(self.viewItem.attachmentStream);
self.attachmentView =
[[OWSGenericAttachmentView alloc] initWithAttachment:self.attachmentStream isIncoming:self.isIncoming];
[self.attachmentView createContents];
@ -906,6 +912,7 @@ NS_ASSUME_NONNULL_BEGIN
self.attachmentView = nil;
[self.audioMessageView removeFromSuperview];
self.audioMessageView = nil;
[self.attachmentUploadView removeFromSuperview];
self.attachmentUploadView = nil;
[self.expirationTimerView clearAnimations];
[self.expirationTimerView removeFromSuperview];

@ -344,7 +344,7 @@ static void *kConversationInputTextViewObservingContext = &kConversationInputTex
- (void)ensureShouldShowVoiceMemoButton
{
self.shouldShowVoiceMemoButton = (self.attachmentToApprove != nil && self.inputTextView.trimmedText.length < 1);
self.shouldShowVoiceMemoButton = (self.attachmentToApprove == nil && self.inputTextView.trimmedText.length < 1);
}
- (void)handleLongPress:(UIGestureRecognizer *)sender
@ -773,6 +773,7 @@ static void *kConversationInputTextViewObservingContext = &kConversationInputTex
[cancelButton autoSetDimension:ALDimensionHeight toSize:cancelButtonSize];
[self ensureContentConstraints];
[self ensureShouldShowVoiceMemoButton];
}
- (void)cancelAttachmentWrapperTapped:(UIGestureRecognizer *)sender
@ -787,6 +788,7 @@ static void *kConversationInputTextViewObservingContext = &kConversationInputTex
self.attachmentToApprove = nil;
[self ensureContentConstraints];
[self ensureShouldShowVoiceMemoButton];
}
- (void)attachmentApprovalSendPressed
@ -799,6 +801,7 @@ static void *kConversationInputTextViewObservingContext = &kConversationInputTex
}
[self ensureContentConstraints];
[self ensureShouldShowVoiceMemoButton];
}
- (void)viewWillAppear:(BOOL)animated

@ -203,6 +203,10 @@ NS_ASSUME_NONNULL_BEGIN
actionBlock:^{
[DebugUIMessages sendMediaAttachments:100 thread:thread];
}],
[OWSTableItem itemWithTitle:@"Send 1,000 media (1/sec.)"
actionBlock:^{
[DebugUIMessages sendMediaAttachments:1000 thread:thread];
}],
[OWSTableItem itemWithTitle:@"Create all system messages"
actionBlock:^{
[DebugUIMessages createSystemMessagesInThread:thread];

Loading…
Cancel
Save