Permalink
Browse files

Add missing implementation

- Files must be available from a path, we won't fetch them for you
- Thumbnails are loaded lazily, but they're not cached on disk. This is by design, you can enable disk caching again by using SDURLCache
  • Loading branch information...
exalted committed Mar 28, 2012
1 parent 9428b00 commit d02b254a1e6e7d146a284b524fe58823bbba24e8
@@ -149,19 +149,13 @@ - (NSInteger)numberOfItemsInShowcaseView:(PTShowcaseView *)showcaseView
return [[self recursiveSearchForItems:self.demoItems forUniqueName:showcaseView.uniqueName] count];
}
-- (NSString *)showcaseView:(PTShowcaseView *)showcaseView uniqueNameForItemAtIndex:(NSInteger)index
-{
- return [[[self recursiveSearchForItems:self.demoItems forUniqueName:showcaseView.uniqueName] objectAtIndex:index]
- objectForKey:@"UniqueName"];
-}
-
- (PTContentType)showcaseView:(PTShowcaseView *)showcaseView contentTypeForItemAtIndex:(NSInteger)index
{
return [[[[self recursiveSearchForItems:self.demoItems forUniqueName:showcaseView.uniqueName] objectAtIndex:index]
objectForKey:@"ContentType"] integerValue];
}
-- (NSString *)showcaseView:(PTShowcaseView *)showcaseView sourceForItemAtIndex:(NSInteger)index
+- (NSString *)showcaseView:(PTShowcaseView *)showcaseView pathForItemAtIndex:(NSInteger)index
{
NSString *source = [[[self recursiveSearchForItems:self.demoItems forUniqueName:showcaseView.uniqueName] objectAtIndex:index]
objectForKey:@"Source"];
@@ -172,7 +166,13 @@ - (NSString *)showcaseView:(PTShowcaseView *)showcaseView sourceForItemAtIndex:(
return nil;
}
-- (NSString *)showcaseView:(PTShowcaseView *)showcaseView sourceForItemThumbnailAtIndex:(NSInteger)index
+- (NSString *)showcaseView:(PTShowcaseView *)showcaseView uniqueNameForItemAtIndex:(NSInteger)index
+{
+ return [[[self recursiveSearchForItems:self.demoItems forUniqueName:showcaseView.uniqueName] objectAtIndex:index]
+ objectForKey:@"UniqueName"];
+}
+
+- (NSString *)showcaseView:(PTShowcaseView *)showcaseView sourceForThumbnailImageOfItemAtIndex:(NSInteger)index
{
NSString *source = [[[self recursiveSearchForItems:self.demoItems forUniqueName:showcaseView.uniqueName] objectAtIndex:index]
objectForKey:@"Thumbnail"];
@@ -20,6 +20,6 @@
@interface PTImageDetailViewController : PTImageAlbumViewController
-@property (nonatomic, retain) NSArray *images;
+@property (nonatomic, retain) NSArray *data;
@end
@@ -20,7 +20,7 @@
@implementation PTImageDetailViewController
-@synthesize images = _images;
+@synthesize data = _data;
- (void)didReceiveMemoryWarning
{
@@ -53,37 +53,29 @@ - (void)viewDidUnload
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
- self.images = nil;
+ self.data = nil;
}
#pragma mark - PTImageAlbumViewDataSource
- (NSInteger)numberOfImagesInAlbumView:(PTImageAlbumView *)imageAlbumView
{
- return [self.images count];
+ return [self.data count];
}
-- (NSString *)imageAlbumView:(PTImageAlbumView *)imageAlbumView sourceForImageAtIndex:(NSInteger)index
+- (CGSize)imageAlbumView:(PTImageAlbumView *)imageAlbumView sizeForImageAtIndex:(NSInteger)index
{
- return [[self.images objectAtIndex:index] objectForKey:@"source"];
+ return [[UIImage imageWithContentsOfFile:[[self.data objectAtIndex:index] objectForKey:@"path"]] size];
}
-- (CGSize)imageAlbumView:(PTImageAlbumView *)imageAlbumView sizeForImageAtIndex:(NSInteger)index
+- (UIImage *)imageAlbumView:(PTImageAlbumView *)imageAlbumView imageAtIndex:(NSInteger)index
{
- // TODO temporary implementation
- // return original sized image's size
- return [[UIImage imageWithContentsOfFile:[self imageAlbumView:imageAlbumView sourceForImageAtIndex:index]] size];
+ return [UIImage imageWithContentsOfFile:[[self.data objectAtIndex:index] objectForKey:@"path"]];
}
- (NSString *)imageAlbumView:(PTImageAlbumView *)imageAlbumView sourceForThumbnailImageAtIndex:(NSInteger)index
{
- // TODO temporary implementation
- // replace with:
- // - create a thumbnail once the original image has been downloaded
- // - return thumbnail's sourcs
- // current:
- // - return original sized image
- return [self imageAlbumView:imageAlbumView sourceForImageAtIndex:index];
+ return [[self.data objectAtIndex:index] objectForKey:@"thumbnailImageSource"];
}
@end
@@ -35,12 +35,16 @@
- (id)initWithUniqueName:(NSString *)uniqueName;
- (NSInteger)numberOfItems;
-- (NSString *)uniqueNameForItemAtIndex:(NSInteger)index;
+
- (PTContentType)contentTypeForItemAtIndex:(NSInteger)index;
- (PTItemOrientation)orientationForItemAtIndex:(NSInteger)index;
-- (NSString *)sourceForItemAtIndex:(NSInteger)index;
-- (NSString *)sourceForItemThumbnailAtIndex:(NSInteger)index;
+
+- (NSString *)pathForItemAtIndex:(NSInteger)index;
+
+- (NSString *)uniqueNameForItemAtIndex:(NSInteger)index;
+- (NSString *)sourceForThumbnailImageOfItemAtIndex:(NSInteger)index;
- (NSString *)textForItemAtIndex:(NSInteger)index;
+
- (NSInteger)relativeIndexForItemAtIndex:(NSInteger)index withContentType:(PTContentType)contentType;
- (void)reloadData;
@@ -62,12 +62,6 @@ - (NSInteger)numberOfItems
return [self.data count];
}
-- (NSString *)uniqueNameForItemAtIndex:(NSInteger)index
-{
- id object = [[self.data objectAtIndex:index] objectForKey:@"uniqueName"];
- return object == [NSNull null] ? nil : object;
-}
-
- (PTContentType)contentTypeForItemAtIndex:(NSInteger)index
{
return [[[self.data objectAtIndex:index] objectForKey:@"contentType"] integerValue];
@@ -78,15 +72,21 @@ - (PTItemOrientation)orientationForItemAtIndex:(NSInteger)index
return [[[self.data objectAtIndex:index] objectForKey:@"orientation"] integerValue];
}
-- (NSString *)sourceForItemAtIndex:(NSInteger)index
+- (NSString *)uniqueNameForItemAtIndex:(NSInteger)index
+{
+ id object = [[self.data objectAtIndex:index] objectForKey:@"uniqueName"];
+ return object == [NSNull null] ? nil : object;
+}
+
+- (NSString *)pathForItemAtIndex:(NSInteger)index
{
- id object = [[self.data objectAtIndex:index] objectForKey:@"source"];
+ id object = [[self.data objectAtIndex:index] objectForKey:@"path"];
return object == [NSNull null] ? nil : object;
}
-- (NSString *)sourceForItemThumbnailAtIndex:(NSInteger)index
+- (NSString *)sourceForThumbnailImageOfItemAtIndex:(NSInteger)index
{
- id object = [[self.data objectAtIndex:index] objectForKey:@"thumbnailSource"];
+ id object = [[self.data objectAtIndex:index] objectForKey:@"thumbnailImageSource"];
return object == [NSNull null] ? nil : object;
}
@@ -116,20 +116,24 @@ - (void)reloadData
// Create an items' info array for reusing
self.data = [NSMutableArray arrayWithCapacity:numberOfItems];
for (NSInteger i = 0; i < numberOfItems; i++) {
- // Ask datasource and delegate for various data
- NSString *uniqueName = [self.showcaseDataSource showcaseView:self uniqueNameForItemAtIndex:i];
+ // Ask data source and delegate for various data
PTContentType contentType = [self.showcaseDataSource showcaseView:self contentTypeForItemAtIndex:i];
PTItemOrientation orientation = [self.showcaseDelegate showcaseView:self orientationForItemAtIndex:i];
- NSString *source = [self.showcaseDataSource showcaseView:self sourceForItemAtIndex:i];
- NSString *thumbnailSource = [self.showcaseDataSource showcaseView:self sourceForItemThumbnailAtIndex:i];
+
+ NSString *path = [self.showcaseDataSource showcaseView:self pathForItemAtIndex:i];
+ if (path) {
+ NSAssert([path hasPrefix:@"/"], @"path should be a valid non-relative (absolute) system path.");
+ }
+ NSString *uniqueName = [self.showcaseDataSource showcaseView:self uniqueNameForItemAtIndex:i];
+ NSString *thumbnailImageSource = [self.showcaseDataSource showcaseView:self sourceForThumbnailImageOfItemAtIndex:i];
NSString *text = [self.showcaseDataSource showcaseView:self textForItemAtIndex:i];
[self.data addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
- uniqueName ? uniqueName : [NSNull null], @"uniqueName",
[NSNumber numberWithInteger:contentType], @"contentType",
[NSNumber numberWithInteger:orientation], @"orientation",
- source ? source : [NSNull null], @"source",
- thumbnailSource ? thumbnailSource : [NSNull null], @"thumbnailSource",
+ path ? path : [NSNull null], @"path",
+ uniqueName ? uniqueName : [NSNull null], @"uniqueName",
+ thumbnailImageSource ? thumbnailImageSource : [NSNull null], @"thumbnailImageSource",
text ? text : [NSNull null], @"text",
nil]];
}
@@ -437,7 +437,7 @@ - (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInte
{
PTContentType contentType = [self.showcaseView contentTypeForItemAtIndex:index];
PTItemOrientation orientation = [self.showcaseView orientationForItemAtIndex:index];
- NSString *thumbnailImageSource = [self.showcaseView sourceForItemThumbnailAtIndex:index];
+ NSString *thumbnailImageSource = [self.showcaseView sourceForThumbnailImageOfItemAtIndex:index];
NSString *text = [self.showcaseView textForItemAtIndex:index];
// Dequeue or generate a new cell
@@ -463,10 +463,10 @@ - (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInte
- (void)GMGridView:(GMGridView *)gridView didTapOnItemAtIndex:(NSInteger)position
{
PTContentType contentType = [self.showcaseView contentTypeForItemAtIndex:position];
- NSInteger relativeIndex = [self.showcaseView relativeIndexForItemAtIndex:position withContentType:contentType];
NSString *uniqueName = [self.showcaseView uniqueNameForItemAtIndex:position];
- NSString *source = [self.showcaseView sourceForItemAtIndex:position];
+ NSString *path = [self.showcaseView pathForItemAtIndex:position];
NSString *text = [self.showcaseView textForItemAtIndex:position];
+ NSInteger relativeIndex = [self.showcaseView relativeIndexForItemAtIndex:position withContentType:contentType];
switch (contentType)
{
@@ -487,7 +487,7 @@ - (void)GMGridView:(GMGridView *)gridView didTapOnItemAtIndex:(NSInteger)positio
case PTContentTypeImage:
{
PTImageDetailViewController *detailViewController = [[PTImageDetailViewController alloc] initWithImageAtIndex:relativeIndex];
- detailViewController.images = self.showcaseView.imageItems;
+ detailViewController.data = self.showcaseView.imageItems;
detailViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[detailViewController.navigationItem setLeftBarButtonItem:
@@ -510,13 +510,13 @@ - (void)GMGridView:(GMGridView *)gridView didTapOnItemAtIndex:(NSInteger)positio
NSURL *url = nil;
// Check for file URLs.
- if ([source hasPrefix:@"/"]) {
+ if ([path hasPrefix:@"/"]) {
// If the url starts with / then it's likely a file URL, so treat it accordingly.
- url = [NSURL fileURLWithPath:source];
+ url = [NSURL fileURLWithPath:path];
}
else {
// Otherwise we assume it's a regular URL.
- url = [NSURL URLWithString:source];
+ url = [NSURL URLWithString:path];
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@@ -538,13 +538,13 @@ - (void)GMGridView:(GMGridView *)gridView didTapOnItemAtIndex:(NSInteger)positio
NSURL *url = nil;
// Check for file URLs.
- if ([source hasPrefix:@"/"]) {
+ if ([path hasPrefix:@"/"]) {
// If the url starts with / then it's likely a file URL, so treat it accordingly.
- url = [NSURL fileURLWithPath:source];
+ url = [NSURL fileURLWithPath:path];
}
else {
// Otherwise we assume it's a regular URL.
- url = [NSURL URLWithString:source];
+ url = [NSURL URLWithString:path];
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@@ -583,24 +583,24 @@ - (NSInteger)numberOfItemsInShowcaseView:(PTShowcaseView *)showcaseView
return -1;
}
-- (NSString *)showcaseView:(PTShowcaseView *)showcaseView uniqueNameForItemAtIndex:(NSInteger)index;
-{
- return nil;
-}
-
- (PTContentType)showcaseView:(PTShowcaseView *)showcaseView contentTypeForItemAtIndex:(NSInteger)index
{
NSAssert(NO, @"missing required method implementation 'showcaseView:contentTypeForItemAtIndex:'");
return -1;
}
-- (NSString *)showcaseView:(PTShowcaseView *)showcaseView sourceForItemAtIndex:(NSInteger)index
+- (NSString *)showcaseView:(PTShowcaseView *)showcaseView pathForItemAtIndex:(NSInteger)index
+{
+ NSAssert(NO, @"missing required method implementation 'showcaseView:pathForItemAtIndex:'");
+ return nil;
+}
+
+- (NSString *)showcaseView:(PTShowcaseView *)showcaseView uniqueNameForItemAtIndex:(NSInteger)index;
{
- NSAssert(NO, @"missing required method implementation 'showcaseView:sourceForItemAtIndex:'");
return nil;
}
-- (NSString *)showcaseView:(PTShowcaseView *)showcaseView sourceForItemThumbnailAtIndex:(NSInteger)index
+- (NSString *)showcaseView:(PTShowcaseView *)showcaseView sourceForThumbnailImageOfItemAtIndex:(NSInteger)index
{
return nil;
}
@@ -27,11 +27,11 @@
@required
- (NSInteger)numberOfItemsInShowcaseView:(PTShowcaseView *)showcaseView;
- (PTContentType)showcaseView:(PTShowcaseView *)showcaseView contentTypeForItemAtIndex:(NSInteger)index;
-- (NSString *)showcaseView:(PTShowcaseView *)showcaseView sourceForItemAtIndex:(NSInteger)index;
-- (NSString *)showcaseView:(PTShowcaseView *)showcaseView sourceForItemThumbnailAtIndex:(NSInteger)index;
+- (NSString *)showcaseView:(PTShowcaseView *)showcaseView pathForItemAtIndex:(NSInteger)index;
@optional
- (NSString *)showcaseView:(PTShowcaseView *)showcaseView uniqueNameForItemAtIndex:(NSInteger)index;
+- (NSString *)showcaseView:(PTShowcaseView *)showcaseView sourceForThumbnailImageOfItemAtIndex:(NSInteger)index;
- (NSString *)showcaseView:(PTShowcaseView *)showcaseView textForItemAtIndex:(NSInteger)index;
@end

0 comments on commit d02b254

Please sign in to comment.