From 9ce6bd566ff3231f65e864f5bf33559827111ff4 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 22 Aug 2024 13:33:02 -0400 Subject: [PATCH] Show errors when video loading fails Closes #532 --- .../VideoGalleryContentViewController.swift | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Tusker/Screens/Gallery/VideoGalleryContentViewController.swift b/Tusker/Screens/Gallery/VideoGalleryContentViewController.swift index c693b888..2549b224 100644 --- a/Tusker/Screens/Gallery/VideoGalleryContentViewController.swift +++ b/Tusker/Screens/Gallery/VideoGalleryContentViewController.swift @@ -116,12 +116,45 @@ class VideoGalleryContentViewController: UIViewController, GalleryContentViewCon MainActor.runUnsafely { if item.status == .readyToPlay { self.container?.setGalleryContentLoading(false) - statusObservation = nil + self.statusObservation = nil + } else if item.status == .failed, + let error = item.error { + self.container?.setGalleryContentLoading(false) + self.showErrorView(error) + self.statusObservation = nil } } }) } + private func showErrorView(_ error: any Error) { + let image = UIImageView(image: UIImage(systemName: "exclamationmark.triangle.fill")!) + image.tintColor = .secondaryLabel + image.contentMode = .scaleAspectFit + + let label = UILabel() + label.text = "Error Loading" + label.font = .preferredFont(forTextStyle: .title1).withTraits(.traitBold)! + label.textColor = .secondaryLabel + label.adjustsFontForContentSizeCategory = true + + let stackView = UIStackView(arrangedSubviews: [ + image, + label, + ]) + stackView.translatesAutoresizingMaskIntoConstraints = false + stackView.axis = .vertical + stackView.alignment = .center + stackView.spacing = 8 + view.addSubview(stackView) + NSLayoutConstraint.activate([ + image.widthAnchor.constraint(equalToConstant: 64), + image.heightAnchor.constraint(equalToConstant: 64), + stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor), + stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor), + ]) + } + @objc private func preferencesChanged() { if isGrayscale != Preferences.shared.grayscaleImages { let isPlaying = player.rate > 0