forked from shadowfacts/Tusker
parent
8c7bebcce8
commit
d7953470e3
|
@ -52,7 +52,7 @@ class GalleryViewController: UIPageViewController, UIPageViewControllerDataSourc
|
||||||
switch $0.kind {
|
switch $0.kind {
|
||||||
case .image:
|
case .image:
|
||||||
return AttachmentViewController(attachment: $0)
|
return AttachmentViewController(attachment: $0)
|
||||||
case .video:
|
case .video, .audio:
|
||||||
let vc = AVPlayerViewController()
|
let vc = AVPlayerViewController()
|
||||||
vc.player = AVPlayer(url: $0.url)
|
vc.player = AVPlayer(url: $0.url)
|
||||||
return vc
|
return vc
|
||||||
|
|
|
@ -19,7 +19,7 @@ class AttachmentView: UIImageView, GIFAnimatable {
|
||||||
|
|
||||||
weak var delegate: AttachmentViewDelegate?
|
weak var delegate: AttachmentViewDelegate?
|
||||||
|
|
||||||
var playImageView: UIImageView!
|
var playImageView: UIImageView?
|
||||||
|
|
||||||
var attachment: Attachment!
|
var attachment: Attachment!
|
||||||
var index: Int!
|
var index: Int!
|
||||||
|
@ -54,25 +54,21 @@ class AttachmentView: UIImageView, GIFAnimatable {
|
||||||
isUserInteractionEnabled = true
|
isUserInteractionEnabled = true
|
||||||
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imagePressed)))
|
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imagePressed)))
|
||||||
|
|
||||||
playImageView = UIImageView(image: UIImage(systemName: "play.circle.fill"))
|
|
||||||
playImageView.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
addSubview(playImageView)
|
|
||||||
NSLayoutConstraint.activate([
|
|
||||||
playImageView.widthAnchor.constraint(equalToConstant: 50),
|
|
||||||
playImageView.heightAnchor.constraint(equalToConstant: 50),
|
|
||||||
playImageView.centerXAnchor.constraint(equalTo: centerXAnchor),
|
|
||||||
playImageView.centerYAnchor.constraint(equalTo: centerYAnchor)
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadAttachment() {
|
func loadAttachment() {
|
||||||
|
guard AttachmentsContainerView.supportedAttachmentTypes.contains(attachment.kind) else {
|
||||||
|
preconditionFailure("invalid attachment type")
|
||||||
|
}
|
||||||
switch attachment.kind {
|
switch attachment.kind {
|
||||||
case .image:
|
case .image:
|
||||||
loadImage()
|
loadImage()
|
||||||
case .video:
|
case .video:
|
||||||
loadVideo()
|
loadVideo()
|
||||||
|
case .audio:
|
||||||
|
loadAudio()
|
||||||
default:
|
default:
|
||||||
fatalError()
|
preconditionFailure("invalid attachment type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,8 +85,6 @@ class AttachmentView: UIImageView, GIFAnimatable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
playImageView.isHidden = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadVideo() {
|
func loadVideo() {
|
||||||
|
@ -106,7 +100,36 @@ class AttachmentView: UIImageView, GIFAnimatable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
playImageView.isHidden = false
|
let playImageView = UIImageView(image: UIImage(systemName: "play.circle.fill"))
|
||||||
|
playImageView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
addSubview(playImageView)
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
playImageView.widthAnchor.constraint(equalToConstant: 50),
|
||||||
|
playImageView.heightAnchor.constraint(equalToConstant: 50),
|
||||||
|
playImageView.centerXAnchor.constraint(equalTo: centerXAnchor),
|
||||||
|
playImageView.centerYAnchor.constraint(equalTo: centerYAnchor),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadAudio() {
|
||||||
|
let label = UILabel()
|
||||||
|
label.text = "Audio Only"
|
||||||
|
let playImageView = UIImageView(image: UIImage(systemName: "play.circle.fill"))
|
||||||
|
let stack = UIStackView(arrangedSubviews: [
|
||||||
|
label,
|
||||||
|
playImageView
|
||||||
|
])
|
||||||
|
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
stack.axis = .vertical
|
||||||
|
stack.spacing = 8
|
||||||
|
stack.alignment = .center
|
||||||
|
addSubview(stack)
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
stack.centerXAnchor.constraint(equalTo: centerXAnchor),
|
||||||
|
stack.centerYAnchor.constraint(equalTo: centerYAnchor),
|
||||||
|
playImageView.widthAnchor.constraint(equalToConstant: 50),
|
||||||
|
playImageView.heightAnchor.constraint(equalToConstant: 50),
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
override func display(_ layer: CALayer) {
|
override func display(_ layer: CALayer) {
|
||||||
|
|
|
@ -11,6 +11,8 @@ import Pachyderm
|
||||||
|
|
||||||
class AttachmentsContainerView: UIView {
|
class AttachmentsContainerView: UIView {
|
||||||
|
|
||||||
|
static let supportedAttachmentTypes = [Attachment.Kind.image, .video, .audio]
|
||||||
|
|
||||||
weak var delegate: AttachmentViewDelegate?
|
weak var delegate: AttachmentViewDelegate?
|
||||||
|
|
||||||
var statusID: String!
|
var statusID: String!
|
||||||
|
@ -47,7 +49,7 @@ class AttachmentsContainerView: UIView {
|
||||||
|
|
||||||
func updateUI(status: Status) {
|
func updateUI(status: Status) {
|
||||||
self.statusID = status.id
|
self.statusID = status.id
|
||||||
attachments = status.attachments.filter { $0.kind == .image || $0.kind == .video }
|
attachments = status.attachments.filter { AttachmentsContainerView.supportedAttachmentTypes.contains($0.kind) }
|
||||||
|
|
||||||
attachmentViews.allObjects.forEach { $0.removeFromSuperview() }
|
attachmentViews.allObjects.forEach { $0.removeFromSuperview() }
|
||||||
attachmentViews.removeAllObjects()
|
attachmentViews.removeAllObjects()
|
||||||
|
|
Loading…
Reference in New Issue