Cache profile header images
This commit is contained in:
parent
ba0ca042aa
commit
3715701935
|
@ -12,6 +12,7 @@ import Cache
|
|||
class ImageCache {
|
||||
|
||||
static let avatars = ImageCache(name: "Avatars")
|
||||
static let headers = ImageCache(name: "Headers")
|
||||
|
||||
let storage: Storage<UIImage>
|
||||
|
||||
|
|
|
@ -28,8 +28,7 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|||
var accountID: String!
|
||||
|
||||
var avatarURL: URL?
|
||||
|
||||
var headerImageDownloadTask: URLSessionDataTask?
|
||||
var headerURL: URL?
|
||||
|
||||
override func awakeFromNib() {
|
||||
avatarContainerView.layer.masksToBounds = true
|
||||
|
@ -65,14 +64,12 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|||
self.avatarURL = nil
|
||||
}
|
||||
}
|
||||
headerImageDownloadTask = URLSession.shared.dataTask(with: account.header) { data, response, error in
|
||||
guard error == nil, let data = data, let image = UIImage(data: data) else { return }
|
||||
ImageCache.headers.get(account.header) { (image) in
|
||||
DispatchQueue.main.async {
|
||||
self.headerImageView.image = image
|
||||
self.headerImageDownloadTask = nil
|
||||
self.headerURL = nil
|
||||
}
|
||||
}
|
||||
headerImageDownloadTask!.resume()
|
||||
|
||||
noteLabel.setTextFromHtml(account.note)
|
||||
|
||||
|
@ -91,6 +88,9 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|||
if let url = avatarURL {
|
||||
ImageCache.avatars.cancel(url)
|
||||
}
|
||||
if let url = headerURL {
|
||||
ImageCache.headers.cancel(url)
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func morePressed(_ sender: Any) {
|
||||
|
|
Loading…
Reference in New Issue