Authored by Olivier Poitrey

Merge pull request #664 from xuki/master

add support for high priority download
@@ -37,7 +37,12 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) { @@ -37,7 +37,12 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {
37 * Enable to allow untrusted SSL ceriticates. 37 * Enable to allow untrusted SSL ceriticates.
38 * Useful for testing purposes. Use with caution in production. 38 * Useful for testing purposes. Use with caution in production.
39 */ 39 */
40 - SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6 40 + SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6,
  41 + /**
  42 + *
  43 + */
  44 + SDWebImageDownloaderHighPriority = 1 << 7,
  45 +
41 46
42 }; 47 };
43 48
@@ -152,6 +152,10 @@ static NSString *const kCompletedCallbackKey = @"completed"; @@ -152,6 +152,10 @@ static NSString *const kCompletedCallbackKey = @"completed";
152 SDWebImageDownloader *sself = wself; 152 SDWebImageDownloader *sself = wself;
153 [sself removeCallbacksForURL:url]; 153 [sself removeCallbacksForURL:url];
154 }]; 154 }];
  155 +
  156 + if (options & SDWebImageDownloaderHighPriority) {
  157 + operation.queuePriority = NSOperationQueuePriorityHigh;
  158 + }
155 159
156 [wself.downloadQueue addOperation:operation]; 160 [wself.downloadQueue addOperation:operation];
157 if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) { 161 if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) {
@@ -55,7 +55,13 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { @@ -55,7 +55,13 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
55 * Enable to allow untrusted SSL ceriticates. 55 * Enable to allow untrusted SSL ceriticates.
56 * Useful for testing purposes. Use with caution in production. 56 * Useful for testing purposes. Use with caution in production.
57 */ 57 */
58 - SDWebImageAllowInvalidSSLCertificates = 1 << 7 58 + SDWebImageAllowInvalidSSLCertificates = 1 << 7,
  59 + /**
  60 + * By default, image are loaded in the order they were queued. This flag move them to
  61 + * the front of the queue and is loaded immediately instead of waiting for the current queue to be loaded (which
  62 + * could take a while).
  63 + */
  64 + SDWebImageHighPriority = 1 << 8
59 }; 65 };
60 66
61 typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType); 67 typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType);
@@ -127,6 +127,7 @@ @@ -127,6 +127,7 @@
127 if (options & SDWebImageContinueInBackground) downloaderOptions |= SDWebImageDownloaderContinueInBackground; 127 if (options & SDWebImageContinueInBackground) downloaderOptions |= SDWebImageDownloaderContinueInBackground;
128 if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies; 128 if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies;
129 if (options & SDWebImageAllowInvalidSSLCertificates) downloaderOptions |= SDWebImageDownloaderAllowInvalidSSLCertificates; 129 if (options & SDWebImageAllowInvalidSSLCertificates) downloaderOptions |= SDWebImageDownloaderAllowInvalidSSLCertificates;
  130 + if (options & SDWebImageHighPriority) downloaderOptions |= SDWebImageDownloaderHighPriority;
130 if (image && options & SDWebImageRefreshCached) { 131 if (image && options & SDWebImageRefreshCached) {
131 // force progressive off if image already cached but forced refreshing 132 // force progressive off if image already cached but forced refreshing
132 downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload; 133 downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;