Compare commits

...

3 Commits

Author SHA1 Message Date
Shadowfacts d7953470e3
Add rudimentary support for audio attachments
Closes #7
2020-01-26 18:50:45 -05:00
Shadowfacts 8c7bebcce8
Fix large image controls being positioned incorrectly on notched-devices
when opening via a context menu preview.

The constraints for the top controls were being set only once, but when
showing a large image in the contxt menu preview window, the top inset
safe area is 0 and didn't become 44 (the value for notched devices)
until the preview was expanded.

Fixes #86
2020-01-26 18:28:46 -05:00
Shadowfacts 20c602f911
Disable row insertion animations 2020-01-26 18:23:18 -05:00
7 changed files with 64 additions and 34 deletions

View File

@ -94,10 +94,12 @@ class BookmarksTableViewController: EnhancedTableViewController {
self.statuses.append(contentsOf: newStatuses.map { ($0.id, .unknown) }) self.statuses.append(contentsOf: newStatuses.map { ($0.id, .unknown) })
DispatchQueue.main.async { DispatchQueue.main.async {
UIView.performWithoutAnimation {
self.tableView.insertRows(at: newIndexPaths, with: .automatic) self.tableView.insertRows(at: newIndexPaths, with: .automatic)
} }
} }
} }
}
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true return true

View File

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

View File

@ -37,8 +37,6 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var bottomControlsView: UIView! @IBOutlet weak var bottomControlsView: UIView!
@IBOutlet weak var descriptionLabel: UILabel! @IBOutlet weak var descriptionLabel: UILabel!
var initializedTopControlsConstrains = false
var image: UIImage? var image: UIImage?
var gifData: Data? var gifData: Data?
var imageDescription: String? var imageDescription: String?
@ -120,8 +118,6 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate {
centerImage() centerImage()
if !initializedTopControlsConstrains {
initializedTopControlsConstrains = true
if view.safeAreaInsets.top == 44 { if view.safeAreaInsets.top == 44 {
// running on iPhone X style notched device // running on iPhone X style notched device
let notchWidth: CGFloat = 209 let notchWidth: CGFloat = 209
@ -131,7 +127,6 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate {
closeButtonTrailingConstraint.constant = offset closeButtonTrailingConstraint.constant = offset
} }
} }
}
func imageForDismissalAnimation() -> UIImage? { func imageForDismissalAnimation() -> UIImage? {
return sourceInfo?.image ?? image return sourceInfo?.image ?? image

View File

@ -143,11 +143,13 @@ class NotificationsTableViewController: EnhancedTableViewController {
self.older = pagination?.older self.older = pagination?.older
DispatchQueue.main.async { DispatchQueue.main.async {
UIView.performWithoutAnimation {
self.tableView.insertRows(at: newIndexPaths, with: .automatic) self.tableView.insertRows(at: newIndexPaths, with: .automatic)
} }
} }
} }
} }
}
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true return true
@ -224,7 +226,9 @@ class NotificationsTableViewController: EnhancedTableViewController {
let newIndexPaths = (0..<groups.count).map { let newIndexPaths = (0..<groups.count).map {
IndexPath(row: $0, section: 0) IndexPath(row: $0, section: 0)
} }
UIView.performWithoutAnimation {
self.tableView.insertRows(at: newIndexPaths, with: .automatic) self.tableView.insertRows(at: newIndexPaths, with: .automatic)
}
self.refreshControl?.endRefreshing() self.refreshControl?.endRefreshing()

View File

@ -106,11 +106,13 @@ class TimelineTableViewController: EnhancedTableViewController {
let newIndexPaths = newRows.map { IndexPath(row: $0, section: self.timelineSegments.count - 1) } let newIndexPaths = newRows.map { IndexPath(row: $0, section: self.timelineSegments.count - 1) }
self.timelineSegments[self.timelineSegments.count - 1].append(contentsOf: newStatuses.map { ($0.id, .unknown) }) self.timelineSegments[self.timelineSegments.count - 1].append(contentsOf: newStatuses.map { ($0.id, .unknown) })
DispatchQueue.main.async { DispatchQueue.main.async {
UIView.performWithoutAnimation {
self.tableView.insertRows(at: newIndexPaths, with: .none) self.tableView.insertRows(at: newIndexPaths, with: .none)
} }
} }
} }
} }
}
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true return true
@ -142,7 +144,9 @@ class TimelineTableViewController: EnhancedTableViewController {
let newIndexPaths = (0..<newStatuses.count).map { let newIndexPaths = (0..<newStatuses.count).map {
IndexPath(row: $0, section: 0) IndexPath(row: $0, section: 0)
} }
UIView.performWithoutAnimation {
self.tableView.insertRows(at: newIndexPaths, with: .automatic) self.tableView.insertRows(at: newIndexPaths, with: .automatic)
}
self.refreshControl?.endRefreshing() self.refreshControl?.endRefreshing()

View File

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

View File

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