Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 3d451846a6
commit 7b84019251

@ -5,6 +5,8 @@
#import "OWSMessageEditing.h"
#import <JSQMessagesViewController/JSQPhotoMediaItem.h>
NS_ASSUME_NONNULL_BEGIN
@class TSAttachmentStream;
@interface TSAnimatedAdapter : JSQMediaItem <OWSMessageEditing>
@ -15,3 +17,5 @@
@property NSData *fileData;
@end
NS_ASSUME_NONNULL_END

@ -11,16 +11,20 @@
#import <JSQMessagesViewController/JSQMessagesMediaViewBubbleImageMasker.h>
#import <MobileCoreServices/MobileCoreServices.h>
NS_ASSUME_NONNULL_BEGIN
@interface TSAnimatedAdapter ()
@property (nonatomic) UIImageView *cachedImageView;
@property (nonatomic, nullable) UIImageView *cachedImageView;
@property (nonatomic) UIImage *image;
@property (nonatomic) TSAttachmentStream *attachment;
@property (nonatomic) AttachmentUploadView *attachmentUploadView;
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL incoming;
@end
#pragma mark -
@implementation TSAnimatedAdapter
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming
@ -124,3 +128,5 @@
}
@end
NS_ASSUME_NONNULL_END

@ -5,6 +5,8 @@
#import "OWSMessageEditing.h"
#import <JSQMessagesViewController/JSQMediaItem.h>
NS_ASSUME_NONNULL_BEGIN
@class TSAttachmentStream;
@interface TSGenericAttachmentAdapter : JSQMediaItem <OWSMessageEditing>
@ -12,3 +14,5 @@
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming;
@end
NS_ASSUME_NONNULL_END

@ -13,16 +13,19 @@
#import <MobileCoreServices/MobileCoreServices.h>
#import <SignalServiceKit/MimeTypeUtil.h>
NS_ASSUME_NONNULL_BEGIN
@interface TSGenericAttachmentAdapter ()
@property (nonatomic) UIView *cachedMediaView;
@property (nonatomic, nullable) UIView *cachedMediaView;
@property (nonatomic) TSAttachmentStream *attachment;
@property (nonatomic) AttachmentUploadView *attachmentUploadView;
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL incoming;
@property (nonatomic) NSString *attachmentId;
@end
#pragma mark -
@implementation TSGenericAttachmentAdapter
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming
@ -31,13 +34,17 @@
if (self) {
_attachment = attachment;
_attachmentId = attachment.uniqueId;
_incoming = incoming;
}
return self;
}
- (NSString *)attachmentId
{
return self.attachment.uniqueId;
}
- (void)clearCachedMediaViews
{
[super clearCachedMediaViews];
@ -194,3 +201,5 @@
}
@end
NS_ASSUME_NONNULL_END

@ -18,6 +18,8 @@
#import "TSOutgoingMessage.h"
#import <MobileCoreServices/MobileCoreServices.h>
NS_ASSUME_NONNULL_BEGIN
@interface TSMessageAdapter ()
// ---
@ -60,6 +62,7 @@
@end
#pragma mark -
@implementation TSMessageAdapter
@ -134,8 +137,8 @@
if ([attachment.contentType isEqualToString:OWSMimeTypeOversizeTextMessage]) {
NSData *textData = [NSData dataWithContentsOfURL:stream.mediaURL];
NSString *fullText = [[NSString alloc] initWithData:textData encoding:NSUTF8StringEncoding];
// TODO: Tune this value.
const NSUInteger kMaxTextDisplayLength = 256;
// Only show up to 2kb of text.
const NSUInteger kMaxTextDisplayLength = 2 * 1024;
NSString *displayText = [[DisplayableTextFilter new] displayableText:fullText];
if (displayText.length > kMaxTextDisplayLength) {
// Trim whitespace before _AND_ after slicing the snipper from the string.
@ -152,27 +155,24 @@
} else if ([stream isAnimated]) {
adapter.mediaItem =
[[TSAnimatedAdapter alloc] initWithAttachment:stream incoming:isIncomingAttachment];
adapter.mediaItem.appliesMediaViewMaskAsOutgoing =
[interaction isKindOfClass:[TSOutgoingMessage class]];
adapter.mediaItem.appliesMediaViewMaskAsOutgoing = !isIncomingAttachment;
break;
} else if ([stream isImage]) {
adapter.mediaItem =
[[TSPhotoAdapter alloc] initWithAttachment:stream incoming:isIncomingAttachment];
adapter.mediaItem.appliesMediaViewMaskAsOutgoing =
[interaction isKindOfClass:[TSOutgoingMessage class]];
adapter.mediaItem.appliesMediaViewMaskAsOutgoing = !isIncomingAttachment;
break;
} else if ([stream isVideo]) {
adapter.mediaItem = [[TSVideoAttachmentAdapter alloc]
initWithAttachment:stream
incoming:[interaction isKindOfClass:[TSIncomingMessage class]]];
adapter.mediaItem.appliesMediaViewMaskAsOutgoing =
[interaction isKindOfClass:[TSOutgoingMessage class]];
adapter.mediaItem.appliesMediaViewMaskAsOutgoing = !isIncomingAttachment;
break;
} else {
adapter.mediaItem = [[TSGenericAttachmentAdapter alloc]
initWithAttachment:stream
incoming:[interaction isKindOfClass:[TSIncomingMessage class]]];
adapter.mediaItem.appliesMediaViewMaskAsOutgoing = YES;
adapter.mediaItem.appliesMediaViewMaskAsOutgoing = !isIncomingAttachment;
break;
}
} else if ([attachment isKindOfClass:[TSAttachmentPointer class]]) {
@ -402,3 +402,5 @@
}
@end
NS_ASSUME_NONNULL_END

@ -5,6 +5,8 @@
#import "OWSMessageEditing.h"
#import <JSQMessagesViewController/JSQPhotoMediaItem.h>
NS_ASSUME_NONNULL_BEGIN
@class TSAttachmentStream;
@interface TSPhotoAdapter : JSQPhotoMediaItem <OWSMessageEditing>
@ -15,3 +17,5 @@
@property NSString *attachmentId;
@end
NS_ASSUME_NONNULL_END

@ -9,14 +9,18 @@
#import <JSQMessagesViewController/JSQMessagesMediaViewBubbleImageMasker.h>
#import <MobileCoreServices/MobileCoreServices.h>
NS_ASSUME_NONNULL_BEGIN
@interface TSPhotoAdapter ()
@property (nonatomic) UIImageView *cachedImageView;
@property (nonatomic) AttachmentUploadView *attachmentUploadView;
@property (nonatomic, nullable) UIImageView *cachedImageView;
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL incoming;
@end
#pragma mark -
@implementation TSPhotoAdapter
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming
@ -126,3 +130,5 @@
}
@end
NS_ASSUME_NONNULL_END

@ -1,9 +1,12 @@
// Created by Frederic Jacobs on 17/12/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSMessageEditing.h"
#import <JSQMessagesViewController/JSQVideoMediaItem.h>
NS_ASSUME_NONNULL_BEGIN
@class TSAttachmentStream;
@interface TSVideoAttachmentAdapter : JSQVideoMediaItem <OWSMessageEditing>
@ -24,3 +27,5 @@
- (void)resetAudioDuration;
@end
NS_ASSUME_NONNULL_END

@ -14,22 +14,23 @@
#import <SCWaveformView.h>
#define AUDIO_BAR_HEIGHT 36
NS_ASSUME_NONNULL_BEGIN
@interface TSVideoAttachmentAdapter ()
@property (nonatomic) UIImage *image;
@property (nonatomic) UIImageView *cachedImageView;
@property (nonatomic) UIImageView *videoPlayButton;
@property (nonatomic, nullable) UIImageView *cachedImageView;
@property (nonatomic) TSAttachmentStream *attachment;
@property (nonatomic) UIProgressView *audioProgress;
@property (nonatomic) SCWaveformView *waveform;
@property (nonatomic) UIButton *audioPlayPauseButton;
@property (nonatomic) UILabel *durationLabel;
@property (nonatomic) UIView *audioBubble;
@property (nonatomic, nullable) SCWaveformView *waveform;
@property (nonatomic, nullable) UIButton *audioPlayPauseButton;
@property (nonatomic, nullable) UILabel *durationLabel;
@property (nonatomic) BOOL incoming;
@property (nonatomic) AttachmentUploadView *attachmentUploadView;
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@end
#pragma mark -
@implementation TSVideoAttachmentAdapter
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming {
@ -113,17 +114,15 @@
isOutgoing:self.appliesMediaViewMaskAsOutgoing];
self.cachedImageView = imageView;
UIImage *img = [UIImage imageNamed:@"play_button"];
_videoPlayButton = [[UIImageView alloc] initWithImage:img];
_videoPlayButton.frame = CGRectMake((size.width / 2) - 18, (size.height / 2) - 18, 37, 37);
[self.cachedImageView addSubview:_videoPlayButton];
UIImageView *videoPlayButton = [[UIImageView alloc] initWithImage:img];
videoPlayButton.frame = CGRectMake((size.width / 2) - 18, (size.height / 2) - 18, 37, 37);
[self.cachedImageView addSubview:videoPlayButton];
if (!_incoming) {
__weak TSVideoAttachmentAdapter *weakSelf = self;
self.attachmentUploadView = [[AttachmentUploadView alloc] initWithAttachment:self.attachment
superview:imageView
attachmentStateCallback:^(BOOL isAttachmentReady) {
weakSelf.videoPlayButton.hidden
= !isAttachmentReady;
videoPlayButton.hidden = !isAttachmentReady;
}];
}
}
@ -143,11 +142,11 @@
self.waveform.progress = 0.0;
}
_audioBubble = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, size.width, size.height)];
_audioBubble.backgroundColor =
UIView *audioBubble = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, size.width, size.height)];
audioBubble.backgroundColor =
[UIColor colorWithRed:10 / 255.0f green:130 / 255.0f blue:253 / 255.0f alpha:1.0f];
_audioBubble.layer.cornerRadius = 18;
_audioBubble.layer.masksToBounds = YES;
audioBubble.layer.cornerRadius = 18;
audioBubble.layer.masksToBounds = YES;
_audioPlayPauseButton = [[UIButton alloc] initWithFrame:CGRectMake(3, 3, 30, 30)];
[_audioPlayPauseButton setBackgroundImage:[UIImage imageNamed:@"audio_play_button"]
@ -166,7 +165,7 @@
_durationLabel.textColor = [UIColor whiteColor];
if (_incoming) {
_audioBubble.backgroundColor =
audioBubble.backgroundColor =
[UIColor colorWithRed:229 / 255.0f green:228 / 255.0f blue:234 / 255.0f alpha:1.0f];
_waveform.normalColor = [UIColor whiteColor];
_waveform.progressColor =
@ -176,21 +175,21 @@
_durationLabel.textColor = [UIColor darkTextColor];
}
[_audioBubble addSubview:_waveform];
[_audioBubble addSubview:_audioPlayPauseButton];
[_audioBubble addSubview:_durationLabel];
[audioBubble addSubview:_waveform];
[audioBubble addSubview:_audioPlayPauseButton];
[audioBubble addSubview:_durationLabel];
if (!_incoming) {
__weak TSVideoAttachmentAdapter *weakSelf = self;
self.attachmentUploadView = [[AttachmentUploadView alloc] initWithAttachment:self.attachment
superview:_audioBubble
superview:audioBubble
attachmentStateCallback:^(BOOL isAttachmentReady) {
weakSelf.audioPlayPauseButton.enabled
= isAttachmentReady;
}];
}
return _audioBubble;
return audioBubble;
} else {
// Unknown media type.
OWSAssert(0);
@ -280,3 +279,5 @@
}
@end
NS_ASSUME_NONNULL_END

@ -21,7 +21,7 @@ class AttachmentApprovalViewController: UIViewController {
self.attachment = SignalAttachment.genericAttachment(data: nil,
dataUTI: kUTTypeContent as String)
super.init(coder: aDecoder)
assert(false)
assertionFailure()
}
required init(attachment: SignalAttachment, successCompletion : @escaping () -> Void) {

@ -116,7 +116,7 @@ class SignalAttachment: NSObject {
var errorName: String? {
guard let error = error else {
// This method should only be called if there is an error.
assert(false)
assertionFailure()
return nil
}
@ -126,7 +126,7 @@ class SignalAttachment: NSObject {
var localizedErrorDescription: String? {
guard let error = self.error else {
// This method should only be called if there is an error.
assert(false)
assertionFailure()
return nil
}
@ -158,8 +158,8 @@ class SignalAttachment: NSObject {
var fileExtension: String? {
if dataUTI == SignalAttachment.kOversizeTextAttachmentUTI ||
dataUTI == SignalAttachment.kUnknownTestAttachmentUTI {
assert(false)
return ""
assertionFailure()
return nil
}
guard let fileExtension = UTTypeCopyPreferredTagWithClass(dataUTI as CFString,

Loading…
Cancel
Save