From 22da75d92df8f6fbbcb43ea9b3f5cbe6b910ff9d Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 30 Sep 2015 18:39:56 +0800 Subject: [PATCH] show images of feed --- .../NewFeed/NewFeedViewController.swift | 2 +- Yep/Views/Cells/Feed/FeedCell.swift | 25 ++++++++++++++++--- Yep/Views/Cells/FeedMedia/FeedMediaCell.swift | 5 ++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index 93c736f0..af496369 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -112,7 +112,7 @@ class NewFeedViewController: UIViewController { dispatch_group_enter(uploadMediaImagesGroup) - s3PublicUploadFile(inFilePath: nil, orFileData: imageData, mimeType: MessageMediaType.Image.mineType, failureHandler: { (reason, errorMessage) in + s3PrivateUploadFile(inFilePath: nil, orFileData: imageData, mimeType: MessageMediaType.Image.mineType, failureHandler: { (reason, errorMessage) in defaultFailureHandler(reason, errorMessage: errorMessage) diff --git a/Yep/Views/Cells/Feed/FeedCell.swift b/Yep/Views/Cells/Feed/FeedCell.swift index eb1bd13f..b458560b 100644 --- a/Yep/Views/Cells/Feed/FeedCell.swift +++ b/Yep/Views/Cells/Feed/FeedCell.swift @@ -23,11 +23,20 @@ class FeedCell: UITableViewCell { @IBOutlet weak var messageCountLabel: UILabel! + + var attachmentURLs = [NSURL]() { + didSet { + mediaCollectionView.reloadData() + } + } + static let messageLabelMaxWidth: CGFloat = { let maxWidth = UIScreen.mainScreen().bounds.width - (60 + 10) return maxWidth }() + let feedMediaCellID = "FeedMediaCell" + override func awakeFromNib() { super.awakeFromNib() @@ -39,6 +48,7 @@ class FeedCell: UITableViewCell { messageLabel.font = UIFont.feedMessageFont() + mediaCollectionView.registerNib(UINib(nibName: feedMediaCellID, bundle: nil), forCellWithReuseIdentifier: feedMediaCellID) mediaCollectionView.dataSource = self mediaCollectionView.delegate = self @@ -53,7 +63,7 @@ class FeedCell: UITableViewCell { timeLabelTopConstraint.constant = hasMedia ? 100 : 10 mediaCollectionView.hidden = hasMedia ? false : true - //let URLs = feed.attachments.map({ NSURL(string: $0.URLString) }).flatMap({ $0 }) + attachmentURLs = feed.attachments.map({ NSURL(string: $0.URLString) }).flatMap({ $0 }) let avatarURLString = feed.creator.avatarURLString let radius = min(CGRectGetWidth(avatarImageView.bounds), CGRectGetHeight(avatarImageView.bounds)) * 0.5 @@ -83,12 +93,19 @@ extension FeedCell: UICollectionViewDataSource, UICollectionViewDelegate { } func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return 15 + return attachmentURLs.count } func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) - cell.backgroundColor = UIColor.greenColor() + + let cell = collectionView.dequeueReusableCellWithReuseIdentifier(feedMediaCellID, forIndexPath: indexPath) as! FeedMediaCell + + let imageURL = attachmentURLs[indexPath.item] + + println("attachment imageURL: \(imageURL)") + + cell.configureWithImageURL(imageURL) + return cell } diff --git a/Yep/Views/Cells/FeedMedia/FeedMediaCell.swift b/Yep/Views/Cells/FeedMedia/FeedMediaCell.swift index 9b239f40..313b5fbe 100644 --- a/Yep/Views/Cells/FeedMedia/FeedMediaCell.swift +++ b/Yep/Views/Cells/FeedMedia/FeedMediaCell.swift @@ -7,6 +7,7 @@ // import UIKit +import Kingfisher class FeedMediaCell: UICollectionViewCell { @@ -21,4 +22,8 @@ class FeedMediaCell: UICollectionViewCell { func configureWithImage(image: UIImage) { imageView.image = image } + + func configureWithImageURL(imageURL: NSURL) { + imageView.kf_setImageWithURL(imageURL) + } }