Show attachment upload progress indicators.

This commit is contained in:
Matthew Chen 2018-11-07 12:58:16 -05:00
parent c1a5e1e258
commit a26086b303
4 changed files with 41 additions and 14 deletions

View File

@ -7,6 +7,7 @@
// Separate iOS Frameworks from other imports.
#import "AppSettingsViewController.h"
#import "AttachmentUploadView.h"
#import "ContactCellView.h"
#import "ContactTableViewCell.h"
#import "ConversationViewCell.h"

View File

@ -8,15 +8,18 @@ import Foundation
public class ConversationMediaView: UIView {
private let mediaCache: NSCache<NSString, AnyObject>
private let attachment: TSAttachment
private let isOutgoing: Bool
private var loadBlock : (() -> Void)?
private var unloadBlock : (() -> Void)?
private var didFailToLoad = false
@objc
public required init(mediaCache: NSCache<NSString, AnyObject>,
attachment: TSAttachment) {
attachment: TSAttachment,
isOutgoing: Bool) {
self.mediaCache = mediaCache
self.attachment = attachment
self.isOutgoing = isOutgoing
super.init(frame: .zero)
@ -35,8 +38,6 @@ public class ConversationMediaView: UIView {
AssertIsOnMainThread()
guard let attachmentStream = attachment as? TSAttachmentStream else {
// TODO: Handle this case.
owsFailDebug("Missing attachment stream.")
return
}
if attachmentStream.isAnimated {
@ -51,10 +52,21 @@ public class ConversationMediaView: UIView {
}
}
private func addMediaSubview(_ subview: UIView) {
addSubview(subview)
subview.autoPinEdgesToSuperviewEdges()
// TODO: Possibly add upload/download indicator here.
private func addAttachmentUploadViewIfNecessary(_ subview: UIView,
completion: @escaping (Bool) -> Void) {
guard isOutgoing else {
return
}
guard let attachmentStream = attachment as? TSAttachmentStream else {
return
}
guard !attachmentStream.isUploaded else {
return
}
let uploadView = AttachmentUploadView(attachment: attachmentStream) { (_) in
}
subview.addSubview(uploadView)
uploadView.autoPinEdgesToSuperviewEdges()
}
private func configureForAnimatedImage(attachmentStream: TSAttachmentStream) {
@ -71,7 +83,10 @@ public class ConversationMediaView: UIView {
animatedImageView.layer.minificationFilter = kCAFilterTrilinear
animatedImageView.layer.magnificationFilter = kCAFilterTrilinear
animatedImageView.backgroundColor = Theme.offBackgroundColor
addMediaSubview(animatedImageView)
addSubview(animatedImageView)
animatedImageView.autoPinEdgesToSuperviewEdges()
addAttachmentUploadViewIfNecessary(animatedImageView) { (_) in
}
loadBlock = { [weak self] in
guard let strongSelf = self else {
return
@ -117,7 +132,10 @@ public class ConversationMediaView: UIView {
stillImageView.layer.minificationFilter = kCAFilterTrilinear
stillImageView.layer.magnificationFilter = kCAFilterTrilinear
stillImageView.backgroundColor = Theme.offBackgroundColor
addMediaSubview(stillImageView)
addSubview(stillImageView)
stillImageView.autoPinEdgesToSuperviewEdges()
addAttachmentUploadViewIfNecessary(stillImageView) { (_) in
}
loadBlock = { [weak self] in
guard let strongSelf = self else {
return
@ -162,14 +180,18 @@ public class ConversationMediaView: UIView {
stillImageView.layer.minificationFilter = kCAFilterTrilinear
stillImageView.layer.magnificationFilter = kCAFilterTrilinear
stillImageView.backgroundColor = Theme.offBackgroundColor
addMediaSubview(stillImageView)
// TODO: Hide during upload/download.
let videoPlayIcon = UIImage(named: "play_button")
let videoPlayButton = UIImageView(image: videoPlayIcon)
stillImageView.addSubview(videoPlayButton)
videoPlayButton.autoCenterInSuperview()
addSubview(stillImageView)
stillImageView.autoPinEdgesToSuperviewEdges()
addAttachmentUploadViewIfNecessary(stillImageView) { (isAttachmentReady) in
videoPlayButton.isHidden = !isAttachmentReady
}
loadBlock = { [weak self] in
guard let strongSelf = self else {
return

View File

@ -22,11 +22,13 @@ public class MediaAlbumCellView: UIStackView {
@objc
public required init(mediaCache: NSCache<NSString, AnyObject>,
items: [ConversationMediaAlbumItem],
isOutgoing: Bool,
maxMessageWidth: CGFloat) {
self.items = items
self.itemViews = MediaAlbumCellView.itemsToDisplay(forItems: items).map {
ConversationMediaView(mediaCache: mediaCache,
attachment: $0.attachment)
attachment: $0.attachment,
isOutgoing: isOutgoing)
}
super.init(frame: .zero)

View File

@ -787,6 +787,7 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
OWSMediaAlbumCellView *albumView =
[[OWSMediaAlbumCellView alloc] initWithMediaCache:self.cellMediaCache
items:self.viewItem.mediaAlbumItems
isOutgoing:self.isOutgoing
maxMessageWidth:self.conversationStyle.maxMessageWidth];
self.loadCellContentBlock = ^{
[albumView loadMedia];
@ -803,8 +804,9 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
OWSAssertDebug(self.attachmentStream);
OWSAssertDebug([self.attachmentStream isVisualMedia]);
ConversationMediaView *mediaView =
[[ConversationMediaView alloc] initWithMediaCache:self.cellMediaCache attachment:self.attachmentStream];
ConversationMediaView *mediaView = [[ConversationMediaView alloc] initWithMediaCache:self.cellMediaCache
attachment:self.attachmentStream
isOutgoing:self.isOutgoing];
self.loadCellContentBlock = ^{
[mediaView loadMedia];
};