Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent b833976b77
commit b1624d6818

@ -2,8 +2,8 @@
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// //
#import "OWSMath.h"
#import "UIView+OWS.h" #import "UIView+OWS.h"
#import "OWSMath.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -36,8 +36,8 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value)
- (NSArray<NSLayoutConstraint *> *)autoPinWidthToSuperviewWithMargin:(CGFloat)margin - (NSArray<NSLayoutConstraint *> *)autoPinWidthToSuperviewWithMargin:(CGFloat)margin
{ {
NSArray<NSLayoutConstraint *> *result = @[ NSArray<NSLayoutConstraint *> *result = @[
[self autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:self.superview withOffset:+margin], [self autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:margin],
[self autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:self.superview withOffset:-margin], [self autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:margin],
]; ];
return result; return result;
} }
@ -45,8 +45,8 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value)
- (NSArray<NSLayoutConstraint *> *)autoPinWidthToSuperview - (NSArray<NSLayoutConstraint *> *)autoPinWidthToSuperview
{ {
NSArray<NSLayoutConstraint *> *result = @[ NSArray<NSLayoutConstraint *> *result = @[
[self autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:self.superview], [self autoPinEdgeToSuperviewEdge:ALEdgeLeft],
[self autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:self.superview], [self autoPinEdgeToSuperviewEdge:ALEdgeRight],
]; ];
return result; return result;
} }
@ -63,8 +63,8 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value)
- (NSArray<NSLayoutConstraint *> *)autoPinHeightToSuperviewWithMargin:(CGFloat)margin - (NSArray<NSLayoutConstraint *> *)autoPinHeightToSuperviewWithMargin:(CGFloat)margin
{ {
NSArray<NSLayoutConstraint *> *result = @[ NSArray<NSLayoutConstraint *> *result = @[
[self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.superview withOffset:+margin], [self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:margin],
[self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self.superview withOffset:-margin], [self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:margin],
]; ];
return result; return result;
} }
@ -72,8 +72,8 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value)
- (NSArray<NSLayoutConstraint *> *)autoPinHeightToSuperview - (NSArray<NSLayoutConstraint *> *)autoPinHeightToSuperview
{ {
NSArray<NSLayoutConstraint *> *result = @[ NSArray<NSLayoutConstraint *> *result = @[
[self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.superview], [self autoPinEdgeToSuperviewEdge:ALEdgeTop],
[self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self.superview], [self autoPinEdgeToSuperviewEdge:ALEdgeBottom],
]; ];
return result; return result;
} }
@ -81,10 +81,10 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value)
- (NSArray<NSLayoutConstraint *> *)autoPinToSuperviewEdges - (NSArray<NSLayoutConstraint *> *)autoPinToSuperviewEdges
{ {
NSArray<NSLayoutConstraint *> *result = @[ NSArray<NSLayoutConstraint *> *result = @[
[self autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:self.superview], [self autoPinEdgeToSuperviewEdge:ALEdgeLeft ],
[self autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:self.superview], [self autoPinEdgeToSuperviewEdge:ALEdgeRight ],
[self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.superview], [self autoPinEdgeToSuperviewEdge:ALEdgeTop ],
[self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self.superview], [self autoPinEdgeToSuperviewEdge:ALEdgeBottom ],
]; ];
return result; return result;
} }

@ -23,6 +23,15 @@
]]; ]];
} }
+ (void)showShareUIForText:(NSString *)text
{
OWSAssert(text);
[AttachmentSharing showShareUIForActivityItems:@[
text,
]];
}
+ (void)showShareUIForActivityItems:(NSArray *)activityItems + (void)showShareUIForActivityItems:(NSArray *)activityItems
{ {
OWSAssert(activityItems); OWSAssert(activityItems);
@ -63,15 +72,6 @@
}); });
} }
+ (void)showShareUIForText:(NSString *)text
{
OWSAssert(text);
[AttachmentSharing showShareUIForActivityItems:@[
text,
]];
}
#pragma mark - Logging #pragma mark - Logging
+ (NSString *)tag + (NSString *)tag

@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
typedef void (^AttachmentStateBlock)(BOOL isAttachmentReady); typedef void (^AttachmentStateBlock)(BOOL isAttachmentReady);
// This entity is used by display download progress for incoming // This entity is used to display download progress for incoming
// attachments in conversation view cells. // attachments in conversation view cells.
// //
// During attachment uploads we want to: // During attachment uploads we want to:

@ -292,10 +292,6 @@ NS_ASSUME_NONNULL_BEGIN
= (self.isIncoming ? [UIColor jsq_messageBubbleLightGrayColor] : [UIColor ows_fadedBlueColor]); = (self.isIncoming ? [UIColor jsq_messageBubbleLightGrayColor] : [UIColor ows_fadedBlueColor]);
break; break;
case TSAttachmentPointerStateDownloading: case TSAttachmentPointerStateDownloading:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(attachmentDownloadProgress:)
name:kAttachmentDownloadProgressNotification
object:nil];
self.customView.backgroundColor self.customView.backgroundColor
= (self.isIncoming ? [UIColor jsq_messageBubbleLightGrayColor] : [UIColor ows_fadedBlueColor]); = (self.isIncoming ? [UIColor jsq_messageBubbleLightGrayColor] : [UIColor ows_fadedBlueColor]);
break; break;
@ -491,7 +487,6 @@ NS_ASSUME_NONNULL_BEGIN
{ {
[super prepareForReuse]; [super prepareForReuse];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[NSLayoutConstraint deactivateConstraints:self.contentConstraints]; [NSLayoutConstraint deactivateConstraints:self.contentConstraints];
self.contentConstraints = nil; self.contentConstraints = nil;
@ -575,20 +570,6 @@ NS_ASSUME_NONNULL_BEGIN
// [self.expirationTimerView stopTimer]; // [self.expirationTimerView stopTimer];
//} //}
#pragma mark - Notifications:
// TODO: Move this logic into AttachmentPointerView.
- (void)attachmentDownloadProgress:(NSNotification *)notification
{
NSNumber *progress = notification.userInfo[kAttachmentDownloadProgressKey];
NSString *attachmentId = notification.userInfo[kAttachmentDownloadAttachmentIDKey];
if (!self.attachmentPointer || ![self.attachmentPointer.uniqueId isEqualToString:attachmentId]) {
OWSFail(@"%@ Unexpected attachment progress notification: %@", self.logTag, attachmentId);
return;
}
self.attachmentPointerView.progress = progress.floatValue;
}
#pragma mark - Gesture recognizers #pragma mark - Gesture recognizers
- (void)handleTapGesture:(UITapGestureRecognizer *)sender - (void)handleTapGesture:(UITapGestureRecognizer *)sender

@ -20,6 +20,8 @@ typedef NS_ENUM(NSInteger, OWSMessageCellType) {
OWSMessageCellType_Unknown = OWSMessageCellType_TextMessage, OWSMessageCellType_Unknown = OWSMessageCellType_TextMessage,
}; };
NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
@class ConversationViewCell; @class ConversationViewCell;
@class OWSAudioMessageView; @class OWSAudioMessageView;
@class TSAttachmentPointer; @class TSAttachmentPointer;

@ -15,6 +15,28 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
{
switch (cellType) {
case OWSMessageCellType_TextMessage:
return @"OWSMessageCellType_TextMessage";
case OWSMessageCellType_OversizeTextMessage:
return @"OWSMessageCellType_OversizeTextMessage";
case OWSMessageCellType_StillImage:
return @"OWSMessageCellType_StillImage";
case OWSMessageCellType_AnimatedImage:
return @"OWSMessageCellType_AnimatedImage";
case OWSMessageCellType_Audio:
return @"OWSMessageCellType_Audio";
case OWSMessageCellType_Video:
return @"OWSMessageCellType_Video";
case OWSMessageCellType_GenericAttachment:
return @"OWSMessageCellType_GenericAttachment";
case OWSMessageCellType_DownloadingAttachment:
return @"OWSMessageCellType_DownloadingAttachment";
}
}
@interface ConversationViewItem () @interface ConversationViewItem ()
@property (nonatomic, nullable) NSValue *cachedCellSize; @property (nonatomic, nullable) NSValue *cachedCellSize;
@ -58,6 +80,13 @@ NS_ASSUME_NONNULL_BEGIN
_interaction = interaction; _interaction = interaction;
self.hasViewState = NO;
self.messageCellType = OWSMessageCellType_Unknown;
self.textMessage = nil;
self.attachmentStream = nil;
self.attachmentPointer = nil;
self.contentSize = CGSizeZero;
[self clearCachedLayoutState]; [self clearCachedLayoutState];
} }

@ -37,6 +37,36 @@ class AttachmentPointerView: UIView {
createSubviews() createSubviews()
updateViews() updateViews()
if attachmentPointer.state == .downloading {
NotificationCenter.default.addObserver(self,
selector:#selector(attachmentDownloadProgress(_:)),
name:NSNotification.Name.attachmentDownloadProgress,
object:nil)
}
}
deinit {
NotificationCenter.default.removeObserver(self)
}
internal func attachmentDownloadProgress(_ notification: Notification) {
guard let attachmentId = attachmentPointer.uniqueId else {
owsFail("Missing attachment id.")
return
}
guard let progress = (notification as NSNotification).userInfo?[kAttachmentDownloadProgressKey] as? NSNumber else {
owsFail("Attachment download notification missing progress.")
return
}
guard let notificationAttachmentId = (notification as NSNotification).userInfo?[kAttachmentDownloadAttachmentIDKey] as? String else {
owsFail("Attachment download notification missing attachment id.")
return
}
guard notificationAttachmentId == attachmentId else {
return
}
self.progress = CGFloat(progress.floatValue)
} }
@available(*, unavailable) @available(*, unavailable)

@ -119,6 +119,18 @@ NS_ASSUME_NONNULL_BEGIN
return CGSizeMake(UIViewNoIntrinsicMetric, 16); return CGSizeMake(UIViewNoIntrinsicMetric, 16);
} }
#pragma mark - Logging
+ (NSString *)logTag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)logTag
{
return self.class.logTag;
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

Loading…
Cancel
Save