Rework attachment download progress for generic attachments.

pull/2/head
Matthew Chen 6 years ago
parent 5df4a0bc17
commit 31b4612746

@ -136,8 +136,8 @@ NS_ASSUME_NONNULL_BEGIN
switch (self.viewItem.attachmentPointer.state) { switch (self.viewItem.attachmentPointer.state) {
case TSAttachmentPointerStateFailed: case TSAttachmentPointerStateFailed:
// TODO: // We don't need to handle the "tap to retry" state here,
// [self addTapToRetryView:bodyMediaView]; // only download progress.
return; return;
case TSAttachmentPointerStateEnqueued: case TSAttachmentPointerStateEnqueued:
case TSAttachmentPointerStateDownloading: case TSAttachmentPointerStateDownloading:

@ -7,9 +7,13 @@ NS_ASSUME_NONNULL_BEGIN
@class ConversationStyle; @class ConversationStyle;
@class TSAttachment; @class TSAttachment;
@protocol ConversationViewItem;
@interface OWSGenericAttachmentView : UIStackView @interface OWSGenericAttachmentView : UIStackView
- (instancetype)initWithAttachment:(TSAttachment *)attachment isIncoming:(BOOL)isIncoming; - (instancetype)initWithAttachment:(TSAttachment *)attachment
isIncoming:(BOOL)isIncoming
viewItem:(id<ConversationViewItem>)viewItem;
- (void)createContentsWithConversationStyle:(ConversationStyle *)conversationStyle; - (void)createContentsWithConversationStyle:(ConversationStyle *)conversationStyle;

@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) TSAttachment *attachment; @property (nonatomic) TSAttachment *attachment;
@property (nonatomic, nullable) TSAttachmentStream *attachmentStream; @property (nonatomic, nullable) TSAttachmentStream *attachmentStream;
@property (nonatomic, weak) id<ConversationViewItem> viewItem;
@property (nonatomic) BOOL isIncoming; @property (nonatomic) BOOL isIncoming;
@property (nonatomic) UILabel *topLabel; @property (nonatomic) UILabel *topLabel;
@property (nonatomic) UILabel *bottomLabel; @property (nonatomic) UILabel *bottomLabel;
@ -30,7 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSGenericAttachmentView @implementation OWSGenericAttachmentView
- (instancetype)initWithAttachment:(TSAttachment *)attachment isIncoming:(BOOL)isIncoming - (instancetype)initWithAttachment:(TSAttachment *)attachment
isIncoming:(BOOL)isIncoming
viewItem:(id<ConversationViewItem>)viewItem
{ {
self = [super init]; self = [super init];
@ -40,6 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
_attachmentStream = (TSAttachmentStream *)attachment; _attachmentStream = (TSAttachmentStream *)attachment;
} }
_isIncoming = isIncoming; _isIncoming = isIncoming;
_viewItem = viewItem;
} }
return self; return self;
@ -130,6 +134,8 @@ NS_ASSUME_NONNULL_BEGIN
[fileTypeLabel autoCenterInSuperview]; [fileTypeLabel autoCenterInSuperview];
[fileTypeLabel autoSetDimension:ALDimensionWidth toSize:self.iconWidth - 20.f]; [fileTypeLabel autoSetDimension:ALDimensionWidth toSize:self.iconWidth - 20.f];
[self replaceIconWithDownloadProgressIfNecessary:imageView];
UIStackView *labelsView = [UIStackView new]; UIStackView *labelsView = [UIStackView new];
labelsView.axis = UILayoutConstraintAxisVertical; labelsView.axis = UILayoutConstraintAxisVertical;
labelsView.spacing = [OWSGenericAttachmentView labelVSpacing]; labelsView.spacing = [OWSGenericAttachmentView labelVSpacing];
@ -175,6 +181,46 @@ NS_ASSUME_NONNULL_BEGIN
[labelsView addArrangedSubview:bottomLabel]; [labelsView addArrangedSubview:bottomLabel];
} }
- (void)replaceIconWithDownloadProgressIfNecessary:(UIView *)iconView
{
if (!self.viewItem.attachmentPointer) {
return;
}
switch (self.viewItem.attachmentPointer.state) {
case TSAttachmentPointerStateFailed:
// We don't need to handle the "tap to retry" state here,
// only download progress.
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;
}
CGSize iconViewSize = [iconView sizeThatFits:CGSizeZero];
CGFloat downloadViewSize = MIN(iconViewSize.width, iconViewSize.height);
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];
}
+ (UIFont *)topLabelFont + (UIFont *)topLabelFont
{ {
return [UIFont ows_dynamicTypeBodyFont]; return [UIFont ows_dynamicTypeBodyFont];

@ -854,8 +854,9 @@ NS_ASSUME_NONNULL_BEGIN
{ {
TSAttachment *attachment = (self.viewItem.attachmentStream ?: self.viewItem.attachmentPointer); TSAttachment *attachment = (self.viewItem.attachmentStream ?: self.viewItem.attachmentPointer);
OWSAssertDebug(attachment); OWSAssertDebug(attachment);
OWSGenericAttachmentView *attachmentView = OWSGenericAttachmentView *attachmentView = [[OWSGenericAttachmentView alloc] initWithAttachment:attachment
[[OWSGenericAttachmentView alloc] initWithAttachment:attachment isIncoming:self.isIncoming]; isIncoming:self.isIncoming
viewItem:self.viewItem];
[attachmentView createContentsWithConversationStyle:self.conversationStyle]; [attachmentView createContentsWithConversationStyle:self.conversationStyle];
[self addProgressViewsIfNecessary:attachmentView shouldShowDownloadProgress:NO]; [self addProgressViewsIfNecessary:attachmentView shouldShowDownloadProgress:NO];
@ -1065,7 +1066,9 @@ NS_ASSUME_NONNULL_BEGIN
TSAttachment *attachment = (self.viewItem.attachmentStream ?: self.viewItem.attachmentPointer); TSAttachment *attachment = (self.viewItem.attachmentStream ?: self.viewItem.attachmentPointer);
OWSAssertDebug(attachment); OWSAssertDebug(attachment);
OWSGenericAttachmentView *attachmentView = OWSGenericAttachmentView *attachmentView =
[[OWSGenericAttachmentView alloc] initWithAttachment:attachment isIncoming:self.isIncoming]; [[OWSGenericAttachmentView alloc] initWithAttachment:attachment
isIncoming:self.isIncoming
viewItem:self.viewItem];
[attachmentView createContentsWithConversationStyle:self.conversationStyle]; [attachmentView createContentsWithConversationStyle:self.conversationStyle];
result = [attachmentView measureSizeWithMaxMessageWidth:maxMessageWidth]; result = [attachmentView measureSizeWithMaxMessageWidth:maxMessageWidth];
break; break;

Loading…
Cancel
Save