Rework attachment download progress for audio files.

pull/2/head
Matthew Chen 6 years ago
parent 4b5994d1b3
commit 5df4a0bc17

@ -128,6 +128,45 @@ NS_ASSUME_NONNULL_BEGIN
self.audioProgressView.progressColor = progressColor;
}
- (void)replaceIconWithDownloadProgressIfNecessary:(UIView *)iconView
{
if (!self.viewItem.attachmentPointer) {
return;
}
switch (self.viewItem.attachmentPointer.state) {
case TSAttachmentPointerStateFailed:
// TODO:
// [self addTapToRetryView:bodyMediaView];
return;
case TSAttachmentPointerStateEnqueued:
case TSAttachmentPointerStateDownloading:
break;
}
switch (self.viewItem.attachmentPointer.pointerType) {
case TSAttachmentPointerTypeRestoring:
// TODO: Show "restoring" indicator and possibly progress.
return;
case TSAttachmentPointerTypeUnknown:
case TSAttachmentPointerTypeIncoming:
break;
}
NSString *_Nullable uniqueId = self.viewItem.attachmentPointer.uniqueId;
if (uniqueId.length < 1) {
OWSFailDebug(@"Missing uniqueId.");
return;
}
CGFloat downloadViewSize = self.iconSize;
MediaDownloadView *downloadView =
[[MediaDownloadView alloc] initWithAttachmentId:uniqueId radius:downloadViewSize * 0.5f];
iconView.layer.opacity = 0.01f;
[self addSubview:downloadView];
[downloadView autoSetDimensionsToSize:CGSizeMake(downloadViewSize, downloadViewSize)];
[downloadView autoAlignAxis:ALAxisHorizontal toSameAxisOfView:iconView];
[downloadView autoAlignAxis:ALAxisVertical toSameAxisOfView:iconView];
}
#pragma mark -
- (CGFloat)hMargin
@ -192,6 +231,8 @@ NS_ASSUME_NONNULL_BEGIN
[self addArrangedSubview:self.audioPlayPauseButton];
[self.audioPlayPauseButton setContentHuggingHigh];
[self replaceIconWithDownloadProgressIfNecessary:self.audioPlayPauseButton];
NSString *_Nullable filename = self.attachment.sourceFilename;
if (filename.length < 1) {
filename = [self.attachmentStream.originalFilePath lastPathComponent];

@ -838,7 +838,7 @@ NS_ASSUME_NONNULL_BEGIN
conversationStyle:self.conversationStyle];
self.viewItem.lastAudioMessageView = audioMessageView;
[audioMessageView createContents];
[self addProgressViewsIfNecessary:audioMessageView];
[self addProgressViewsIfNecessary:audioMessageView shouldShowDownloadProgress:NO];
self.loadCellContentBlock = ^{
// Do nothing.
@ -857,7 +857,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSGenericAttachmentView *attachmentView =
[[OWSGenericAttachmentView alloc] initWithAttachment:attachment isIncoming:self.isIncoming];
[attachmentView createContentsWithConversationStyle:self.conversationStyle];
[self addProgressViewsIfNecessary:attachmentView];
[self addProgressViewsIfNecessary:attachmentView shouldShowDownloadProgress:NO];
self.loadCellContentBlock = ^{
// Do nothing.
@ -895,7 +895,7 @@ NS_ASSUME_NONNULL_BEGIN
// progress or tap-to-retry UI.
UIView *attachmentView = [UIView new];
[self addProgressViewsIfNecessary:attachmentView];
[self addProgressViewsIfNecessary:attachmentView shouldShowDownloadProgress:YES];
self.loadCellContentBlock = ^{
// Do nothing.
@ -907,12 +907,12 @@ NS_ASSUME_NONNULL_BEGIN
return attachmentView;
}
- (void)addProgressViewsIfNecessary:(UIView *)bodyMediaView
- (void)addProgressViewsIfNecessary:(UIView *)bodyMediaView shouldShowDownloadProgress:(BOOL)shouldShowDownloadProgress
{
if (self.viewItem.attachmentStream) {
[self addUploadViewIfNecessary:bodyMediaView];
} else if (self.viewItem.attachmentPointer) {
[self addDownloadViewIfNecessary:bodyMediaView];
[self addDownloadViewIfNecessary:bodyMediaView shouldShowDownloadProgress:(BOOL)shouldShowDownloadProgress];
}
}
@ -934,7 +934,7 @@ NS_ASSUME_NONNULL_BEGIN
[uploadView setCompressionResistanceLow];
}
- (void)addDownloadViewIfNecessary:(UIView *)bodyMediaView
- (void)addDownloadViewIfNecessary:(UIView *)bodyMediaView shouldShowDownloadProgress:(BOOL)shouldShowDownloadProgress
{
OWSAssertDebug(self.viewItem.attachmentPointer);
@ -954,6 +954,9 @@ NS_ASSUME_NONNULL_BEGIN
case TSAttachmentPointerTypeIncoming:
break;
}
if (!shouldShowDownloadProgress) {
return;
}
NSString *_Nullable uniqueId = self.viewItem.attachmentPointer.uniqueId;
if (uniqueId.length < 1) {
OWSFailDebug(@"Missing uniqueId.");

Loading…
Cancel
Save