Respond to CR.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-10-12 13:48:09 -04:00
parent b833976b77
commit b1624d6818
8 changed files with 96 additions and 42 deletions

View File

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

View File

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

View File

@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
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.
//
// During attachment uploads we want to:

View File

@ -292,10 +292,6 @@ NS_ASSUME_NONNULL_BEGIN
= (self.isIncoming ? [UIColor jsq_messageBubbleLightGrayColor] : [UIColor ows_fadedBlueColor]);
break;
case TSAttachmentPointerStateDownloading:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(attachmentDownloadProgress:)
name:kAttachmentDownloadProgressNotification
object:nil];
self.customView.backgroundColor
= (self.isIncoming ? [UIColor jsq_messageBubbleLightGrayColor] : [UIColor ows_fadedBlueColor]);
break;
@ -491,7 +487,6 @@ NS_ASSUME_NONNULL_BEGIN
{
[super prepareForReuse];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[NSLayoutConstraint deactivateConstraints:self.contentConstraints];
self.contentConstraints = nil;
@ -575,20 +570,6 @@ NS_ASSUME_NONNULL_BEGIN
// [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
- (void)handleTapGesture:(UITapGestureRecognizer *)sender

View File

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

View File

@ -15,6 +15,28 @@
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 ()
@property (nonatomic, nullable) NSValue *cachedCellSize;
@ -58,6 +80,13 @@ NS_ASSUME_NONNULL_BEGIN
_interaction = interaction;
self.hasViewState = NO;
self.messageCellType = OWSMessageCellType_Unknown;
self.textMessage = nil;
self.attachmentStream = nil;
self.attachmentPointer = nil;
self.contentSize = CGSizeZero;
[self clearCachedLayoutState];
}

View File

@ -37,6 +37,36 @@ class AttachmentPointerView: UIView {
createSubviews()
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)

View File

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