From 84d6f61d53b992023bb6f76b73366bfa8e1360af Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Nov 2018 11:57:16 -0500 Subject: [PATCH 1/2] Fix glitches in conversation media view. --- .../Cells/ConversationMediaView.swift | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift b/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift index 7e1889f22..11fed8a22 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift +++ b/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift @@ -7,6 +7,12 @@ import Foundation @objc(OWSConversationMediaView) public class ConversationMediaView: UIView { + private enum MediaError { + case missing + case invalid + case failed + } + // MARK: - Dependencies private var attachmentDownloads: OWSAttachmentDownloads { @@ -54,6 +60,10 @@ public class ConversationMediaView: UIView { addDownloadProgressIfNecessary() return } + guard !isFailedDownload else { + configureForMissingOrInvalid(.failed) + return + } if attachmentStream.isAnimated { configureForAnimatedImage(attachmentStream: attachmentStream) } else if attachmentStream.isImage { @@ -61,27 +71,29 @@ public class ConversationMediaView: UIView { } else if attachmentStream.isVideo { configureForVideo(attachmentStream: attachmentStream) } else { - // TODO: Handle this case. owsFailDebug("Attachment has unexpected type.") - configureForMissingOrInvalid() + configureForMissingOrInvalid(.invalid) } } - // private func addDownloadProgressIfNecessary() { + guard !isFailedDownload else { + configureForMissingOrInvalid(.failed) + return + } guard let attachmentPointer = attachment as? TSAttachmentPointer else { owsFailDebug("Attachment has unexpected type.") - configureForMissingOrInvalid() + configureForMissingOrInvalid(.invalid) return } guard let attachmentId = attachmentPointer.uniqueId else { owsFailDebug("Attachment missing unique ID.") - configureForMissingOrInvalid() + configureForMissingOrInvalid(.invalid) return } guard nil != attachmentDownloads.downloadProgress(forAttachmentId: attachmentId) else { // Not being downloaded. - configureForMissingOrInvalid() + configureForMissingOrInvalid(.missing) return } @@ -100,7 +112,7 @@ public class ConversationMediaView: UIView { } guard let attachmentId = attachmentStream.uniqueId else { owsFailDebug("Attachment missing unique ID.") - configureForMissingOrInvalid() + configureForMissingOrInvalid(.invalid) return false } guard !attachmentStream.isUploaded else { @@ -270,25 +282,28 @@ public class ConversationMediaView: UIView { return attachmentPointer.state == .failed } - private func configureForMissingOrInvalid() { + private func configureForMissingOrInvalid(_ error: MediaError) { backgroundColor = UIColor.ows_gray05 let icon: UIImage - if isFailedDownload { - guard let asset = UIImage(named: "media_retry") else { - owsFailDebug("Missing image") - return - } - icon = asset - } else { + switch (error) { + case .failed: + guard let asset = UIImage(named: "media_retry") else { + owsFailDebug("Missing image") + return + } + icon = asset + case .invalid: guard let asset = UIImage(named: "media_invalid") else { owsFailDebug("Missing image") return } icon = asset + case .missing: + return } let iconView = UIImageView(image: icon.withRenderingMode(.alwaysTemplate)) iconView.tintColor = Theme.primaryColor.withAlphaComponent(0.6) - self.addSubview(iconView) + addSubview(iconView) iconView.autoCenterInSuperview() } From 2e50cc1f2d402cc105dfc63546c1ddf8bea9658e Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Nov 2018 13:14:24 -0500 Subject: [PATCH 2/2] Respond to CR. --- .../xcshareddata/xcschemes/Signal.xcscheme | 17 ++++++----- .../Cells/ConversationMediaView.swift | 28 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme b/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme index f5fde70a8..339ee4f4f 100644 --- a/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme +++ b/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme @@ -28,7 +28,7 @@ buildForAnalyzing = "YES"> @@ -56,7 +56,7 @@ skipped = "NO"> @@ -66,7 +66,7 @@ skipped = "NO"> @@ -76,7 +76,7 @@ skipped = "NO"> @@ -86,7 +86,7 @@ skipped = "NO"> @@ -96,7 +96,7 @@ skipped = "NO"> @@ -106,7 +106,7 @@ skipped = "NO"> @@ -136,8 +136,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - enableThreadSanitizer = "YES" - enableUBSanitizer = "YES" + disableMainThreadChecker = "YES" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift b/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift index 11fed8a22..af3702dc2 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift +++ b/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift @@ -61,7 +61,7 @@ public class ConversationMediaView: UIView { return } guard !isFailedDownload else { - configureForMissingOrInvalid(.failed) + configure(forError: .failed) return } if attachmentStream.isAnimated { @@ -72,28 +72,28 @@ public class ConversationMediaView: UIView { configureForVideo(attachmentStream: attachmentStream) } else { owsFailDebug("Attachment has unexpected type.") - configureForMissingOrInvalid(.invalid) + configure(forError: .invalid) } } private func addDownloadProgressIfNecessary() { guard !isFailedDownload else { - configureForMissingOrInvalid(.failed) + configure(forError: .failed) return } guard let attachmentPointer = attachment as? TSAttachmentPointer else { owsFailDebug("Attachment has unexpected type.") - configureForMissingOrInvalid(.invalid) + configure(forError: .invalid) return } guard let attachmentId = attachmentPointer.uniqueId else { owsFailDebug("Attachment missing unique ID.") - configureForMissingOrInvalid(.invalid) + configure(forError: .invalid) return } guard nil != attachmentDownloads.downloadProgress(forAttachmentId: attachmentId) else { // Not being downloaded. - configureForMissingOrInvalid(.missing) + configure(forError: .missing) return } @@ -112,7 +112,7 @@ public class ConversationMediaView: UIView { } guard let attachmentId = attachmentStream.uniqueId else { owsFailDebug("Attachment missing unique ID.") - configureForMissingOrInvalid(.invalid) + configure(forError: .invalid) return false } guard !attachmentStream.isUploaded else { @@ -282,16 +282,16 @@ public class ConversationMediaView: UIView { return attachmentPointer.state == .failed } - private func configureForMissingOrInvalid(_ error: MediaError) { + private func configure(forError error: MediaError) { backgroundColor = UIColor.ows_gray05 let icon: UIImage switch (error) { - case .failed: - guard let asset = UIImage(named: "media_retry") else { - owsFailDebug("Missing image") - return - } - icon = asset + case .failed: + guard let asset = UIImage(named: "media_retry") else { + owsFailDebug("Missing image") + return + } + icon = asset case .invalid: guard let asset = UIImage(named: "media_invalid") else { owsFailDebug("Missing image")