Cache image attachments
This commit is contained in:
parent
fd611d1f04
commit
82e351465e
|
@ -13,6 +13,7 @@ class ImageCache {
|
|||
|
||||
static let avatars = ImageCache(name: "Avatars")
|
||||
static let headers = ImageCache(name: "Headers")
|
||||
static let attachments = ImageCache(name: "Attachments", diskExpiry: .seconds(60 * 60), memoryExpiry: .seconds(60))
|
||||
|
||||
let storage: Storage<UIImage>
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@ class AttachmentView: UIImageView {
|
|||
|
||||
var attachment: Attachment!
|
||||
|
||||
var task: URLSessionDataTask?
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
commonInit()
|
||||
|
@ -45,13 +43,11 @@ class AttachmentView: UIImageView {
|
|||
}
|
||||
|
||||
func loadImage() {
|
||||
task = URLSession.shared.dataTask(with: attachment.url) { data, response, error in
|
||||
guard error == nil, let data = data, let image = UIImage(data: data) else { return }
|
||||
ImageCache.attachments.get(attachment.url) { (image) in
|
||||
DispatchQueue.main.async {
|
||||
self.image = image
|
||||
}
|
||||
}
|
||||
task!.resume()
|
||||
}
|
||||
|
||||
@objc func imagePressed() {
|
||||
|
|
|
@ -85,7 +85,6 @@ class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive
|
|||
}
|
||||
updateTimestamp()
|
||||
|
||||
attachmentsView.subviews.forEach { $0.removeFromSuperview() }
|
||||
let attachments = status.attachments.filter({ $0.kind == .image })
|
||||
if attachments.count > 0 {
|
||||
attachmentsView.isHidden = false
|
||||
|
@ -155,9 +154,7 @@ class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive
|
|||
}
|
||||
updateTimestampWorkItem?.cancel()
|
||||
updateTimestampWorkItem = nil
|
||||
attachmentsView.subviews.forEach { view in
|
||||
(view as? AttachmentView)?.task?.cancel()
|
||||
}
|
||||
attachmentsView.subviews.forEach { $0.removeFromSuperview() }
|
||||
}
|
||||
|
||||
@objc func accountPressed() {
|
||||
|
|
|
@ -170,10 +170,7 @@ class StatusTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|||
}
|
||||
updateTimestampWorkItem?.cancel()
|
||||
updateTimestampWorkItem = nil
|
||||
attachmentsView.subviews.forEach { view in
|
||||
(view as? AttachmentView)?.task?.cancel()
|
||||
view.removeFromSuperview()
|
||||
}
|
||||
attachmentsView.subviews.forEach { $0.removeFromSuperview() }
|
||||
}
|
||||
|
||||
override func setSelected(_ selected: Bool, animated: Bool) {
|
||||
|
|
Loading…
Reference in New Issue