Skip to content

Commit

Permalink
gallery loading was really slow because it was fetching photos from d…
Browse files Browse the repository at this point in the history
…isk and creating thumbnails each time the view comes into view and when it scrolls. decided to cache that shit so that it flows smoothly. fixes #16
  • Loading branch information
seanmcgary committed Apr 17, 2012
1 parent d364d9c commit 0396591
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Binary file not shown.
2 changes: 2 additions & 0 deletions photohunt/GalleryCollectionViewController.h
Expand Up @@ -14,6 +14,8 @@

@property (strong, nonatomic) NSMutableArray *photos;

@property (strong, nonatomic) NSMutableDictionary *loadedPhotoItems;

- (id) init;

@end
13 changes: 8 additions & 5 deletions photohunt/GalleryCollectionViewController.m
Expand Up @@ -15,6 +15,7 @@ @interface GalleryCollectionViewController ()
@implementation GalleryCollectionViewController

@synthesize photos;
@synthesize loadedPhotoItems;

- (id) init
{
Expand All @@ -26,6 +27,8 @@ - (id) init

self.photos = [[NSMutableArray alloc] init];

self.loadedPhotoItems = [[NSMutableDictionary alloc] init];

}

return self;
Expand Down Expand Up @@ -99,14 +102,14 @@ - (SSCollectionViewItem *)collectionView:(SSCollectionView *)aCollectionView ite

NSString *photoPath = [photoData objectForKey:@"photoPath"];

GalleryPhotoViewItem *item = [[GalleryPhotoViewItem alloc] initWithImagePath:photoPath];



// get the image from disk
//UIImage *photo = [[UIImage alloc] initWithContentsOfFile:[photoData objectForKey:@"photoPath"]];

GalleryPhotoViewItem *item = [self.loadedPhotoItems objectForKey:photoPath];

if(!item){
item = [[GalleryPhotoViewItem alloc] initWithImagePath:photoPath];
[self.loadedPhotoItems setObject:item forKey:photoPath];
}

return item;
}
Expand Down
5 changes: 0 additions & 5 deletions photohunt/GalleryPhotoViewItem.m
Expand Up @@ -48,7 +48,6 @@ - (id)initWithImagePath: (NSString *)imagePath {
if (photo)
{

NSLog(@"Photo found");
photoImage = [[UIImage alloc] initWithData:photo];

UIImage *newImage = [AppHelper imageWithImage:photoImage scaledToSize:CGSizeMake(200, 200)];
Expand All @@ -58,10 +57,6 @@ - (id)initWithImagePath: (NSString *)imagePath {

}
}
else
{
NSLog(@"File does not exist");
}
}

return self;
Expand Down

0 comments on commit 0396591

Please sign in to comment.