diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index dbb6fba7d..dd343bb13 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -33,7 +33,6 @@ 3497DBEF1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEE1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m */; }; 34B3F8711E8DF1700035BE1A /* AboutTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8351E8DF1700035BE1A /* AboutTableViewController.m */; }; 34B3F8721E8DF1700035BE1A /* AdvancedSettingsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8371E8DF1700035BE1A /* AdvancedSettingsTableViewController.m */; }; - 34B3F8731E8DF1700035BE1A /* AttachmentApprovalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8381E8DF1700035BE1A /* AttachmentApprovalViewController.swift */; }; 34B3F8741E8DF1700035BE1A /* AttachmentSharing.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F83A1E8DF1700035BE1A /* AttachmentSharing.m */; }; 34B3F8751E8DF1700035BE1A /* CallViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F83B1E8DF1700035BE1A /* CallViewController.swift */; }; 34B3F8761E8DF1700035BE1A /* CodeVerificationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F83D1E8DF1700035BE1A /* CodeVerificationViewController.m */; }; @@ -445,7 +444,6 @@ 34B3F8351E8DF1700035BE1A /* AboutTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AboutTableViewController.m; sourceTree = ""; }; 34B3F8361E8DF1700035BE1A /* AdvancedSettingsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdvancedSettingsTableViewController.h; sourceTree = ""; }; 34B3F8371E8DF1700035BE1A /* AdvancedSettingsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AdvancedSettingsTableViewController.m; sourceTree = ""; }; - 34B3F8381E8DF1700035BE1A /* AttachmentApprovalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttachmentApprovalViewController.swift; sourceTree = ""; }; 34B3F8391E8DF1700035BE1A /* AttachmentSharing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AttachmentSharing.h; sourceTree = ""; }; 34B3F83A1E8DF1700035BE1A /* AttachmentSharing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AttachmentSharing.m; sourceTree = ""; }; 34B3F83B1E8DF1700035BE1A /* CallViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallViewController.swift; sourceTree = ""; }; @@ -991,7 +989,6 @@ 34B3F8371E8DF1700035BE1A /* AdvancedSettingsTableViewController.m */, 34B3F8681E8DF1700035BE1A /* AppSettingsViewController.h */, 34B3F8691E8DF1700035BE1A /* AppSettingsViewController.m */, - 34B3F8381E8DF1700035BE1A /* AttachmentApprovalViewController.swift */, 34B3F8391E8DF1700035BE1A /* AttachmentSharing.h */, 34B3F83A1E8DF1700035BE1A /* AttachmentSharing.m */, 34D5CCA71EAE3D30005515DB /* AvatarViewHelper.h */, @@ -2356,7 +2353,6 @@ 34B3F8891E8DF1700035BE1A /* OWSConversationSettingsViewController.m in Sources */, 34C42D671F4734ED0072EC04 /* TSUnreadIndicatorInteraction.m in Sources */, 34B3F87E1E8DF1700035BE1A /* InboxTableViewCell.m in Sources */, - 34B3F8731E8DF1700035BE1A /* AttachmentApprovalViewController.swift in Sources */, B6B1013C196D213F007E3930 /* SignalKeyingStorage.m in Sources */, 34D5CC961EA6AFAD005515DB /* OWSContactsSyncing.m in Sources */, 45E2E9201E153B3D00457AA0 /* Strings.swift in Sources */, diff --git a/Signal/src/Signal-Bridging-Header.h b/Signal/src/Signal-Bridging-Header.h index 206a1d4c2..1e2d2ecc1 100644 --- a/Signal/src/Signal-Bridging-Header.h +++ b/Signal/src/Signal-Bridging-Header.h @@ -5,10 +5,12 @@ #import "AppSettingsViewController.h" #import "AttachmentSharing.h" #import "ContactTableViewCell.h" +#import "ConversationViewItem.h" #import "DateUtil.h" #import "DebugUIPage.h" #import "Environment.h" #import "FingerprintViewController.h" +#import "FullImageViewController.h" #import "HomeViewController.h" #import "NSString+OWS.h" #import "NotificationsManager.h" diff --git a/Signal/src/ViewControllers/AttachmentApprovalViewController.swift b/Signal/src/ViewControllers/AttachmentApprovalViewController.swift deleted file mode 100644 index 06bdf2ec9..000000000 --- a/Signal/src/ViewControllers/AttachmentApprovalViewController.swift +++ /dev/null @@ -1,178 +0,0 @@ -// -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. -// - -import Foundation -import MediaPlayer - -class AttachmentApprovalViewController: OWSViewController { - - let TAG = "[AttachmentApprovalViewController]" - - // MARK: Properties - - let attachment: SignalAttachment - - var successCompletion : (() -> Void)? - - let mediaMessageView: MediaMessageView - - // MARK: Initializers - - @available(*, unavailable, message:"use attachment: constructor instead.") - required init?(coder aDecoder: NSCoder) { - self.attachment = SignalAttachment.empty() - self.mediaMessageView = MediaMessageView(attachment:attachment) - super.init(coder: aDecoder) - owsFail("\(self.TAG) invalid constructor") - } - - required init(attachment: SignalAttachment, successCompletion : @escaping () -> Void) { - assert(!attachment.hasError) - self.attachment = attachment - self.successCompletion = successCompletion - self.mediaMessageView = MediaMessageView(attachment:attachment) - super.init(nibName: nil, bundle: nil) - } - - // MARK: View Lifecycle - - override func viewDidLoad() { - super.viewDidLoad() - - view.backgroundColor = UIColor.white - - self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem:.stop, - target:self, - action:#selector(donePressed)) - createViews() - - self.navigationItem.title = dialogTitle() - } - - private func dialogTitle() -> String { - guard let filename = mediaMessageView.formattedFileName() else { - return NSLocalizedString("ATTACHMENT_APPROVAL_DIALOG_TITLE", - comment: "Title for the 'attachment approval' dialog.") - } - return filename - } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - - mediaMessageView.viewWillAppear(animated) - } - - override func viewWillDisappear(_ animated: Bool) { - super.viewWillDisappear(animated) - - mediaMessageView.viewWillDisappear(animated) - } - - // MARK: - Create Views - - private func createViews() { - let previewTopMargin: CGFloat = 30 - let previewHMargin: CGFloat = 20 - - self.view.addSubview(mediaMessageView) - mediaMessageView.autoPinWidthToSuperview(withMargin:previewHMargin) - mediaMessageView.autoPin(toTopLayoutGuideOf: self, withInset:previewTopMargin) - - createButtonRow(mediaMessageView:mediaMessageView) - } - - private func wrapViewsInVerticalStack(subviews: [UIView]) -> UIView { - assert(subviews.count > 0) - - let stackView = UIView() - - var lastView: UIView? - for subview in subviews { - - stackView.addSubview(subview) - subview.autoHCenterInSuperview() - - if lastView == nil { - subview.autoPinEdge(toSuperviewEdge:.top) - } else { - subview.autoPinEdge(.top, to:.bottom, of:lastView!, withOffset:10) - } - - lastView = subview - } - - lastView?.autoPinEdge(toSuperviewEdge:.bottom) - - return stackView - } - - private func createButtonRow(mediaMessageView: UIView) { - let buttonTopMargin = ScaleFromIPhone5To7Plus(30, 40) - let buttonBottomMargin = ScaleFromIPhone5To7Plus(25, 40) - let buttonHSpacing = ScaleFromIPhone5To7Plus(20, 30) - - let buttonRow = UIView() - self.view.addSubview(buttonRow) - buttonRow.autoPinWidthToSuperview() - buttonRow.autoPinEdge(toSuperviewEdge:.bottom, withInset:buttonBottomMargin) - buttonRow.autoPinEdge(.top, to:.bottom, of:mediaMessageView, withOffset:buttonTopMargin) - - // We use this invisible subview to ensure that the buttons are centered - // horizontally. - let buttonSpacer = UIView() - buttonRow.addSubview(buttonSpacer) - // Vertical positioning of this view doesn't matter. - buttonSpacer.autoPinEdge(toSuperviewEdge:.top) - buttonSpacer.autoSetDimension(.width, toSize:buttonHSpacing) - buttonSpacer.autoHCenterInSuperview() - - let cancelButton = createButton(title: CommonStrings.cancelButton, - color : UIColor.ows_destructiveRed(), - action: #selector(cancelPressed)) - buttonRow.addSubview(cancelButton) - cancelButton.autoPinEdge(toSuperviewEdge:.top) - cancelButton.autoPinEdge(toSuperviewEdge:.bottom) - cancelButton.autoPinEdge(.right, to:.left, of:buttonSpacer) - - let sendButton = createButton(title: NSLocalizedString("ATTACHMENT_APPROVAL_SEND_BUTTON", - comment: "Label for 'send' button in the 'attachment approval' dialog."), - color : UIColor(rgbHex:0x2ecc71), - action: #selector(sendPressed)) - buttonRow.addSubview(sendButton) - sendButton.autoPinEdge(toSuperviewEdge:.top) - sendButton.autoPinEdge(toSuperviewEdge:.bottom) - sendButton.autoPinEdge(.left, to:.right, of:buttonSpacer) - } - - private func createButton(title: String, color: UIColor, action: Selector) -> UIView { - let buttonWidth = ScaleFromIPhone5To7Plus(110, 140) - let buttonHeight = ScaleFromIPhone5To7Plus(35, 45) - - return OWSFlatButton.button(title:title, - titleColor:UIColor.white, - backgroundColor:color, - width:buttonWidth, - height:buttonHeight, - target:target, - selector:action) - } - - // MARK: - Event Handlers - - func donePressed(sender: UIButton) { - dismiss(animated: true, completion:nil) - } - - func cancelPressed(sender: UIButton) { - dismiss(animated: true, completion:nil) - } - - func sendPressed(sender: UIButton) { - let successCompletion = self.successCompletion - dismiss(animated: true, completion: { - successCompletion?() - }) - } -} diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m index 596ecb28b..f9c0a60ff 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m @@ -241,7 +241,7 @@ static void *kConversationInputTextViewObservingContext = &kConversationInputTex [self.attachmentView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:textViewVInset], [self.attachmentView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:textViewVInset], [self.attachmentView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:contentHInset], - [self.attachmentView autoSetDimension:ALDimensionHeight toSize:300.f], + [self.attachmentView autoSetDimension:ALDimensionHeight toSize:150.f], [self.rightButtonWrapper autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:self.attachmentView], [self.rightButtonWrapper autoPinEdgeToSuperviewEdge:ALEdgeRight], @@ -714,7 +714,8 @@ static void *kConversationInputTextViewObservingContext = &kConversationInputTex self.attachmentToApprove = attachment; - MediaMessageView *attachmentView = [[MediaMessageView alloc] initWithAttachment:attachment]; + MediaMessageView *attachmentView = + [[MediaMessageView alloc] initWithAttachment:attachment mode:MediaMessageViewModeSmall]; self.attachmentView = attachmentView; [self.contentView addSubview:attachmentView]; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 8024b1dd9..a39f619c3 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -1946,8 +1946,9 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { UIWindow *window = [UIApplication sharedApplication].keyWindow; CGRect convertedRect = [imageView convertRect:imageView.bounds toView:window]; - FullImageViewController *vc = - [[FullImageViewController alloc] initWithAttachment:attachmentStream fromRect:convertedRect viewItem:viewItem]; + FullImageViewController *vc = [[FullImageViewController alloc] initWithAttachmentStream:attachmentStream + fromRect:convertedRect + viewItem:viewItem]; [vc presentFromViewController:self]; } diff --git a/Signal/src/ViewControllers/FullImageViewController.h b/Signal/src/ViewControllers/FullImageViewController.h index b6edff4eb..6ade09366 100644 --- a/Signal/src/ViewControllers/FullImageViewController.h +++ b/Signal/src/ViewControllers/FullImageViewController.h @@ -7,13 +7,17 @@ NS_ASSUME_NONNULL_BEGIN @class ConversationViewItem; +@class SignalAttachment; @class TSAttachmentStream; @interface FullImageViewController : OWSViewController -- (instancetype)initWithAttachment:(TSAttachmentStream *)attachmentStream - fromRect:(CGRect)rect - viewItem:(ConversationViewItem *)viewItem; +// If viewItem is non-null, long press will show a menu controller. +- (instancetype)initWithAttachmentStream:(TSAttachmentStream *)attachmentStream + fromRect:(CGRect)rect + viewItem:(ConversationViewItem *_Nullable)viewItem; + +- (instancetype)initWithAttachment:(SignalAttachment *)attachment fromRect:(CGRect)rect; - (void)presentFromViewController:(UIViewController *)viewController; diff --git a/Signal/src/ViewControllers/FullImageViewController.m b/Signal/src/ViewControllers/FullImageViewController.m index 7309bf204..6b92c03bd 100644 --- a/Signal/src/ViewControllers/FullImageViewController.m +++ b/Signal/src/ViewControllers/FullImageViewController.m @@ -5,6 +5,7 @@ #import "FullImageViewController.h" #import "AttachmentSharing.h" #import "ConversationViewItem.h" +#import "Signal-Swift.h" #import "TSAttachmentStream.h" #import "TSInteraction.h" #import "UIColor+OWS.h" @@ -56,8 +57,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) BOOL isPresenting; @property (nonatomic) NSData *fileData; -@property (nonatomic) TSAttachmentStream *attachmentStream; -@property (nonatomic) ConversationViewItem *viewItem; +@property (nonatomic, nullable) TSAttachmentStream *attachmentStream; +@property (nonatomic, nullable) SignalAttachment *attachment; +@property (nonatomic, nullable) ConversationViewItem *viewItem; @property (nonatomic) UIToolbar *footerBar; @@ -65,10 +67,9 @@ NS_ASSUME_NONNULL_BEGIN @implementation FullImageViewController - -- (instancetype)initWithAttachment:(TSAttachmentStream *)attachmentStream - fromRect:(CGRect)rect - viewItem:(ConversationViewItem *)viewItem +- (instancetype)initWithAttachmentStream:(TSAttachmentStream *)attachmentStream + fromRect:(CGRect)rect + viewItem:(ConversationViewItem *_Nullable)viewItem { self = [super initWithNibName:nil bundle:nil]; @@ -77,14 +78,65 @@ NS_ASSUME_NONNULL_BEGIN self.attachmentStream = attachmentStream; self.originRect = rect; self.viewItem = viewItem; - self.fileData = [NSData dataWithContentsOfURL:[attachmentStream mediaURL]]; } return self; } +- (instancetype)initWithAttachment:(SignalAttachment *)attachment fromRect:(CGRect)rect +{ + + self = [super initWithNibName:nil bundle:nil]; + + if (self) { + self.attachment = attachment; + self.originRect = rect; + } + + return self; +} + +- (NSURL *_Nullable)attachmentUrl +{ + if (self.attachmentStream) { + return self.attachmentStream.mediaURL; + } else if (self.attachment) { + return self.attachment.dataUrl; + } else { + return nil; + } +} + +- (NSData *)fileData +{ + if (!_fileData) { + NSURL *_Nullable url = self.attachmentUrl; + if (url) { + _fileData = [NSData dataWithContentsOfURL:url]; + } + } + return _fileData; +} + - (UIImage *)image { - return self.attachmentStream.image; + if (self.attachmentStream) { + return self.attachmentStream.image; + } else if (self.attachment) { + return self.attachment.image; + } else { + return nil; + } +} + +- (BOOL)isAnimated +{ + if (self.attachmentStream) { + return self.attachmentStream.isAnimated; + } else if (self.attachment) { + return self.attachment.isAnimatedImage; + } else { + return NO; + } } - (void)loadView { @@ -150,7 +202,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)shareWasPressed:(id)sender { DDLogInfo(@"%@: sharing image.", self.tag); - [AttachmentSharing showShareUIForURL:[self.attachmentStream mediaURL]]; + [AttachmentSharing showShareUIForURL:self.attachmentUrl]; } - (void)initializeScrollView { @@ -162,13 +214,6 @@ NS_ASSUME_NONNULL_BEGIN [self.contentView addSubview:self.scrollView]; } -- (BOOL)isAnimated -{ - OWSAssert(self.attachmentStream); - - return self.attachmentStream.isAnimated; -} - - (void)initializeImageView { if (self.isAnimated) { if ([self.fileData ows_isValidImage]) { @@ -249,6 +294,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)longPressGesture:(UIGestureRecognizer *)sender { // We "eagerly" respond when the long press begins, not when it ends. if (sender.state == UIGestureRecognizerStateBegan) { + if (!self.viewItem) { + return; + } [self.view becomeFirstResponder]; diff --git a/Signal/src/ViewControllers/MediaMessageView.swift b/Signal/src/ViewControllers/MediaMessageView.swift index 2449d6b00..5f4fdd20b 100644 --- a/Signal/src/ViewControllers/MediaMessageView.swift +++ b/Signal/src/ViewControllers/MediaMessageView.swift @@ -5,24 +5,30 @@ import Foundation import MediaPlayer +@objc +enum MediaMessageViewMode: UInt { + case large + case small +} + class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { let TAG = "[MediaMessageView]" // MARK: Properties + let mode: MediaMessageViewMode + let attachment: SignalAttachment var videoPlayer: MPMoviePlayerController? var audioPlayer: OWSAudioAttachmentPlayer? - var audioStatusLabel: UILabel? var audioPlayButton: UIButton? var playbackState = AudioPlaybackState.stopped { didSet { AssertIsOnMainThread() - updateAudioStatusLabel() ensureButtonState() } } @@ -34,17 +40,14 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { // MARK: Initializers - @available(*, unavailable, message:"use attachment: constructor instead.") + @available(*, unavailable, message:"use other constructor instead.") required init?(coder aDecoder: NSCoder) { - self.attachment = SignalAttachment.empty() - super.init(coder: aDecoder) - owsFail("\(self.TAG) invalid constructor") - - createViews() + fatalError("\(#function) is unimplemented.") } - required init(attachment: SignalAttachment) { + required init(attachment: SignalAttachment, mode: MediaMessageViewMode) { assert(!attachment.hasError) + self.mode = mode self.attachment = attachment super.init(frame: CGRect.zero) @@ -95,7 +98,7 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { if lastView == nil { subview.autoPinEdge(toSuperviewEdge: .top) } else { - subview.autoPinEdge(.top, to: .bottom, of: lastView!, withOffset: 10) + subview.autoPinEdge(.top, to: .bottom, of: lastView!, withOffset: stackSpacing()) } lastView = subview @@ -106,6 +109,15 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { return stackView } + private func stackSpacing() -> CGFloat { + switch mode { + case .large: + return CGFloat(10) + case .small: + return CGFloat(5) + } + } + private func createAudioPreview() { guard let dataUrl = attachment.dataUrl else { createGenericPreview() @@ -135,11 +147,6 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { let fileSizeLabel = createFileSizeLabel() subviews.append(fileSizeLabel) - let audioStatusLabel = createAudioStatusLabel() - self.audioStatusLabel = audioStatusLabel - updateAudioStatusLabel() - subviews.append(audioStatusLabel) - let stackView = wrapViewsInVerticalStack(subviews: subviews) self.addSubview(stackView) fileNameLabel?.autoPinWidthToSuperview(withMargin: 32) @@ -169,6 +176,9 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { let aspectRatio = image.size.width / image.size.height addSubviewWithScaleAspectFitLayout(view:animatedImageView, aspectRatio:aspectRatio) contentView = animatedImageView + + animatedImageView.isUserInteractionEnabled = true + animatedImageView.addGestureRecognizer(UITapGestureRecognizer(target:self, action:#selector(imageTapped))) } private func addSubviewWithScaleAspectFitLayout(view: UIView, aspectRatio: CGFloat) { @@ -200,6 +210,9 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { let aspectRatio = image.size.width / image.size.height addSubviewWithScaleAspectFitLayout(view:imageView, aspectRatio:aspectRatio) contentView = imageView + + imageView.isUserInteractionEnabled = true + imageView.addGestureRecognizer(UITapGestureRecognizer(target:self, action:#selector(imageTapped))) } private func createVideoPreview() { @@ -250,7 +263,12 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { } private func createHeroViewSize() -> CGFloat { - return ScaleFromIPhone5To7Plus(175, 225) + switch mode { + case .large: + return ScaleFromIPhone5To7Plus(175, 225) + case .small: + return ScaleFromIPhone5To7Plus(80, 80) + } } private func createHeroImageView(imageName: String) -> UIView { @@ -272,7 +290,12 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { } private func labelFont() -> UIFont { - return UIFont.ows_regularFont(withSize: ScaleFromIPhone5To7Plus(18, 24)) + switch mode { + case .large: + return UIFont.ows_regularFont(withSize: ScaleFromIPhone5To7Plus(18, 24)) + case .small: + return UIFont.ows_regularFont(withSize: ScaleFromIPhone5To7Plus(14, 14)) + } } private func formattedFileExtension() -> String? { @@ -326,15 +349,6 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { return label } - private func createAudioStatusLabel() -> UILabel { - let label = UILabel() - label.textColor = UIColor.ows_materialBlue() - label.font = labelFont() - label.textAlignment = .center - - return label - } - // MARK: - Event Handlers func audioPlayButtonPressed(sender: UIButton) { @@ -362,24 +376,6 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { public func setAudioProgress(_ progress: CGFloat, duration: CGFloat) { audioProgressSeconds = progress audioDurationSeconds = duration - - updateAudioStatusLabel() - } - - private func updateAudioStatusLabel() { - guard let audioStatusLabel = self.audioStatusLabel else { - owsFail("Missing audio status label") - return - } - - let isAudioPlaying = playbackState == .playing - if isAudioPlaying && audioProgressSeconds > 0 && audioDurationSeconds > 0 { - audioStatusLabel.text = String(format: "%@ / %@", - ViewControllerUtils.formatDurationSeconds(Int(round(self.audioProgressSeconds))), - ViewControllerUtils.formatDurationSeconds(Int(round(self.audioDurationSeconds)))) - } else { - audioStatusLabel.text = " " - } } private func setAudioIconToPlay() { @@ -396,13 +392,44 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { audioPlayButton?.imageView?.tintColor = UIColor.ows_materialBlue() } + // MARK: - Full Screen Image + + func imageTapped(sender: UIGestureRecognizer) { + guard sender.state == .recognized else { + return + } + guard let fromView = sender.view else { + return + } + guard let fromViewController = fromViewController() else { + return + } + let window = UIApplication.shared.keyWindow + let convertedRect = fromView.convert(fromView.bounds, to:window) + let viewController = FullImageViewController(attachment:attachment, from:convertedRect) + viewController.present(from:fromViewController) + } + + private func fromViewController() -> UIViewController? { + var responder: UIResponder? = self + while true { + if responder == nil { + return nil + } + if let viewController = responder as? UIViewController { + return viewController + } + responder = responder?.next + } + } + // MARK: - Video Playback func videoTapped(sender: UIGestureRecognizer) { - guard let dataUrl = attachment.dataUrl else { + guard sender.state == .recognized else { return } - guard sender.state == .recognized else { + guard let dataUrl = attachment.dataUrl else { return } guard let videoPlayer = MPMoviePlayerController(contentURL: dataUrl) else { diff --git a/Signal/src/ViewControllers/MessageMetadataViewController.swift b/Signal/src/ViewControllers/MessageMetadataViewController.swift index 1becce99b..ac52c911f 100644 --- a/Signal/src/ViewControllers/MessageMetadataViewController.swift +++ b/Signal/src/ViewControllers/MessageMetadataViewController.swift @@ -382,7 +382,7 @@ class MessageMetadataViewController: OWSViewController { let contentType = attachment.contentType if let dataUTI = MIMETypeUtil.utiType(forMIMEType: contentType) { let attachment = SignalAttachment(dataSource: dataSource, dataUTI: dataUTI) - let mediaMessageView = MediaMessageView(attachment: attachment) + let mediaMessageView = MediaMessageView(attachment: attachment, mode: .small) mediaMessageView.backgroundColor = UIColor.white self.mediaMessageView = mediaMessageView rows.append(mediaMessageView)