|
|
@ -60,19 +60,29 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView |
|
|
break |
|
|
break |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
let URL = NSURL(string: i.thumbUrlAbsolute)! |
|
|
|
|
|
|
|
|
|
|
|
let op1 = ImageLoadOperation(imageURL: URL, succeeder: { |
|
|
|
|
|
img in |
|
|
|
|
|
let imageRef = img.CGImage; |
|
|
|
|
|
let bytesPerPixel = CGImageGetBitsPerPixel(imageRef) / 8; |
|
|
|
|
|
let cost = CGImageGetWidth(imageRef) * CGImageGetHeight(imageRef) * bytesPerPixel; |
|
|
|
|
|
self.total += cost |
|
|
|
|
|
println("preload image loaded \(i.thumbUrlAbsolute) cost \(cost) total\(self.total)") |
|
|
|
|
|
self.imageCache.setObject(img, forKey: i.thumbUrlAbsolute, cost: cost) |
|
|
|
|
|
}, index: j) |
|
|
|
|
|
op1.qualityOfService = NSQualityOfService.Background |
|
|
|
|
|
backgroundOperationQueue.addOperation(op1) |
|
|
|
|
|
|
|
|
let u1 = NSURL(string: i.thumbUrlAbsolute) |
|
|
|
|
|
|
|
|
|
|
|
if let URL = u1 { |
|
|
|
|
|
|
|
|
|
|
|
let op1 = DataLoadOperation(imageURL: URL, succeeder: { |
|
|
|
|
|
d in |
|
|
|
|
|
if d.length > 0 { |
|
|
|
|
|
if let img = UIImage(data: d) { |
|
|
|
|
|
let imageRef = img.CGImage; |
|
|
|
|
|
let bytesPerPixel = CGImageGetBitsPerPixel(imageRef) / 8; |
|
|
|
|
|
let cost = CGImageGetWidth(imageRef) * CGImageGetHeight(imageRef) * bytesPerPixel; |
|
|
|
|
|
self.total += d.length |
|
|
|
|
|
println("preload image loaded \(i.thumbUrlAbsolute) cost \(cost) total\(self.total)") |
|
|
|
|
|
self.imageCache.setObject(img, forKey: i.thumbUrlAbsolute, cost: d.length) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}, index: j) |
|
|
|
|
|
op1.qualityOfService = NSQualityOfService.Background |
|
|
|
|
|
backgroundOperationQueue.addOperation(op1) |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
println("## Invalid URL: \(i.thumbUrlAbsolute)") |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -213,72 +223,82 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView |
|
|
let c = count(items) |
|
|
let c = count(items) |
|
|
// println("Index: \(photoAtIndex) of \(c)") |
|
|
// println("Index: \(photoAtIndex) of \(c)") |
|
|
let newItem = items[photoAtIndex] |
|
|
let newItem = items[photoAtIndex] |
|
|
let hqURL = NSURL(string: newItem.imageUrlAbsolute)! |
|
|
|
|
|
let URL = NSURL(string: newItem.thumbUrlAbsolute)! |
|
|
|
|
|
|
|
|
let u1 = NSURL(string: newItem.imageUrlAbsolute) |
|
|
|
|
|
let u2 = NSURL(string: newItem.thumbUrlAbsolute) |
|
|
|
|
|
if let hqURL = u1, URL = u2 { |
|
|
|
|
|
|
|
|
var image: UIImage? = nil |
|
|
|
|
|
|
|
|
var image: UIImage? = nil |
|
|
|
|
|
|
|
|
var size = NIPhotoScrollViewPhotoSizeUnknown |
|
|
|
|
|
|
|
|
var size = NIPhotoScrollViewPhotoSizeUnknown |
|
|
|
|
|
|
|
|
for r in requests { |
|
|
|
|
|
let pages = self.photoAlbumView.visiblePages() as NSMutableSet! |
|
|
|
|
|
var ok = false |
|
|
|
|
|
for page in pages.allObjects { |
|
|
|
|
|
if (page.pageIndex == r.index) { |
|
|
|
|
|
ok = true |
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
for r in requests { |
|
|
|
|
|
let pages = self.photoAlbumView.visiblePages() as NSMutableSet! |
|
|
|
|
|
var ok = false |
|
|
|
|
|
for page in pages.allObjects { |
|
|
|
|
|
if (page.pageIndex == r.index) { |
|
|
|
|
|
ok = true |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
r.cancel() |
|
|
|
|
|
requests.remove(r) |
|
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
r.cancel() |
|
|
|
|
|
requests.remove(r) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
image = imageCache.objectForKey(URL.absoluteString!) as? UIImage |
|
|
|
|
|
|
|
|
image = imageCache.objectForKey(URL.absoluteString!) as? UIImage |
|
|
|
|
|
|
|
|
|
|
|
if let i = image { |
|
|
|
|
|
size = NIPhotoScrollViewPhotoSizeThumbnail |
|
|
|
|
|
isLoading[0] = false |
|
|
|
|
|
} else { |
|
|
|
|
|
let URL = NSURL(string: newItem.thumbUrlAbsolute)! |
|
|
|
|
|
|
|
|
|
|
|
let op3 = DataLoadOperation(imageURL: URL, succeeder: { |
|
|
|
|
|
d in |
|
|
|
|
|
if d.length > 0 { |
|
|
|
|
|
if let i = UIImage(data: d) { |
|
|
|
|
|
// println("thumb preload image loaded \(newItem.imageUrlAbsolute)") |
|
|
|
|
|
let imageRef = i.CGImage; |
|
|
|
|
|
let bytesPerPixel = CGImageGetBitsPerPixel(imageRef) / 8; |
|
|
|
|
|
let cost = CGImageGetWidth(imageRef) * CGImageGetHeight(imageRef) * bytesPerPixel; |
|
|
|
|
|
self.imageCache.setObject(d, forKey: newItem.thumbUrlAbsolute, cost: d.length) |
|
|
|
|
|
size = NIPhotoScrollViewPhotoSizeThumbnail |
|
|
|
|
|
self.photoAlbumView.didLoadPhoto(i, atIndex: photoAtIndex, photoSize: size) |
|
|
|
|
|
self.photoScrubberView.didLoadThumbnail(i, atIndex: photoAtIndex); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}, index: photoAtIndex) |
|
|
|
|
|
op3.qualityOfService = NSQualityOfService.UserInteractive |
|
|
|
|
|
// requests.append(op3) |
|
|
|
|
|
operationQueue.addOperation(op3) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if let i = image { |
|
|
|
|
|
size = NIPhotoScrollViewPhotoSizeThumbnail |
|
|
|
|
|
isLoading[0] = false |
|
|
|
|
|
} else { |
|
|
|
|
|
let URL = NSURL(string: newItem.thumbUrlAbsolute)! |
|
|
|
|
|
|
|
|
|
|
|
let op3 = ImageLoadOperation(imageURL: URL, succeeder: { |
|
|
|
|
|
|
|
|
let op2 = ImageLoadOperation(imageURL: hqURL, succeeder: { |
|
|
i in |
|
|
i in |
|
|
// println("thumb preload image loaded \(newItem.imageUrlAbsolute)") |
|
|
|
|
|
let imageRef = i.CGImage; |
|
|
|
|
|
let bytesPerPixel = CGImageGetBitsPerPixel(imageRef) / 8; |
|
|
|
|
|
let cost = CGImageGetWidth(imageRef) * CGImageGetHeight(imageRef) * bytesPerPixel; |
|
|
|
|
|
self.imageCache.setObject(i, forKey: newItem.thumbUrlAbsolute, cost: cost) |
|
|
|
|
|
size = NIPhotoScrollViewPhotoSizeThumbnail |
|
|
|
|
|
|
|
|
// println("image loaded \(newItem.imageUrlAbsolute) at \(photoAtIndex)") |
|
|
|
|
|
size = NIPhotoScrollViewPhotoSizeOriginal |
|
|
self.photoAlbumView.didLoadPhoto(i, atIndex: photoAtIndex, photoSize: size) |
|
|
self.photoAlbumView.didLoadPhoto(i, atIndex: photoAtIndex, photoSize: size) |
|
|
self.photoScrubberView.didLoadThumbnail(i, atIndex: photoAtIndex); |
|
|
|
|
|
|
|
|
photoSize[0] = size |
|
|
}, index: photoAtIndex) |
|
|
}, index: photoAtIndex) |
|
|
op3.qualityOfService = NSQualityOfService.UserInteractive |
|
|
|
|
|
requests.append(op3) |
|
|
|
|
|
operationQueue.addOperation(op3) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
op2.qualityOfService = NSQualityOfService.UserInitiated |
|
|
|
|
|
requests.append(op2) |
|
|
|
|
|
operationQueue.addOperation(op2) |
|
|
|
|
|
|
|
|
|
|
|
if (image == nil) { |
|
|
|
|
|
isLoading[0] = true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let op2 = ImageLoadOperation(imageURL: hqURL, succeeder: { |
|
|
|
|
|
i in |
|
|
|
|
|
// println("image loaded \(newItem.imageUrlAbsolute) at \(photoAtIndex)") |
|
|
|
|
|
size = NIPhotoScrollViewPhotoSizeOriginal |
|
|
|
|
|
self.photoAlbumView.didLoadPhoto(i, atIndex: photoAtIndex, photoSize: size) |
|
|
|
|
|
photoSize[0] = size |
|
|
photoSize[0] = size |
|
|
}, index: photoAtIndex) |
|
|
|
|
|
op2.qualityOfService = NSQualityOfService.UserInitiated |
|
|
|
|
|
requests.append(op2) |
|
|
|
|
|
operationQueue.addOperation(op2) |
|
|
|
|
|
|
|
|
|
|
|
if (image == nil) { |
|
|
|
|
|
isLoading[0] = true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
photoSize[0] = size |
|
|
|
|
|
|
|
|
return image |
|
|
|
|
|
} else { |
|
|
|
|
|
println("## Invalid URL: \(newItem.imageUrlAbsolute)") |
|
|
|
|
|
|
|
|
return image |
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func numberOfPagesInPagingScrollView(pagingScrollView: NIPagingScrollView) -> Int { |
|
|
func numberOfPagesInPagingScrollView(pagingScrollView: NIPagingScrollView) -> Int { |
|
|
@ -324,20 +344,30 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView |
|
|
image = imageCache.objectForKey(newItem.thumbUrlAbsolute) as? UIImage |
|
|
image = imageCache.objectForKey(newItem.thumbUrlAbsolute) as? UIImage |
|
|
|
|
|
|
|
|
if (image == nil) { |
|
|
if (image == nil) { |
|
|
let URL = NSURL(string: newItem.thumbUrlAbsolute)! |
|
|
|
|
|
let op3 = ImageLoadOperation(imageURL: URL, succeeder: { |
|
|
|
|
|
i in |
|
|
|
|
|
|
|
|
let u1 = NSURL(string: newItem.thumbUrlAbsolute) |
|
|
|
|
|
if let URL = u1 { |
|
|
|
|
|
let op3 = DataLoadOperation(imageURL: URL, succeeder: { |
|
|
|
|
|
d in |
|
|
|
|
|
|
|
|
|
|
|
if d.length > 0 { |
|
|
|
|
|
if let i = UIImage(data: d) { |
|
|
// println("thumb image loaded \(newItem.thumbUrlAbsolute)") |
|
|
// println("thumb image loaded \(newItem.thumbUrlAbsolute)") |
|
|
let imageRef = i.CGImage; |
|
|
|
|
|
let bytesPerPixel = CGImageGetBitsPerPixel(imageRef) / 8; |
|
|
|
|
|
let cost = CGImageGetWidth(imageRef) * CGImageGetHeight(imageRef) * bytesPerPixel; |
|
|
|
|
|
|
|
|
let imageRef = i.CGImage; |
|
|
|
|
|
let bytesPerPixel = CGImageGetBitsPerPixel(imageRef) / 8; |
|
|
|
|
|
let cost = CGImageGetWidth(imageRef) * CGImageGetHeight(imageRef) * bytesPerPixel; |
|
|
|
|
|
|
|
|
self.imageCache.setObject(i, forKey: newItem.thumbUrlAbsolute, cost: cost) |
|
|
|
|
|
|
|
|
self.imageCache.setObject(i, forKey: newItem.thumbUrlAbsolute, cost: d.length) |
|
|
|
|
|
|
|
|
self.photoScrubberView.didLoadThumbnail(i, atIndex: thumbnailIndex); |
|
|
|
|
|
}, index: thumbnailIndex) |
|
|
|
|
|
op3.qualityOfService = NSQualityOfService.UserInitiated |
|
|
|
|
|
operationQueue.addOperation(op3) |
|
|
|
|
|
|
|
|
self.photoScrubberView.didLoadThumbnail(i, atIndex: thumbnailIndex); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}, index: thumbnailIndex) |
|
|
|
|
|
op3.qualityOfService = NSQualityOfService.UserInitiated |
|
|
|
|
|
operationQueue.addOperation(op3) |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
println("## Invalid URL: \(newItem.thumbUrlAbsolute)") |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return image |
|
|
return image |
|
|
|