Fix size of message previews.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-10-24 12:58:24 -04:00
parent 9ff1577407
commit 722fc4d7a7
5 changed files with 37 additions and 223 deletions

View File

@ -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 = "<group>"; };
34B3F8361E8DF1700035BE1A /* AdvancedSettingsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdvancedSettingsTableViewController.h; sourceTree = "<group>"; };
34B3F8371E8DF1700035BE1A /* AdvancedSettingsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AdvancedSettingsTableViewController.m; sourceTree = "<group>"; };
34B3F8381E8DF1700035BE1A /* AttachmentApprovalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttachmentApprovalViewController.swift; sourceTree = "<group>"; };
34B3F8391E8DF1700035BE1A /* AttachmentSharing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AttachmentSharing.h; sourceTree = "<group>"; };
34B3F83A1E8DF1700035BE1A /* AttachmentSharing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AttachmentSharing.m; sourceTree = "<group>"; };
34B3F83B1E8DF1700035BE1A /* CallViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallViewController.swift; sourceTree = "<group>"; };
@ -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 */,

View File

@ -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?()
})
}
}

View File

@ -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];

View File

@ -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()
}
}
@ -36,6 +42,7 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate {
@available(*, unavailable, message:"use attachment: constructor instead.")
required init?(coder aDecoder: NSCoder) {
self.mode = .large
self.attachment = SignalAttachment.empty()
super.init(coder: aDecoder)
owsFail("\(self.TAG) invalid constructor")
@ -43,8 +50,9 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate {
createViews()
}
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 +103,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 +114,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 +152,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)
@ -250,7 +262,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 +289,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 +348,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 +375,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() {

View File

@ -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)