mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-11 05:45:56 +10:00
use DiscoveredAttachment's thumbnailImage for FeedMediaView if can
This commit is contained in:
@@ -2397,6 +2397,22 @@ struct DiscoveredAttachment {
|
||||
let metadata: String
|
||||
let URLString: String
|
||||
|
||||
var thumbnailImage: UIImage? {
|
||||
|
||||
if let data = metadata.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) {
|
||||
if let metaDataInfo = decodeJSON(data) {
|
||||
if let thumbnailString = metaDataInfo[YepConfig.MetaData.thumbnailString] as? String {
|
||||
if let imageData = NSData(base64EncodedString: thumbnailString, options: NSDataBase64DecodingOptions(rawValue: 0)) {
|
||||
let image = UIImage(data: imageData)
|
||||
return image
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
static func fromJSONDictionary(json: JSONDictionary) -> DiscoveredAttachment? {
|
||||
guard let
|
||||
kindString = json["kind"] as? String,
|
||||
|
||||
@@ -75,7 +75,7 @@ class FeedConversationCell: UITableViewCell {
|
||||
|
||||
let attachments = feed.attachments.map({
|
||||
DiscoveredAttachment(kind: AttachmentKind(rawValue: $0.kind)!, metadata: $0.metadata, URLString: $0.URLString)
|
||||
})//.map({ NSURL(string: $0.URLString) }).flatMap({ $0 })
|
||||
})
|
||||
mediaView.setImagesWithAttachments(attachments)
|
||||
|
||||
if let latestMessage = messagesInConversation(conversation).last {
|
||||
|
||||
@@ -52,80 +52,105 @@ class FeedMediaView: UIView {
|
||||
|
||||
hidden = (attachments.count == 0)
|
||||
|
||||
// println(URLs)
|
||||
|
||||
attachmentURLs = attachments.map({ NSURL(string: $0.URLString) }).flatMap({ $0 })
|
||||
|
||||
switch attachments.count {
|
||||
|
||||
case 1:
|
||||
imageView1.frame = fullRect
|
||||
// imageView1.kf_setImageWithURL(URLs[0])
|
||||
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[0], withSize: fullRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView1.image = image
|
||||
})
|
||||
|
||||
if let thumbnailImage = attachments[0].thumbnailImage {
|
||||
imageView1.image = thumbnailImage
|
||||
|
||||
} else {
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[0], withSize: fullRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView1.image = image
|
||||
})
|
||||
}
|
||||
|
||||
addSubview(imageView1)
|
||||
|
||||
case 2:
|
||||
imageView1.frame = halfRect
|
||||
imageView1.center = CGPoint(x: halfRect.width * 0.5, y: imageView1.center.y)
|
||||
// imageView1.kf_setImageWithURL(URLs[0])
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[0], withSize: halfRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView1.image = image
|
||||
})
|
||||
|
||||
if let thumbnailImage = attachments[0].thumbnailImage {
|
||||
imageView1.image = thumbnailImage
|
||||
|
||||
} else {
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[0], withSize: halfRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView1.image = image
|
||||
})
|
||||
}
|
||||
|
||||
imageView2.frame = halfRect
|
||||
imageView2.center = CGPoint(x: halfRect.width * 1.5, y: imageView2.center.y)
|
||||
// imageView2.kf_setImageWithURL(URLs[1])
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[1], withSize: halfRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView2.image = image
|
||||
})
|
||||
|
||||
if let thumbnailImage = attachments[1].thumbnailImage {
|
||||
imageView2.image = thumbnailImage
|
||||
|
||||
} else {
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[1], withSize: halfRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView2.image = image
|
||||
})
|
||||
}
|
||||
|
||||
addSubview(imageView1)
|
||||
addSubview(imageView2)
|
||||
|
||||
case 3:
|
||||
imageView1.frame = quarterRect
|
||||
// imageView1.kf_setImageWithURL(URLs[0])
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[0], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView1.image = image
|
||||
})
|
||||
|
||||
if let thumbnailImage = attachments[0].thumbnailImage {
|
||||
imageView1.image = thumbnailImage
|
||||
|
||||
} else {
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[0], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView1.image = image
|
||||
})
|
||||
}
|
||||
|
||||
imageView2.frame = quarterRect
|
||||
imageView2.center = CGPoint(x: imageView2.center.x, y: quarterRect.height * 1.5)
|
||||
// imageView2.kf_setImageWithURL(URLs[1])
|
||||
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[1], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView2.image = image
|
||||
})
|
||||
|
||||
if let thumbnailImage = attachments[1].thumbnailImage {
|
||||
imageView2.image = thumbnailImage
|
||||
|
||||
} else {
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[1], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView2.image = image
|
||||
})
|
||||
}
|
||||
|
||||
imageView3.frame = halfRect
|
||||
imageView3.center = CGPoint(x: halfRect.width * 1.5, y: imageView3.center.y)
|
||||
// imageView3.kf_setImageWithURL(URLs[2])
|
||||
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[2], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView3.image = image
|
||||
})
|
||||
|
||||
if let thumbnailImage = attachments[2].thumbnailImage {
|
||||
imageView3.image = thumbnailImage
|
||||
|
||||
} else {
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[2], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView3.image = image
|
||||
})
|
||||
}
|
||||
|
||||
addSubview(imageView1)
|
||||
addSubview(imageView2)
|
||||
@@ -134,46 +159,63 @@ class FeedMediaView: UIView {
|
||||
case 4..<Int.max:
|
||||
|
||||
imageView1.frame = quarterRect
|
||||
// imageView1.kf_setImageWithURL(URLs[0])
|
||||
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[0], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView1.image = image
|
||||
})
|
||||
|
||||
if let thumbnailImage = attachments[0].thumbnailImage {
|
||||
imageView1.image = thumbnailImage
|
||||
|
||||
} else {
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[0], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView1.image = image
|
||||
})
|
||||
}
|
||||
|
||||
imageView2.frame = quarterRect
|
||||
imageView2.center = CGPoint(x: imageView2.center.x, y: quarterRect.height * 1.5)
|
||||
// imageView2.kf_setImageWithURL(URLs[1])
|
||||
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[1], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView2.image = image
|
||||
})
|
||||
|
||||
if let thumbnailImage = attachments[1].thumbnailImage {
|
||||
imageView2.image = thumbnailImage
|
||||
|
||||
} else {
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[1], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView2.image = image
|
||||
})
|
||||
}
|
||||
|
||||
imageView3.frame = quarterRect
|
||||
imageView3.center = CGPoint(x: quarterRect.width * 1.5, y: imageView3.center.y)
|
||||
// imageView3.kf_setImageWithURL(URLs[2])
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[2], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView3.image = image
|
||||
})
|
||||
|
||||
if let thumbnailImage = attachments[2].thumbnailImage {
|
||||
imageView3.image = thumbnailImage
|
||||
|
||||
} else {
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[2], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView3.image = image
|
||||
})
|
||||
}
|
||||
|
||||
imageView4.frame = quarterRect
|
||||
imageView4.center = CGPoint(x: quarterRect.width * 1.5, y: quarterRect.height * 1.5)
|
||||
// imageView4.kf_setImageWithURL(URLs[3])
|
||||
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[3], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView4.image = image
|
||||
})
|
||||
|
||||
if let thumbnailImage = attachments[3].thumbnailImage {
|
||||
imageView4.image = thumbnailImage
|
||||
|
||||
} else {
|
||||
ImageCache.sharedInstance.imageOfAttachment(attachments[3], withSize: quarterRect.size, completion: { [weak self] (url, image) in
|
||||
guard let strongSelf = self where strongSelf.attachmentURLs.contains(url) else {
|
||||
return
|
||||
}
|
||||
self?.imageView4.image = image
|
||||
})
|
||||
}
|
||||
|
||||
addSubview(imageView1)
|
||||
addSubview(imageView2)
|
||||
|
||||
Reference in New Issue
Block a user