Skip to content

Commit

Permalink
[photos] Fix a severe bug that caused photos to never load when scrub…
Browse files Browse the repository at this point in the history
…bing.

We weren't properly removing the photo tag from the loading queue when a photo
request was canceled, causing the controller to think that photos were perpetually
loading even though the operation had been canceled.
  • Loading branch information
jverkoey committed Jan 31, 2012
1 parent e044af0 commit 9081680
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
Expand Up @@ -261,6 +261,9 @@ - (void)photoAlbumScrollView: (NIPhotoAlbumScrollView *)photoAlbumScrollView
for (NIOperation* op in [self.queue operations]) {
if (op.tag == photoIndex) {
[op cancel];

[self didCancelRequestWithPhotoSize:NIPhotoScrollViewPhotoSizeOriginal
photoIndex:photoIndex];
}
}
}
Expand Down
Expand Up @@ -285,6 +285,9 @@ - (void)photoAlbumScrollView: (NIPhotoAlbumScrollView *)photoAlbumScrollView
for (NIOperation* op in [self.queue operations]) {
if (op.tag == photoIndex) {
[op cancel];

[self didCancelRequestWithPhotoSize:NIPhotoScrollViewPhotoSizeOriginal
photoIndex:photoIndex];
}
}
}
Expand Down
Expand Up @@ -101,4 +101,7 @@
photoSize: (NIPhotoScrollViewPhotoSize)photoSize
photoIndex: (NSInteger)photoIndex;

- (void)didCancelRequestWithPhotoSize:(NIPhotoScrollViewPhotoSize)photoSize
photoIndex:(NSInteger)photoIndex;

@end
Expand Up @@ -57,12 +57,27 @@ - (NSString *)cacheKeyForPhotoIndex:(NSInteger)photoIndex {


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)requestImageFromSource: (NSString *)source
photoSize: (NIPhotoScrollViewPhotoSize)photoSize
photoIndex: (NSInteger)photoIndex {
- (NSInteger)identifierWithPhotoSize:(NIPhotoScrollViewPhotoSize)photoSize
photoIndex:(NSInteger)photoIndex {
BOOL isThumbnail = (NIPhotoScrollViewPhotoSizeThumbnail == photoSize);
NSInteger identifier = isThumbnail ? -(photoIndex + 1) : photoIndex;
NSNumber* identifierKey = [NSNumber numberWithInt:identifier];
return identifier;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)identifierKeyFromIdentifier:(NSInteger)identifier {
return [NSNumber numberWithInt:identifier];
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)requestImageFromSource:(NSString *)source
photoSize:(NIPhotoScrollViewPhotoSize)photoSize
photoIndex:(NSInteger)photoIndex {
BOOL isThumbnail = (NIPhotoScrollViewPhotoSizeThumbnail == photoSize);
NSInteger identifier = [self identifierWithPhotoSize:photoSize photoIndex:photoIndex];
id identifierKey = [self identifierKeyFromIdentifier:identifier];

// Avoid duplicating requests.
if ([_activeRequests containsObject:identifierKey]) {
Expand All @@ -77,7 +92,7 @@ - (void)requestImageFromSource: (NSString *)source

// Set an negative index for thumbnail requests so that they don't get cancelled by
// photoAlbumScrollView:stopLoadingPhotoAtIndex:
readOp.tag = isThumbnail ? -(photoIndex + 1) : photoIndex;
readOp.tag = identifier;

NSString* photoIndexKey = [self cacheKeyForPhotoIndex:photoIndex];

Expand Down Expand Up @@ -135,6 +150,15 @@ - (void)requestImageFromSource: (NSString *)source
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)didCancelRequestWithPhotoSize:(NIPhotoScrollViewPhotoSize)photoSize
photoIndex:(NSInteger)photoIndex {
NSInteger identifier = [self identifierWithPhotoSize:photoSize photoIndex:photoIndex];
id identifierKey = [self identifierKeyFromIdentifier:identifier];
[_activeRequests removeObject:identifierKey];
}


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
Expand Down

0 comments on commit 9081680

Please sign in to comment.