Added FlickrPicture handling and displaying.

This commit is contained in:
etudiant 2014-04-30 18:35:16 +02:00
parent ea5b50732b
commit 73b3cb58c3
7 changed files with 93 additions and 3 deletions

View File

@ -30,6 +30,7 @@
5A11DD2718F68646007CE97C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5A11DD2518F68646007CE97C /* InfoPlist.strings */; }; 5A11DD2718F68646007CE97C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5A11DD2518F68646007CE97C /* InfoPlist.strings */; };
5A11DD2918F68646007CE97C /* FlikrkrTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A11DD2818F68646007CE97C /* FlikrkrTests.m */; }; 5A11DD2918F68646007CE97C /* FlikrkrTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A11DD2818F68646007CE97C /* FlikrkrTests.m */; };
5A11DD3318F6871F007CE97C /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5A11DD3218F6871F007CE97C /* Storyboard.storyboard */; }; 5A11DD3318F6871F007CE97C /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5A11DD3218F6871F007CE97C /* Storyboard.storyboard */; };
EC056A7A19114FCF006EB10D /* FlickPicture.m in Sources */ = {isa = PBXBuildFile; fileRef = EC056A7919114FCF006EB10D /* FlickPicture.m */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@ -71,6 +72,8 @@
5A11DD2618F68646007CE97C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; }; 5A11DD2618F68646007CE97C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
5A11DD2818F68646007CE97C /* FlikrkrTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FlikrkrTests.m; sourceTree = "<group>"; }; 5A11DD2818F68646007CE97C /* FlikrkrTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FlikrkrTests.m; sourceTree = "<group>"; };
5A11DD3218F6871F007CE97C /* Storyboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Storyboard.storyboard; sourceTree = "<group>"; }; 5A11DD3218F6871F007CE97C /* Storyboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Storyboard.storyboard; sourceTree = "<group>"; };
EC056A7819114FCF006EB10D /* FlickPicture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlickPicture.h; sourceTree = "<group>"; };
EC056A7919114FCF006EB10D /* FlickPicture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FlickPicture.m; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -143,6 +146,8 @@
5A11DD3218F6871F007CE97C /* Storyboard.storyboard */, 5A11DD3218F6871F007CE97C /* Storyboard.storyboard */,
5A066DD518F68EA500A16494 /* PictureViewController.h */, 5A066DD518F68EA500A16494 /* PictureViewController.h */,
5A066DD618F68EA500A16494 /* PictureViewController.m */, 5A066DD618F68EA500A16494 /* PictureViewController.m */,
EC056A7819114FCF006EB10D /* FlickPicture.h */,
EC056A7919114FCF006EB10D /* FlickPicture.m */,
5A066DD818F68EE900A16494 /* ReaderView.h */, 5A066DD818F68EE900A16494 /* ReaderView.h */,
5A066DD918F68EE900A16494 /* ReaderView.m */, 5A066DD918F68EE900A16494 /* ReaderView.m */,
5A11DD1418F68644007CE97C /* Images.xcassets */, 5A11DD1418F68644007CE97C /* Images.xcassets */,
@ -286,6 +291,7 @@
5A066DD718F68EA500A16494 /* PictureViewController.m in Sources */, 5A066DD718F68EA500A16494 /* PictureViewController.m in Sources */,
5A11DD1018F68644007CE97C /* AppDelegate.m in Sources */, 5A11DD1018F68644007CE97C /* AppDelegate.m in Sources */,
5A066DDA18F68EE900A16494 /* ReaderView.m in Sources */, 5A066DDA18F68EE900A16494 /* ReaderView.m in Sources */,
EC056A7A19114FCF006EB10D /* FlickPicture.m in Sources */,
5A11DD0C18F68644007CE97C /* main.m in Sources */, 5A11DD0C18F68644007CE97C /* main.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;

BIN
Flikrkr/._FlickPicture.h Normal file

Binary file not shown.

BIN
Flikrkr/._FlickPicture.m Normal file

Binary file not shown.

28
Flikrkr/FlickPicture.h Normal file
View File

@ -0,0 +1,28 @@
//
// FlickPicture.h
// Flikrkr
//
// Created by etudiant on 30/04/2014.
// Copyright (c) 2014 Oui. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef struct
{
double latitude;
double longitude;
int radius;
}FlickLocation;
@interface FlickPicture : NSObject
@property (strong, nonatomic) NSString * pictureId;
@property (strong, nonatomic) NSNumber * farm;
@property (strong, nonatomic) NSString * server;
@property (strong, nonatomic) NSString * secret;
@property (strong, nonatomic) NSString * title;
- (NSURL*) url;
+ (NSArray*) picturesAroundLocation:(FlickLocation) location;
@end

42
Flikrkr/FlickPicture.m Normal file
View File

@ -0,0 +1,42 @@
//
// FlickPicture.m
// Flikrkr
//
// Created by etudiant on 30/04/2014.
// Copyright (c) 2014 Oui. All rights reserved.
//
#import "FlickPicture.h"
#define kFlickrAPIKey @"045f3e02082b7820ff89bb17c38f1e5d"
@implementation FlickPicture
- (NSURL *)url
{
NSString * urlString = [NSString stringWithFormat:@"http://farm%i.staticflickr.com/%@/%@_%@.jpg", self.farm.intValue, self.server, self.pictureId, self.secret];
return [NSURL URLWithString:urlString];
}
+ (NSArray *)picturesAroundLocation:(FlickLocation)location
{
NSString * urlString = [NSString stringWithFormat:@"https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=%@&lat=%f&lon=%f&radius=%i&format=json&nojsoncallback=1",kFlickrAPIKey, location.latitude, location.longitude, location.radius];
NSURL * url = [NSURL URLWithString:urlString];
NSData * data = [NSData dataWithContentsOfURL:url];
NSDictionary * jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSMutableArray * pictures = [NSMutableArray arrayWithCapacity:[jsonData[@"photos"][@"photo"] count]];
for (NSDictionary * currentPicture in jsonData[@"photos"][@"photo"]) {
FlickPicture * picture = [[FlickPicture alloc] init];
picture.pictureId = currentPicture[@"id"];
picture.server = currentPicture[@"server"];
picture.secret = currentPicture[@"secret"];
picture.farm = currentPicture[@"farm"];
picture.title = currentPicture[@"title"];
[pictures addObject:picture];
}
return [NSArray arrayWithArray:pictures];
}
@end

View File

@ -7,7 +7,10 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "FlickPicture.h"
@interface PictureViewController : UIViewController @interface PictureViewController : UIViewController
@property (assign, nonatomic) FlickLocation location;
@end @end

View File

@ -12,6 +12,7 @@
@interface PictureViewController () <ReaderViewDelegate> @interface PictureViewController () <ReaderViewDelegate>
@property (weak, nonatomic) IBOutlet ReaderView *readerView; @property (weak, nonatomic) IBOutlet ReaderView *readerView;
@property (strong, nonatomic) NSArray * pictures;
@end @end
@ -30,6 +31,12 @@
{ {
[super viewDidLoad]; [super viewDidLoad];
// Do any additional setup after loading the view. // Do any additional setup after loading the view.
FlickLocation location;
location.latitude = 51.500773;
location.longitude = -0.12464;
location.radius = 1;
self.pictures = [FlickPicture picturesAroundLocation:location];
self.readerView.delegate = self; self.readerView.delegate = self;
} }
- (void) viewDidAppear:(BOOL)animated - (void) viewDidAppear:(BOOL)animated
@ -39,12 +46,16 @@
} }
- (int) numberOfPages - (int) numberOfPages
{ {
return 5; return self.pictures.count;
} }
- (UIView *) pageAtIndex:(int)index - (UIView *) pageAtIndex:(int)index
{ {
NSString * imageName = [NSString stringWithFormat:@"%i.jpg",index]; //NSString * imageName = [NSString stringWithFormat:@"%i.jpg",index];
UIImage * image = [UIImage imageNamed:imageName]; //UIImage * image = [UIImage imageNamed:imageName];
FlickPicture * picture = self.pictures[index];
NSData * imageData = [NSData dataWithContentsOfURL:picture.url];
UIImage * image = [UIImage imageWithData:imageData];
UIImageView * imageView = [[UIImageView alloc] initWithImage: image]; UIImageView * imageView = [[UIImageView alloc] initWithImage: image];
imageView.frame = self.readerView.bounds; imageView.frame = self.readerView.bounds;
imageView.contentMode = UIViewContentModeScaleAspectFit; imageView.contentMode = UIViewContentModeScaleAspectFit;