Merge branch 'feature/feed_thumbnail_url' into develop

This commit is contained in:
nixzhu
2015-11-02 18:07:41 +08:00
13 changed files with 228 additions and 136 deletions
+4
View File
@@ -248,6 +248,7 @@
50DEE0371BE3720F00015741 /* LoadMoreCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50DEE0351BE3720F00015741 /* LoadMoreCollectionViewCell.xib */; };
50DEE03D1BE70E1500015741 /* UIScrollView+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50DEE03C1BE70E1500015741 /* UIScrollView+Yep.swift */; };
50DEE03F1BE729FD00015741 /* PickLocation.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 50DEE03E1BE729FD00015741 /* PickLocation.storyboard */; };
50DEE0411BE7626100015741 /* YepHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50DEE0401BE7626100015741 /* YepHelpers.swift */; };
50E114F41ABBF9CC00F13000 /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E114F31ABBF9CC00F13000 /* Models.swift */; };
50E114F91ABC137A00F13000 /* YepServiceSync.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E114F81ABC137A00F13000 /* YepServiceSync.swift */; };
50E114FC1ABC549300F13000 /* ContactsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E114FA1ABC549300F13000 /* ContactsCell.swift */; };
@@ -567,6 +568,7 @@
50DEE0351BE3720F00015741 /* LoadMoreCollectionViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = LoadMoreCollectionViewCell.xib; path = Views/Cells/LoadMore/LoadMoreCollectionViewCell.xib; sourceTree = "<group>"; };
50DEE03C1BE70E1500015741 /* UIScrollView+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIScrollView+Yep.swift"; path = "Extensions/UIScrollView+Yep.swift"; sourceTree = "<group>"; };
50DEE03E1BE729FD00015741 /* PickLocation.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = PickLocation.storyboard; path = ViewControllers/PickLocation/PickLocation.storyboard; sourceTree = "<group>"; };
50DEE0401BE7626100015741 /* YepHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepHelpers.swift; path = Helpers/YepHelpers.swift; sourceTree = "<group>"; };
50E114F31ABBF9CC00F13000 /* Models.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Models.swift; path = Realm/Models.swift; sourceTree = "<group>"; };
50E114F81ABC137A00F13000 /* YepServiceSync.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepServiceSync.swift; path = Services/YepServiceSync.swift; sourceTree = "<group>"; };
50E114FA1ABC549300F13000 /* ContactsCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ContactsCell.swift; path = Views/Cells/Contacts/ContactsCell.swift; sourceTree = "<group>"; };
@@ -1199,6 +1201,7 @@
502AE53B1AB871C5005BD199 /* Helpers */ = {
isa = PBXGroup;
children = (
50DEE0401BE7626100015741 /* YepHelpers.swift */,
502AE5391AB871C1005BD199 /* YepAlert.swift */,
502AE53C1AB87C0D005BD199 /* YepUserDefaults.swift */,
50EB8C5D1AE78AB9001AC1EE /* YepAsset.swift */,
@@ -2468,6 +2471,7 @@
5064F6541B0B0E160089FAD4 /* AddFriendSearchCell.swift in Sources */,
504CBA3D1B3D04B800663A90 /* ChatTextView.swift in Sources */,
0A1CAC6E1AFA42D400826B45 /* SkillHomeViewController.swift in Sources */,
50DEE0411BE7626100015741 /* YepHelpers.swift in Sources */,
501138311BCB62A20055A014 /* FeedConversationCell.swift in Sources */,
502AE5401AB88862005BD199 /* SkillRankCell.swift in Sources */,
50C090A01ADE391600CC6389 /* AddSkillsReusableView.swift in Sources */,
+6 -2
View File
@@ -20,8 +20,12 @@ class ImageCache {
let cacheAttachmentQueue = dispatch_queue_create("ImageCacheAttachmentQueue", DISPATCH_QUEUE_SERIAL)
// let cacheQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)
func imageOfAttachment(attachmentURL: NSURL, withSize: CGSize?, completion: (url: NSURL, image: UIImage?) -> Void) {
func imageOfAttachment(attachment: DiscoveredAttachment, withSize: CGSize?, completion: (url: NSURL, image: UIImage?) -> Void) {
guard let attachmentURL = NSURL(string: attachment.URLString) else {
return
}
var cacheSize = CGSizeZero
if let withSize = withSize {
+17
View File
@@ -0,0 +1,17 @@
//
// YepHelpers.swift
// Yep
//
// Created by nixzhu on 15/11/2.
// Copyright © 2015 Catch Inc. All rights reserved.
//
import Foundation
final class Box<T> {
let value: T
init(value: T) {
self.value = value
}
}
+1 -1
View File
@@ -28,7 +28,7 @@ func metaDataStringOfImage(image: UIImage, needBlurThumbnail: Bool) -> String? {
let thumbnailSize = CGSize(width: thumbnailWidth, height: thumbnailHeight)
if let thumbnail = image.resizeToSize(thumbnailSize, withInterpolationQuality: CGInterpolationQuality.High) {
if let thumbnail = image.navi_resizeToSize(thumbnailSize, withInterpolationQuality: CGInterpolationQuality.High) {
if needBlurThumbnail {
+16
View File
@@ -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,
@@ -1235,10 +1235,10 @@ class ConversationViewController: BaseViewController {
}
}
feedView.tapMediaAction = { [weak self] transitionView, imageURLs, index in
feedView.tapMediaAction = { [weak self] transitionView, attachments, index in
let info = [
"transitionView": transitionView,
"imageURLs": imageURLs,
"attachments": Box(value: attachments),
"index": index,
]
self?.performSegueWithIdentifier("showFeedMedia", sender: info)
@@ -2304,8 +2304,9 @@ class ConversationViewController: BaseViewController {
let vc = segue.destinationViewController as! MessageMediaViewController
if let imageURLs = info["imageURLs"] as? [NSURL] {
vc.previewMedias = imageURLs.map({ PreviewMedia.AttachmentType(imageURL: $0) })
if let box = info["attachments"] as? Box<[DiscoveredAttachment]> {
let attachments = box.value
vc.previewMedias = attachments.map({ PreviewMedia.AttachmentType(attachment: $0) })
}
if let index = info["index"] as? Int {
@@ -2765,15 +2766,20 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi
private func tryShowMessageMediaFromMessage(message: Message) {
let predicate = NSPredicate(format: "mediaType = %d OR mediaType = %d", MessageMediaType.Image.rawValue, MessageMediaType.Video.rawValue)
if message.mediaType == MessageMediaType.Video.rawValue {
performSegueWithIdentifier("showMessageMedia", sender: ["mediaMessages": [message], "index": 0])
let mediaMessagesResult = messages.filter(predicate)
} else {
let predicate = NSPredicate(format: "mediaType = %d", MessageMediaType.Image.rawValue)
let mediaMessages = mediaMessagesResult.map({ $0 })
let mediaMessagesResult = messages.filter(predicate)
if let index = mediaMessagesResult.indexOf(message) {
let mediaMessages = mediaMessagesResult.map({ $0 })
performSegueWithIdentifier("showMessageMedia", sender: ["mediaMessages": mediaMessages, "index": index])
if let index = mediaMessagesResult.indexOf(message) {
performSegueWithIdentifier("showMessageMedia", sender: ["mediaMessages": mediaMessages, "index": index])
}
}
}
@@ -436,8 +436,9 @@ class FeedsViewController: UIViewController {
let vc = segue.destinationViewController as! MessageMediaViewController
if let imageURLs = info["imageURLs"] as? [NSURL] {
vc.previewMedias = imageURLs.map({ PreviewMedia.AttachmentType(imageURL: $0) })
if let box = info["attachments"] as? Box<[DiscoveredAttachment]> {
let attachments = box.value
vc.previewMedias = attachments.map({ PreviewMedia.AttachmentType(attachment: $0) })
}
if let index = info["index"] as? Int {
@@ -546,10 +547,10 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate {
}
}
cell.tapMediaAction = { [weak self] transitionView, imageURLs, index in
let info = [
cell.tapMediaAction = { [weak self] transitionView, attachments, index in
let info: [String: AnyObject] = [
"transitionView": transitionView,
"imageURLs": imageURLs,
"attachments": Box(value: attachments),
"index": index,
]
self?.performSegueWithIdentifier("showFeedMedia", sender: info)
@@ -13,7 +13,7 @@ import MonkeyKing
enum PreviewMedia {
case MessageType(message: Message)
case AttachmentType(imageURL: NSURL)
case AttachmentType(attachment: DiscoveredAttachment)
}
class MessageMediaViewController: UIViewController {
@@ -242,12 +242,12 @@ extension MessageMediaViewController: UICollectionViewDataSource, UICollectionVi
break
}
case .AttachmentType(let imageURL):
case .AttachmentType(let attachment):
mediaControlView.type = .Image
ImageCache.sharedInstance.imageOfAttachment(imageURL, withSize: nil, completion: { (url, image) in
guard url == imageURL else {
ImageCache.sharedInstance.imageOfAttachment(attachment, withSize: nil, completion: { (url, image) in
guard url.absoluteString == attachment.URLString else {
return
}
cell.mediaView.image = image
+10 -12
View File
@@ -30,15 +30,15 @@ class FeedCell: UITableViewCell {
var tapAvatarAction: (UITableViewCell -> Void)?
var tapSkillAction: (UITableViewCell -> Void)?
var tapMediaAction: ((transitionView: UIView, imageURLs: [NSURL], index: Int) -> Void)?
var tapMediaAction: ((transitionView: UIView, attachments: [DiscoveredAttachment], index: Int) -> Void)?
var touchesBeganAction: (UITableViewCell -> Void)?
var touchesEndedAction: (UITableViewCell -> Void)?
var touchesCancelledAction: (UITableViewCell -> Void)?
var attachmentURLs = [NSURL]() {
var attachments = [DiscoveredAttachment]() {
didSet {
if attachmentURLs.count == 1 {
if attachments.count == 1 {
collectionViewHeight.constant = 160
} else {
collectionViewHeight.constant = 80
@@ -142,7 +142,7 @@ class FeedCell: UITableViewCell {
override func prepareForReuse() {
super.prepareForReuse()
attachmentURLs = []
attachments = []
messageTextView.text = nil
messageTextView.attributedText = nil
@@ -191,7 +191,7 @@ class FeedCell: UITableViewCell {
mediaCollectionView.hidden = hasMedia ? false : true
attachmentURLs = feed.attachments.map({ NSURL(string: $0.URLString) }).flatMap({ $0 })
attachments = feed.attachments
let plainAvatar = PlainAvatar(avatarURLString: feed.creator.avatarURLString, avatarStyle: nanoAvatarStyle)
avatarImageView.navi_setAvatar(plainAvatar)
@@ -214,20 +214,18 @@ extension FeedCell: UICollectionViewDataSource, UICollectionViewDelegate {
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return attachmentURLs.count
return attachments.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(feedMediaCellID, forIndexPath: indexPath) as! FeedMediaCell
if let imageURL = attachmentURLs[safe: indexPath.item] {
if let attachment = attachments[safe: indexPath.item] {
//println("attachment imageURL: \(imageURL)")
cell.attachmentURL = imageURL
cell.configureWithImageURL(imageURL, bigger: (attachmentURLs.count == 1))
cell.configureWithAttachment(attachment, bigger: (attachments.count == 1))
}
return cell
@@ -235,7 +233,7 @@ extension FeedCell: UICollectionViewDataSource, UICollectionViewDelegate {
func collectionView(collectionView: UICollectionView!, layout collectionViewLayout: UICollectionViewLayout!, sizeForItemAtIndexPath indexPath: NSIndexPath!) -> CGSize {
if attachmentURLs.count > 1 {
if attachments.count > 1 {
return CGSize(width: 80, height: 80)
} else {
@@ -252,7 +250,7 @@ extension FeedCell: UICollectionViewDataSource, UICollectionViewDelegate {
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! FeedMediaCell
let transitionView = cell.imageView
tapMediaAction?(transitionView: transitionView, imageURLs: attachmentURLs, index: indexPath.item)
tapMediaAction?(transitionView: transitionView, attachments: attachments, index: indexPath.item)
}
}
@@ -73,9 +73,10 @@ class FeedConversationCell: UITableViewCell {
// timeLabel.text = ""
// }
let attachmentURLs = feed.attachments.map({ NSURL(string: $0.URLString) }).flatMap({ $0 })
mediaView.FeedURLs = attachmentURLs
mediaView.setImagesWithURLs(attachmentURLs)
let attachments = feed.attachments.map({
DiscoveredAttachment(kind: AttachmentKind(rawValue: $0.kind)!, metadata: $0.metadata, URLString: $0.URLString)
})
mediaView.setImagesWithAttachments(attachments)
if let latestMessage = messagesInConversation(conversation).last {
@@ -27,15 +27,17 @@ class FeedMediaCell: UICollectionViewCell {
deleteImageView.hidden = false
}
func configureWithImageURL(imageURL: NSURL, bigger: Bool) {
func configureWithAttachment(attachment: DiscoveredAttachment, bigger: Bool) {
attachmentURL = NSURL(string: attachment.URLString)!
if bigger {
// imageView.kf_setImageWithURL(imageURL, placeholderImage: YepConfig.FeedMedia.biggerPlaceholderImage)
imageView.image = YepConfig.FeedMedia.biggerPlaceholderImage
ImageCache.sharedInstance.imageOfAttachment(imageURL, withSize: imageView.frame.size, completion: { [weak self] (url, image) in
ImageCache.sharedInstance.imageOfAttachment(attachment, withSize: imageView.frame.size, completion: { [weak self] (url, image) in
if let StrongSelf = self {
if StrongSelf.attachmentURL != url {
if let strongSelf = self {
if strongSelf.attachmentURL != url {
return
}
}
@@ -47,9 +49,9 @@ class FeedMediaCell: UICollectionViewCell {
imageView.image = YepConfig.FeedMedia.placeholderImage
// imageView.kf_setImageWithURL(imageURL, placeholderImage: YepConfig.FeedMedia.placeholderImage)
ImageCache.sharedInstance.imageOfAttachment(imageURL, withSize: imageView.frame.size, completion: { [weak self] (url, image) in
if let StrongSelf = self {
if StrongSelf.attachmentURL != url {
ImageCache.sharedInstance.imageOfAttachment(attachment, withSize: imageView.frame.size, completion: { [weak self] (url, image) in
if let strongSelf = self {
if strongSelf.attachmentURL != url {
return
}
}
+125 -81
View File
@@ -10,7 +10,7 @@ import UIKit
class FeedMediaView: UIView {
var FeedURLs = [NSURL]()
var attachmentURLs = [NSURL]()
lazy var imageView1: UIImageView = {
let view = UIImageView()
@@ -44,86 +44,113 @@ class FeedMediaView: UIView {
return view
}()
func setImagesWithURLs(URLs: [NSURL]) {
func setImagesWithAttachments(attachments: [DiscoveredAttachment]) {
let fullRect = bounds
let halfRect = CGRect(x: 0, y: 0, width: fullRect.width * 0.5, height: fullRect.height)
let quarterRect = CGRect(x: 0, y: 0, width: fullRect.width * 0.5, height: fullRect.height * 0.5)
hidden = (URLs.count == 0)
hidden = (attachments.count == 0)
// println(URLs)
attachmentURLs = attachments.map({ NSURL(string: $0.URLString) }).flatMap({ $0 })
switch URLs.count {
switch attachments.count {
case 1:
imageView1.frame = fullRect
// imageView1.kf_setImageWithURL(URLs[0])
ImageCache.sharedInstance.imageOfAttachment(URLs[0], withSize: fullRect.size, completion: { [weak self] (url, image) in
guard let StrongSelf = self where StrongSelf.FeedURLs.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(URLs[0], withSize: halfRect.size, completion: { [weak self] (url, image) in
guard let StrongSelf = self where StrongSelf.FeedURLs.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(URLs[1], withSize: halfRect.size, completion: { [weak self] (url, image) in
guard let StrongSelf = self where StrongSelf.FeedURLs.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(URLs[0], withSize: quarterRect.size, completion: { [weak self] (url, image) in
guard let StrongSelf = self where StrongSelf.FeedURLs.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(URLs[1], withSize: quarterRect.size, completion: { [weak self] (url, image) in
guard let StrongSelf = self where StrongSelf.FeedURLs.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(URLs[2], withSize: quarterRect.size, completion: { [weak self] (url, image) in
guard let StrongSelf = self where StrongSelf.FeedURLs.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)
@@ -132,46 +159,63 @@ class FeedMediaView: UIView {
case 4..<Int.max:
imageView1.frame = quarterRect
// imageView1.kf_setImageWithURL(URLs[0])
ImageCache.sharedInstance.imageOfAttachment(URLs[0], withSize: quarterRect.size, completion: { [weak self] (url, image) in
guard let StrongSelf = self where StrongSelf.FeedURLs.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(URLs[1], withSize: quarterRect.size, completion: { [weak self] (url, image) in
guard let StrongSelf = self where StrongSelf.FeedURLs.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(URLs[2], withSize: quarterRect.size, completion: { [weak self] (url, image) in
guard let StrongSelf = self where StrongSelf.FeedURLs.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(URLs[3], withSize: quarterRect.size, completion: { [weak self] (url, image) in
guard let StrongSelf = self where StrongSelf.FeedURLs.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)
+11 -12
View File
@@ -18,7 +18,7 @@ class FeedView: UIView {
}
}
var tapMediaAction: ((transitionView: UIView, imageURLs: [NSURL], index: Int) -> Void)?
var tapMediaAction: ((transitionView: UIView, attachments: [DiscoveredAttachment], index: Int) -> Void)?
static let foldHeight: CGFloat = 60
@@ -33,7 +33,7 @@ class FeedView: UIView {
if newValue >= 0 && newValue <= 1 {
let normalHeight = self.normalHeight
let attachmentURLsIsEmpty = attachmentURLs.isEmpty
let attachmentURLsIsEmpty = attachments.isEmpty
UIView.animateWithDuration(0.3, delay: 0, usingSpringWithDamping: 0.75, initialSpringVelocity: 0.0, options: UIViewAnimationOptions(rawValue: 0), animations: { [weak self] in
@@ -100,11 +100,10 @@ class FeedView: UIView {
@IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var timeLabelTopConstraint: NSLayoutConstraint!
var attachmentURLs = [NSURL]() {
var attachments = [DiscoveredAttachment]() {
didSet {
mediaCollectionView.reloadData()
mediaView.FeedURLs = attachmentURLs
mediaView.setImagesWithURLs(attachmentURLs)
mediaView.setImagesWithAttachments(attachments)
}
}
@@ -201,7 +200,9 @@ class FeedView: UIView {
timeLabelTopConstraint.constant = hasMedia ? (15 + 80 + 15) : 15
mediaCollectionView.hidden = hasMedia ? false : true
attachmentURLs = feed.attachments.map({ NSURL(string: $0.URLString) }).flatMap({ $0 })
attachments = feed.attachments.map({
DiscoveredAttachment(kind: AttachmentKind(rawValue: $0.kind)!, metadata: $0.metadata, URLString: $0.URLString)
})//.map({ NSURL(string: $0.URLString) }).flatMap({ $0 })
if let creator = feed.creator {
let userAvatar = UserAvatar(userID: creator.userID, avatarStyle: nanoAvatarStyle)
@@ -243,20 +244,18 @@ extension FeedView: UICollectionViewDataSource, UICollectionViewDelegate {
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return attachmentURLs.count
return attachments.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(feedMediaCellID, forIndexPath: indexPath) as! FeedMediaCell
let imageURL = attachmentURLs[indexPath.item]
let attachment = attachments[indexPath.item]
//println("attachment imageURL: \(imageURL)")
cell.attachmentURL = imageURL
cell.configureWithImageURL(imageURL, bigger: (attachmentURLs.count == 1))
cell.configureWithAttachment(attachment, bigger: (attachments.count == 1))
return cell
}
@@ -275,7 +274,7 @@ extension FeedView: UICollectionViewDataSource, UICollectionViewDelegate {
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! FeedMediaCell
let transitionView = cell.imageView
tapMediaAction?(transitionView: transitionView, imageURLs: attachmentURLs, index: indexPath.item)
tapMediaAction?(transitionView: transitionView, attachments: attachments, index: indexPath.item)
}
}