Compare commits
4 Commits
6d692c2730
...
7474969969
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 7474969969 | |
Shadowfacts | 319b5458fc | |
Shadowfacts | f7304a011c | |
Shadowfacts | 94dc5d3177 |
|
@ -81,10 +81,7 @@ class ImageCache {
|
||||||
guard !ImageCache.disableCaching else { return }
|
guard !ImageCache.disableCaching else { return }
|
||||||
|
|
||||||
if !((try? cache.has(url.absoluteString)) ?? false) {
|
if !((try? cache.has(url.absoluteString)) ?? false) {
|
||||||
let task = dataTask(url: url) { data, image in
|
let task = dataTask(url: url, completion: nil)
|
||||||
guard let data else { return }
|
|
||||||
try? self.cache.set(url.absoluteString, data: data, image: image)
|
|
||||||
}
|
|
||||||
task.resume()
|
task.resume()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +92,9 @@ class ImageCache {
|
||||||
let data else {
|
let data else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
completion?(data, UIImage(data: data))
|
let image = UIImage(data: data)
|
||||||
|
try? self.cache.set(url.absoluteString, data: data, image: image)
|
||||||
|
completion?(data, image)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,14 +10,30 @@ import UIKit
|
||||||
import AVKit
|
import AVKit
|
||||||
import Pachyderm
|
import Pachyderm
|
||||||
|
|
||||||
class GalleryPlayerViewController: AVPlayerViewController {
|
class GalleryPlayerViewController: UIViewController {
|
||||||
|
|
||||||
|
let playerVC = AVPlayerViewController()
|
||||||
|
|
||||||
var attachment: Attachment!
|
var attachment: Attachment!
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
allowsPictureInPicturePlayback = true
|
view.backgroundColor = .black
|
||||||
|
|
||||||
|
playerVC.allowsPictureInPicturePlayback = true
|
||||||
|
|
||||||
|
playerVC.view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
addChild(playerVC)
|
||||||
|
playerVC.didMove(toParent: self)
|
||||||
|
view.addSubview(playerVC.view)
|
||||||
|
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
playerVC.view.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
|
||||||
|
playerVC.view.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
|
||||||
|
playerVC.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
|
||||||
|
playerVC.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidAppear(_ animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
|
|
|
@ -93,8 +93,8 @@ class GalleryViewController: UIPageViewController, UIPageViewControllerDataSourc
|
||||||
return vc
|
return vc
|
||||||
case .video, .audio:
|
case .video, .audio:
|
||||||
let vc = GalleryPlayerViewController()
|
let vc = GalleryPlayerViewController()
|
||||||
vc.player = AVPlayer(url: attachment.url)
|
vc.playerVC.player = AVPlayer(url: attachment.url)
|
||||||
vc.delegate = avPlayerViewControllerDelegate
|
vc.playerVC.delegate = avPlayerViewControllerDelegate
|
||||||
vc.attachment = attachment
|
vc.attachment = attachment
|
||||||
return vc
|
return vc
|
||||||
case .gifv:
|
case .gifv:
|
||||||
|
|
|
@ -197,7 +197,11 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
|
|
||||||
@objc func refresh() {
|
@objc func refresh() {
|
||||||
Task {
|
Task {
|
||||||
|
if case .notLoadedInitial = await controller.state {
|
||||||
|
await controller.loadInitial()
|
||||||
|
} else {
|
||||||
await controller.loadNewer()
|
await controller.loadNewer()
|
||||||
|
}
|
||||||
#if !targetEnvironment(macCatalyst)
|
#if !targetEnvironment(macCatalyst)
|
||||||
collectionView.refreshControl?.endRefreshing()
|
collectionView.refreshControl?.endRefreshing()
|
||||||
#endif
|
#endif
|
||||||
|
@ -280,6 +284,8 @@ extension TimelineViewController {
|
||||||
typealias TimelineItem = String // status ID
|
typealias TimelineItem = String // status ID
|
||||||
|
|
||||||
func loadInitial() async throws -> [TimelineItem] {
|
func loadInitial() async throws -> [TimelineItem] {
|
||||||
|
try await Task.sleep(nanoseconds: 1 * NSEC_PER_SEC)
|
||||||
|
|
||||||
guard let mastodonController else {
|
guard let mastodonController else {
|
||||||
throw Error.noClient
|
throw Error.noClient
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,14 @@ extension TimelineLikeCollectionViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleAddLoadingIndicator() async {
|
func handleAddLoadingIndicator() async {
|
||||||
|
if case .loadingInitial(_, _) = await controller.state,
|
||||||
|
let refreshControl = collectionView.refreshControl,
|
||||||
|
refreshControl.isRefreshing {
|
||||||
|
refreshControl.beginRefreshing()
|
||||||
|
// if we're loading initial and the refresh control is already going, we don't need to add another indicator
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var snapshot = dataSource.snapshot()
|
var snapshot = dataSource.snapshot()
|
||||||
if !snapshot.sectionIdentifiers.contains(.footer) {
|
if !snapshot.sectionIdentifiers.contains(.footer) {
|
||||||
snapshot.appendSections([.footer])
|
snapshot.appendSections([.footer])
|
||||||
|
@ -77,6 +85,13 @@ extension TimelineLikeCollectionViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleRemoveLoadingIndicator() async {
|
func handleRemoveLoadingIndicator() async {
|
||||||
|
if case .loadingInitial(_, _) = await controller.state,
|
||||||
|
let refreshControl = collectionView.refreshControl,
|
||||||
|
refreshControl.isRefreshing {
|
||||||
|
refreshControl.endRefreshing()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let oldContentOffset = collectionView.contentOffset
|
let oldContentOffset = collectionView.contentOffset
|
||||||
var snapshot = dataSource.snapshot()
|
var snapshot = dataSource.snapshot()
|
||||||
snapshot.deleteSections([.footer])
|
snapshot.deleteSections([.footer])
|
||||||
|
|
|
@ -70,7 +70,7 @@ actor TimelineLikeController<Item> {
|
||||||
} catch {
|
} catch {
|
||||||
await loadingIndicator.end()
|
await loadingIndicator.end()
|
||||||
await emit(event: .loadAllError(error, token))
|
await emit(event: .loadAllError(error, token))
|
||||||
state = .idle
|
state = .notLoadedInitial
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ actor TimelineLikeController<Item> {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
case .loadingInitial(let token, let hasAddedLoadingIndicator):
|
case .loadingInitial(let token, let hasAddedLoadingIndicator):
|
||||||
return to == .idle || (!hasAddedLoadingIndicator && to == .loadingInitial(token, hasAddedLoadingIndicator: true))
|
return to == .notLoadedInitial || to == .idle || (!hasAddedLoadingIndicator && to == .loadingInitial(token, hasAddedLoadingIndicator: true))
|
||||||
case .loadingNewer(_):
|
case .loadingNewer(_):
|
||||||
return to == .idle
|
return to == .idle
|
||||||
case .loadingOlder(let token, let hasAddedLoadingIndicator):
|
case .loadingOlder(let token, let hasAddedLoadingIndicator):
|
||||||
|
|
|
@ -142,6 +142,7 @@ class ProfileHeaderView: UIView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fieldsView.delegate = delegate
|
||||||
fieldsView.updateUI(account: account)
|
fieldsView.updateUI(account: account)
|
||||||
|
|
||||||
accessibilityElements = [
|
accessibilityElements = [
|
||||||
|
|
Loading…
Reference in New Issue