|
|
@@ -32,6 +32,7 @@ import UIKit
|
|
|
|
|
|
public typealias DownloadProgressBlock = ((receivedSize: Int64, totalSize: Int64) -> ())
|
|
|
public typealias CompletionHandler = ((image: Image?, error: NSError?, cacheType: CacheType, imageURL: URL?) -> ())
|
|
|
+public typealias RetrieveCompletionHandler = ((image: Image?, error: NSError?, cacheType: CacheType, wasDownloaded: Bool, imageURL: URL?) -> ())
|
|
|
|
|
|
/// RetrieveImageTask represents a task of image retrieving process.
|
|
|
/// It contains an async task of getting image from disk and from network.
|
|
|
@@ -119,7 +120,7 @@ public class KingfisherManager {
|
|
|
public func retrieveImageWithResource(_ resource: Resource,
|
|
|
optionsInfo: KingfisherOptionsInfo?,
|
|
|
progressBlock: DownloadProgressBlock?,
|
|
|
- completionHandler: CompletionHandler?) -> RetrieveImageTask
|
|
|
+ completionHandler: RetrieveCompletionHandler?) -> RetrieveImageTask
|
|
|
{
|
|
|
let task = RetrieveImageTask()
|
|
|
|
|
|
@@ -162,7 +163,7 @@ public class KingfisherManager {
|
|
|
public func retrieveImageWithURL(_ URL: Foundation.URL,
|
|
|
optionsInfo: KingfisherOptionsInfo?,
|
|
|
progressBlock: DownloadProgressBlock?,
|
|
|
- completionHandler: CompletionHandler?) -> RetrieveImageTask
|
|
|
+ completionHandler: RetrieveCompletionHandler?) -> RetrieveImageTask
|
|
|
{
|
|
|
return retrieveImageWithResource(Resource(downloadURL: URL), optionsInfo: optionsInfo, progressBlock: progressBlock, completionHandler: completionHandler)
|
|
|
}
|
|
|
@@ -172,7 +173,7 @@ public class KingfisherManager {
|
|
|
forKey key: String,
|
|
|
retrieveImageTask: RetrieveImageTask,
|
|
|
progressBlock: DownloadProgressBlock?,
|
|
|
- completionHandler: CompletionHandler?,
|
|
|
+ completionHandler: RetrieveCompletionHandler?,
|
|
|
options: KingfisherOptionsInfo?) -> RetrieveImageDownloadTask?
|
|
|
{
|
|
|
let downloader = options?.downloader ?? self.downloader
|
|
|
@@ -187,7 +188,7 @@ public class KingfisherManager {
|
|
|
// Not modified. Try to find the image from cache.
|
|
|
// (The image should be in cache. It should be guaranteed by the framework users.)
|
|
|
targetCache.retrieveImageForKey(key, options: options, completionHandler: { (cacheImage, cacheType) -> () in
|
|
|
- completionHandler?(image: cacheImage, error: nil, cacheType: cacheType, imageURL: URL)
|
|
|
+ completionHandler?(image: cacheImage, error: nil, cacheType: cacheType, wasDownloaded: true, imageURL: URL)
|
|
|
|
|
|
})
|
|
|
return
|
|
|
@@ -197,7 +198,7 @@ public class KingfisherManager {
|
|
|
targetCache.storeImage(image, originalData: originalData, forKey: key, toDisk: !(options?.cacheMemoryOnly ?? false), completionHandler: nil)
|
|
|
}
|
|
|
|
|
|
- completionHandler?(image: image, error: error, cacheType: .none, imageURL: URL)
|
|
|
+ completionHandler?(image: image, error: error, cacheType: .none, wasDownloaded: true, imageURL: URL)
|
|
|
|
|
|
})
|
|
|
}
|
|
|
@@ -206,20 +207,21 @@ public class KingfisherManager {
|
|
|
withURL URL: Foundation.URL,
|
|
|
retrieveImageTask: RetrieveImageTask,
|
|
|
progressBlock: DownloadProgressBlock?,
|
|
|
- completionHandler: CompletionHandler?,
|
|
|
+ completionHandler: RetrieveCompletionHandler?,
|
|
|
options: KingfisherOptionsInfo?)
|
|
|
{
|
|
|
- let diskTaskCompletionHandler: CompletionHandler = { (image, error, cacheType, imageURL) -> () in
|
|
|
+ let diskTaskCompletionHandler: RetrieveCompletionHandler = {
|
|
|
+ (image, error, cacheType, wasDownloaded, imageURL) -> () in
|
|
|
// Break retain cycle created inside diskTask closure below
|
|
|
retrieveImageTask.diskRetrieveTask = nil
|
|
|
- completionHandler?(image: image, error: error, cacheType: cacheType, imageURL: imageURL)
|
|
|
+ completionHandler?(image: image, error: error, cacheType: cacheType, wasDownloaded: wasDownloaded, imageURL: imageURL)
|
|
|
}
|
|
|
|
|
|
let targetCache = options?.targetCache ?? cache
|
|
|
let diskTask = targetCache.retrieveImageForKey(key, options: options,
|
|
|
completionHandler: { image, cacheType in
|
|
|
if image != nil {
|
|
|
- diskTaskCompletionHandler(image: image, error: nil, cacheType:cacheType, imageURL: URL)
|
|
|
+ diskTaskCompletionHandler(image: image, error: nil, cacheType:cacheType, wasDownloaded: false, imageURL: URL)
|
|
|
} else {
|
|
|
self.downloadAndCacheImageWithURL(URL,
|
|
|
forKey: key,
|