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