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.log-out" = "Log out";
"identities.pending" = "Pending";
"image-error.unable-to-load" = "Unable to load image";
"lists.new-list-title" = "New List Title";
"load-more" = "Load More";
"load-more.above.accessibility.post" = "Load from post above";

View file

@ -7,6 +7,19 @@ import SDWebImage
import UIKit
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 {
let scrollView = UIScrollView()
let imageView = SDAnimatedImageView()
@ -124,7 +137,14 @@ final class ImageViewController: UIViewController {
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:
playerView.tag = viewModel.tag
imageView.isHidden = true