-
Notifications
You must be signed in to change notification settings - Fork 4
/
FlickrPhoto.m
56 lines (49 loc) · 2.19 KB
/
FlickrPhoto.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// FlickrPhoto.m
// AnimatedPhotoViewer
//
// Created by Chad Berkley on 11/30/10.
// Copyright 2010 OffHeGoes. All rights reserved.
//
#import "FlickrPhoto.h"
#import "Session.h"
@implementation FlickrPhoto
@synthesize photoId, squareIconHeight, squareIconWidth, latitude, longitude, squareIconUrl, title;
//init with the dict that is returned from the Flickr class
- (id)initWithDict:(NSDictionary*)dict
{
if(self = [super init])
{
//fill out all of the fields from the dictionary
self.photoId = [[NSString stringWithFormat:@"%@", [dict objectForKey:@"id"]] intValue];
self.squareIconHeight = [[NSString stringWithFormat:@"%@", [dict objectForKey:@"height_sq"]] intValue];
self.squareIconWidth = [[NSString stringWithFormat:@"%@", [dict objectForKey:@"width_sq"]] intValue];
self.latitude = [[NSString stringWithFormat:@"%@", [dict objectForKey:@"latitude"]] floatValue];
self.longitude = [[NSString stringWithFormat:@"%@", [dict objectForKey:@"longitude"]] floatValue];
self.squareIconUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@", [dict objectForKey:@"url_sq"]]];
self.title = [NSString stringWithFormat:@"%@", [dict objectForKey:@"title"]];
}
return self;
}
//return an image view. Note that the photo must be downloaded first before you can do this.
- (UIImageView*)getImageView
{
NSLog(@"getting imageView for photo with id %i", self.photoId);
NSString *photoPath = [self getPath];
NSLog(@"creating imageView with photo at path %@", photoPath);
UIImage *photoImage = [[UIImage alloc] initWithContentsOfFile:[self getPath]];
UIImageView *photoImageView = [[UIImageView alloc] initWithImage:photoImage];
[photoImage release];
return photoImageView;
}
- (NSString*)getPath
{
// NSMutableArray *pathComponents = [[NSMutableArray alloc] initWithObjects:[Session sharedInstance].cachePath, [NSString stringWithFormat:@"%i",self.photoId], nil];
NSMutableArray *pathComponents = [[NSMutableArray alloc] init];
[pathComponents addObject:[Session sharedInstance].cachePath];
[pathComponents addObject:[NSString stringWithFormat:@"%i", self.photoId]];
NSString *photoPath = [NSString pathWithComponents:pathComponents];
NSLog(@"photo path is %@", photoPath);
return photoPath;
}
@end