Alert image loading errors

This commit is contained in:
Justin Mazzocchi 2021-03-04 19:26:57 -08:00
parent 7a28cf90b0
commit b148930801
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
2 changed files with 22 additions and 1 deletions

View File

@ -162,6 +162,7 @@
"identities.browsing" = "Browsing"; "identities.browsing" = "Browsing";
"identities.log-out" = "Log out"; "identities.log-out" = "Log out";
"identities.pending" = "Pending"; "identities.pending" = "Pending";
"image-error.unable-to-load" = "Unable to load image";
"lists.new-list-title" = "New List Title"; "lists.new-list-title" = "New List Title";
"load-more" = "Load More"; "load-more" = "Load More";
"load-more.above.accessibility.post" = "Load from post above"; "load-more.above.accessibility.post" = "Load from post above";

View File

@ -7,6 +7,19 @@ import SDWebImage
import UIKit import UIKit
import ViewModels import ViewModels
enum ImageError: Error {
case unableToLoad
}
extension ImageError: LocalizedError {
var errorDescription: String? {
switch self {
case .unableToLoad:
return NSLocalizedString("image-error.unable-to-load", comment: "")
}
}
}
final class ImageViewController: UIViewController { final class ImageViewController: UIViewController {
let scrollView = UIScrollView() let scrollView = UIScrollView()
let imageView = SDAnimatedImageView() let imageView = SDAnimatedImageView()
@ -124,7 +137,14 @@ final class ImageViewController: UIViewController {
placeholderImage = nil placeholderImage = nil
} }
imageView.sd_setImage(with: viewModel.attachment.url, placeholderImage: placeholderImage) imageView.sd_setImage(with: viewModel.attachment.url,
placeholderImage: placeholderImage) { _, error, _, _ in
if error != nil {
let alertItem = AlertItem(error: ImageError.unableToLoad)
self.present(alertItem: alertItem)
}
}
case .gifv: case .gifv:
playerView.tag = viewModel.tag playerView.tag = viewModel.tag
imageView.isHidden = true imageView.isHidden = true