Merge branch 'develop' of https://github.com/CatchChat/Yep into develop

This commit is contained in:
kevinzhow
2015-10-15 20:34:41 +08:00
6 changed files with 40 additions and 24 deletions
@@ -10,6 +10,7 @@ import UIKit
import Proposer
import CoreLocation
import MobileCoreServices
import Photos
class NewFeedViewController: UIViewController {
@@ -29,6 +30,8 @@ class NewFeedViewController: UIViewController {
return imagePicker
}()
var imageAssetSet: Set<PHAsset>?
var mediaImages = [UIImage]() {
didSet {
dispatch_async(dispatch_get_main_queue()) { [weak self] in
@@ -110,8 +113,13 @@ class NewFeedViewController: UIViewController {
let vc = segue.destinationViewController as! PickPhotosViewController
vc.completion = { [weak self] images in
self?.mediaImages.appendContentsOf(images)
if let imageAssetSet = imageAssetSet {
vc.pickedImageSet = imageAssetSet
}
vc.completion = { [weak self] images, imageAssetSet in
self?.mediaImages = images
self?.imageAssetSet = imageAssetSet
}
}
}
@@ -35,10 +35,8 @@ class ImageCacheController {
updatedCache.addIndex(path.item)
}
println("images: \(images), \(visibleCells.count), \(updatedCache.lastIndex), \(cachePreheatSize)")
let minCache = max(0, updatedCache.firstIndex - cachePreheatSize)
let maxCache = min(images.count - 1, updatedCache.lastIndex + cachePreheatSize)
println("cache: \(minCache), \(maxCache)")
updatedCache.addIndexesInRange(NSMakeRange(minCache, maxCache - minCache + 1))
@@ -47,7 +45,7 @@ class ImageCacheController {
if !updatedCache.containsIndex(index) {
let asset: PHAsset! = self.images[index] as! PHAsset
self.imageCache.stopCachingImagesForAssets([asset], targetSize: self.targetSize, contentMode: self.contentMode, options: nil)
print("Stopping caching image \(index)")
//println("Stopping caching image \(index)")
}
}
@@ -56,7 +54,7 @@ class ImageCacheController {
if !self.cachedIndices.containsIndex(index) {
let asset: PHAsset! = self.images[index] as! PHAsset
self.imageCache.startCachingImagesForAssets([asset], targetSize: self.targetSize, contentMode: self.contentMode, options: nil)
print("Starting caching image \(index)")
//println("Starting caching image \(index)")
}
}
@@ -17,7 +17,7 @@ class PickPhotosViewController: UICollectionViewController, PHPhotoLibraryChange
var imageCacheController: ImageCacheController!
var pickedImageSet = Set<PHAsset>()
var completion: ((images: [UIImage]) -> Void)?
var completion: ((images: [UIImage], imageAssetSet: Set<PHAsset>) -> Void)?
let photoCellID = "PhotoCell"
@@ -67,8 +67,8 @@ class PickPhotosViewController: UICollectionViewController, PHPhotoLibraryChange
let pixelWidth = CGFloat(imageAsset.pixelWidth)
let pixelHeight = CGFloat(imageAsset.pixelHeight)
println("pixelWidth: \(pixelWidth)")
println("pixelHeight: \(pixelHeight)")
//println("pixelWidth: \(pixelWidth)")
//println("pixelHeight: \(pixelHeight)")
let targetSize: CGSize
@@ -83,17 +83,17 @@ class PickPhotosViewController: UICollectionViewController, PHPhotoLibraryChange
targetSize = CGSize(width: width, height: height)
}
println("targetSize: \(targetSize)")
//println("targetSize: \(targetSize)")
imageManager.requestImageForAsset(imageAsset, targetSize: targetSize, contentMode: .AspectFill, options: options) { image, info in
if let image = image {
println("image.size: \(image.size)")
//println("image.size: \(image.size)")
images.append(image)
}
}
}
completion?(images: images)
completion?(images: images, imageAssetSet: pickedImageSet)
navigationController?.popViewControllerAnimated(true)
}
@@ -108,18 +108,23 @@ class PickPhotosViewController: UICollectionViewController, PHPhotoLibraryChange
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(photoCellID, forIndexPath: indexPath) as! PhotoCell
cell.imageManager = imageManager
if let imageAsset = images[indexPath.item] as? PHAsset {
cell.imageAsset = imageAsset
cell.photoPickedImageView.hidden = !pickedImageSet.contains(imageAsset)
}
return cell
}
override func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
if let cell = cell as? PhotoCell {
cell.imageManager = imageManager
if let imageAsset = images[indexPath.item] as? PHAsset {
cell.imageAsset = imageAsset
cell.photoPickedImageView.hidden = !pickedImageSet.contains(imageAsset)
}
}
}
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
if let imageAsset = images[indexPath.item] as? PHAsset {
+1 -1
View File
@@ -183,7 +183,7 @@ extension FeedCell: UICollectionViewDataSource, UICollectionViewDelegate {
if let imageURL = attachmentURLs[safe: indexPath.item] {
println("attachment imageURL: \(imageURL)")
//println("attachment imageURL: \(imageURL)")
cell.configureWithImageURL(imageURL)
}
+7 -2
View File
@@ -16,15 +16,20 @@ class PhotoCell: UICollectionViewCell {
var imageManager: PHImageManager?
static var imageRequestOptions: PHImageRequestOptions = {
let options = PHImageRequestOptions()
options.synchronous = true
return options
}()
var imageAsset: PHAsset? {
willSet {
guard let imageAsset = newValue else {
return
}
self.imageManager?.requestImageForAsset(imageAsset, targetSize: CGSize(width: 80, height: 80), contentMode: .AspectFill, options: nil) { [weak self] image, info in
self.imageManager?.requestImageForAsset(imageAsset, targetSize: CGSize(width: 120, height: 120), contentMode: .AspectFill, options: PhotoCell.imageRequestOptions) { [weak self] image, info in
self?.photoImageView.image = image
self?.photoPickedImageView.hidden = !imageAsset.favorite
}
}
}
+1 -1
View File
@@ -229,7 +229,7 @@ extension FeedView: UICollectionViewDataSource, UICollectionViewDelegate {
let imageURL = attachmentURLs[indexPath.item]
println("attachment imageURL: \(imageURL)")
//println("attachment imageURL: \(imageURL)")
cell.configureWithImageURL(imageURL)