Remove waveform from audio message bubbles.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 61523a14a1
commit 800715a5e0

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "audio_pause_blue_bubble@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "audio_pause_blue_bubble@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "audio_pause_blue_bubble@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "audio_pause_white_bubble@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "audio_pause_white_bubble@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "audio_pause_white_bubble@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "audio_play_blue_bubble@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "audio_play_blue_bubble@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "audio_play_blue_bubble@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "audio_play_white_bubble@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "audio_play_white_bubble@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "audio_play_white_bubble@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

@ -9,12 +9,18 @@
#import "TSAttachmentStream.h"
#import "TSMessagesManager.h"
#import "TSStorageManager+keyingMaterial.h"
#import "UIColor+OWS.h"
#import "UIFont+OWS.h"
#import "UIView+OWS.h"
#import <JSQMessagesViewController/JSQMessagesMediaViewBubbleImageMasker.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <SCWaveformView.h>
#import <SignalServiceKit/MIMETypeUtil.h>
#define AUDIO_BAR_HEIGHT 36
const CGFloat kAudioViewWidth = 100;
const CGFloat kAudioButtonHeight = kAudioViewWidth;
const CGFloat kAudioViewVSpacing = 5;
const CGFloat kAudioLabelHeight = 20;
const CGFloat kAudioBottomMargin = 5;
NS_ASSUME_NONNULL_BEGIN
@ -23,9 +29,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) UIImage *image;
@property (nonatomic, nullable) UIImageView *cachedImageView;
@property (nonatomic) TSAttachmentStream *attachment;
@property (nonatomic, nullable) SCWaveformView *waveform;
@property (nonatomic, nullable) UIButton *audioPlayPauseButton;
@property (nonatomic, nullable) UILabel *durationLabel;
@property (nonatomic, nullable) UILabel *audioLabel;
@property (nonatomic) BOOL incoming;
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL isAudioPlaying;
@ -81,40 +86,16 @@ NS_ASSUME_NONNULL_BEGIN
return [MIMETypeUtil isSupportedVideoMIMEType:_contentType];
}
- (NSString *)formatDuration:(NSTimeInterval)duration {
double dur = duration;
int minutes = (int)(dur / 60);
int seconds = (int)(dur - minutes * 60);
NSString *minutes_str = [NSString stringWithFormat:@"%01d", minutes];
NSString *seconds_str = [NSString stringWithFormat:@"%02d", seconds];
NSString *label_text = [NSString stringWithFormat:@"%@:%@", minutes_str, seconds_str];
return label_text;
}
- (void)setAudioProgressFromFloat:(float)progress {
dispatch_async(dispatch_get_main_queue(), ^{
if (!isnan(progress)) {
[_waveform setProgress:progress];
[_waveform generateWaveforms];
[_waveform setNeedsDisplay];
}
});
}
- (void)setAudioIconToPlay {
[_audioPlayPauseButton
setBackgroundImage:[UIImage imageNamed:(_incoming ? @"audio_play_button_blue" : @"audio_play_button")]
forState:UIControlStateNormal];
setImage:[UIImage imageNamed:(_incoming ? @"audio_play_blue_bubble" : @"audio_play_white_bubble")]
forState:UIControlStateNormal];
}
- (void)setAudioIconToPause {
[_audioPlayPauseButton
setBackgroundImage:[UIImage imageNamed:(_incoming ? @"audio_pause_button_blue" : @"audio_pause_button")]
forState:UIControlStateNormal];
}
- (void)removeDurationLabel {
[_durationLabel removeFromSuperview];
setImage:[UIImage imageNamed:(_incoming ? @"audio_pause_blue_bubble" : @"audio_pause_white_bubble")]
forState:UIControlStateNormal];
}
#pragma mark - JSQMessageMediaData protocol
@ -144,54 +125,37 @@ NS_ASSUME_NONNULL_BEGIN
}
}
} else if ([self isAudio]) {
NSError *err = NULL;
NSURL *url =
[MIMETypeUtil simLinkCorrectExtensionOfFile:_attachment.mediaURL ofMIMEType:_attachment.contentType];
if (!self.waveform) {
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
self.waveform = [[SCWaveformView alloc] init];
self.waveform.frame = CGRectMake(42.0, 0.0, size.width - 84, size.height);
self.waveform.asset = asset;
self.waveform.progressColor = [UIColor whiteColor];
self.waveform.backgroundColor = [UIColor colorWithRed:229 / 255.0f green:228 / 255.0f blue:234 / 255.0f alpha:1.0f];
[self.waveform generateWaveforms];
self.waveform.progress = 0.0;
}
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;
_audioPlayPauseButton = [[UIButton alloc] initWithFrame:CGRectMake(3, 3, 30, 30)];
_audioPlayPauseButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kAudioViewWidth, kAudioButtonHeight)];
_audioPlayPauseButton.enabled = NO;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&err];
_durationLabel = [[UILabel alloc] init];
_durationLabel.text = [self formatDuration:player.duration];
_durationLabel.font = [UIFont systemFontOfSize:14];
[_durationLabel sizeToFit];
_durationLabel.frame = CGRectMake((size.width - _durationLabel.frame.size.width) - 10,
_durationLabel.frame.origin.y,
_durationLabel.frame.size.width,
AUDIO_BAR_HEIGHT);
_durationLabel.backgroundColor = [UIColor clearColor];
_durationLabel.textColor = [UIColor whiteColor];
NSString *audioLabelText = [[MIMETypeUtil fileExtensionForMIMEType:self.contentType] uppercaseString];
if (!audioLabelText) {
audioLabelText = NSLocalizedString(
@"MESSAGES_VIEW_AUDIO_TYPE_GENERIC", @"A label for audio attachments of unknown type.");
}
_audioLabel = [[UILabel alloc] init];
_audioLabel.text = audioLabelText;
_audioLabel.font = [UIFont ows_mediumFontWithSize:14.f];
_audioLabel.textColor = (_incoming ? [UIColor colorWithRGBHex:0x0b83fd] : [UIColor whiteColor]);
_audioLabel.textAlignment = NSTextAlignmentCenter;
_audioLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[_audioLabel sizeToFit];
_audioLabel.frame = CGRectMake(0, kAudioButtonHeight + kAudioViewVSpacing, kAudioViewWidth, kAudioLabelHeight);
if (_incoming) {
audioBubble.backgroundColor =
[UIColor colorWithRed:229 / 255.0f green:228 / 255.0f blue:234 / 255.0f alpha:1.0f];
_waveform.normalColor = [UIColor whiteColor];
_waveform.progressColor =
[UIColor colorWithRed:107 / 255.0f green:185 / 255.0f blue:254 / 255.0f alpha:1.0f];
_durationLabel.textColor = [UIColor darkTextColor];
}
[audioBubble addSubview:_waveform];
[audioBubble addSubview:_audioPlayPauseButton];
[audioBubble addSubview:_durationLabel];
[audioBubble addSubview:_audioLabel];
if (!_incoming) {
self.attachmentUploadView = [[AttachmentUploadView alloc] initWithAttachment:self.attachment
@ -216,7 +180,9 @@ NS_ASSUME_NONNULL_BEGIN
- (CGSize)mediaViewDisplaySize {
CGSize size = [super mediaViewDisplaySize];
if ([self isAudio]) {
size.height = AUDIO_BAR_HEIGHT;
size.width = kAudioViewWidth;
size.height = kAudioButtonHeight + kAudioViewVSpacing + kAudioLabelHeight + kAudioBottomMargin;
} else if ([self isVideo]) {
return [self ows_adjustBubbleSize:size forImage:self.image];
}

@ -741,24 +741,7 @@ typedef enum : NSUInteger {
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
[self.audioAttachmentPlayer stop];
// reset all audio bars to 0
JSQMessagesCollectionView *collectionView = self.collectionView;
NSInteger num_bubbles = [self collectionView:collectionView numberOfItemsInSection:0];
for (NSInteger i = 0; i < num_bubbles; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
id<OWSMessageData> message = [self messageAtIndexPath:indexPath];
if (message.messageType == TSIncomingMessageAdapter && message.isMediaMessage &&
[message isKindOfClass:[TSVideoAttachmentAdapter class]]) {
TSVideoAttachmentAdapter *msgMedia = (TSVideoAttachmentAdapter *)message.media;
if ([msgMedia isAudio]) {
msgMedia.isPaused = NO;
msgMedia.isAudioPlaying = NO;
[msgMedia setAudioProgressFromFloat:0];
[msgMedia setAudioIconToPlay];
}
}
}
self.audioAttachmentPlayer = nil;
[self cancelReadTimer];
[self saveDraft];

@ -17,7 +17,6 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)isPaused;
- (void)setIsPaused:(BOOL)isPaused;
- (void)setAudioProgressFromFloat:(float)progress;
- (void)setAudioIconToPlay;
- (void)setAudioIconToPause;

@ -17,7 +17,6 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSURL *mediaUrl;
@property (nonatomic, nullable) AVAudioPlayer *audioPlayer;
@property (nonatomic, nullable) NSTimer *audioPlayerPoller;
@end
@ -99,8 +98,6 @@ NS_ASSUME_NONNULL_BEGIN
[ViewControllerUtils setAudioIgnoresHardwareMuteSwitch:YES];
[self.audioPlayerPoller invalidate];
self.delegate.isAudioPlaying = YES;
self.delegate.isPaused = NO;
[self.delegate setAudioIconToPause];
@ -132,9 +129,6 @@ NS_ASSUME_NONNULL_BEGIN
self.delegate.isAudioPlaying = NO;
self.delegate.isPaused = YES;
[self.audioPlayer pause];
[self.audioPlayerPoller invalidate];
double current = [self.audioPlayer currentTime] / [self.audioPlayer duration];
[self.delegate setAudioProgressFromFloat:(float)current];
[self.delegate setAudioIconToPlay];
}
@ -143,8 +137,6 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert([NSThread isMainThread]);
[self.audioPlayer pause];
[self.audioPlayerPoller invalidate];
[self.delegate setAudioProgressFromFloat:0];
[self.delegate setAudioIconToPlay];
self.delegate.isAudioPlaying = NO;
self.delegate.isPaused = NO;
@ -163,17 +155,6 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Events
- (void)audioPlayerUpdated:(NSTimer *)timer
{
OWSAssert([NSThread isMainThread]);
OWSAssert(self.audioPlayer);
OWSAssert(self.audioPlayerPoller);
double current = [self.audioPlayer currentTime] / [self.audioPlayer duration];
[self.delegate setAudioProgressFromFloat:(float)current];
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
OWSAssert([NSThread isMainThread]);

@ -421,9 +421,6 @@
/* Generic error used whenver Signal can't contact the server */
"ERROR_DESCRIPTION_NO_INTERNET" = "Signal was unable to connect to the internet. Please try from another WiFi network or use mobile data.";
/* Error indicating that an outgoing message had no valid recipients. */
"ERROR_DESCRIPTION_NO_VALID_RECIPIENTS" = "Message send failed due to a lack of valid recipients.";
/* Error message when attempting to send message */
"ERROR_DESCRIPTION_SENDING_UNAUTHORIZED" = "Your device is no longer registered for your phone number. You must remove and reinstall Signal.";
@ -667,6 +664,9 @@
/* message footer while attachment is uploading */
"MESSAGE_STATUS_UPLOADING" = "Uploading...";
/* A label for audio attachments of unknown type. */
"MESSAGES_VIEW_AUDIO_TYPE_GENERIC" = "Audio";
/* Indicates that this 1:1 conversation has been blocked. */
"MESSAGES_VIEW_CONTACT_BLOCKED" = "You Blocked this User";

Loading…
Cancel
Save