Permalink
Browse files

Update SDWebImagePrefetecher.m

I added progress block that I need.
  • Loading branch information...
1 parent 895249b commit 159f08279af01deb77233545f29e5c29adafce77 @burakkilic burakkilic committed Feb 14, 2014
Showing with 6 additions and 2 deletions.
  1. +6 −2 SDWebImage/SDWebImagePrefetcher.m
@@ -17,6 +17,7 @@ @interface SDWebImagePrefetcher ()
@property (assign, nonatomic) NSUInteger finishedCount;
@property (assign, nonatomic) NSTimeInterval startedTime;
@property (copy, nonatomic) void (^completionBlock)(NSUInteger, NSUInteger);
+@property (copy, nonatomic) void (^progressBlock)(NSUInteger, NSUInteger);
@end
@@ -56,11 +57,13 @@ - (void)startPrefetchingAtIndex:(NSUInteger)index {
self.finishedCount++;
if (image) {
+ self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
#ifdef SD_VERBOSE
NSLog(@"Prefetched %d out of %d", self.finishedCount, self.prefetchURLs.count);
#endif
}
else {
+ self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
#ifdef SD_VERBOSE
NSLog(@"Prefetched %d out of %d (Failed)", self.finishedCount, [self.prefetchURLs count]);
#endif
@@ -103,14 +106,15 @@ - (void)reportStatus {
}
- (void)prefetchURLs:(NSArray *)urls {
- [self prefetchURLs:urls completed:nil];
+ [self prefetchURLs:urls progress:nil completed:nil];
}
-- (void)prefetchURLs:(NSArray *)urls completed:(void (^)(NSUInteger, NSUInteger))completionBlock {
+- (void)prefetchURLs:(NSArray *)urls progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(NSUInteger, NSUInteger))completionBlock {
@runmad

runmad Feb 15, 2014

Contributor

This method needs to be defined in the header file, the old method is still defined.

@runmad

runmad Feb 15, 2014

Contributor

PR: #637

[self cancelPrefetching]; // Prevent duplicate prefetch request
self.startedTime = CFAbsoluteTimeGetCurrent();
self.prefetchURLs = urls;
self.completionBlock = completionBlock;
+ self.progressBlock = progressBlock;
// Starts prefetching from the very first image on the list with the max allowed concurrency
NSUInteger listCount = self.prefetchURLs.count;

0 comments on commit 159f082

Please sign in to comment.