This commit is contained in:
Ash Furrow
2013-10-14 15:49:45 -04:00
parent 8d39194fc7
commit a762903bb6
6 changed files with 61 additions and 17 deletions

View File

@@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
2826EB375D254DDD8DE6EAA8 /* libPods-FRP.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 772BE9E4C5824F1C8E5CDC45 /* libPods-FRP.a */; };
5EBC599E180B247500B683A7 /* FRPCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBC599D180B247500B683A7 /* FRPCell.m */; };
5EBC59A2180B268600B683A7 /* FRPPhotoModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBC59A1180B268600B683A7 /* FRPPhotoModel.m */; };
5EBC59A6180B2AA200B683A7 /* FRPPhotoImporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBC59A5180B2AA200B683A7 /* FRPPhotoImporter.m */; };
5EBC59A9180B2C4F00B683A7 /* FRPGalleryFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBC59A8180B2C4F00B683A7 /* FRPGalleryFlowLayout.m */; };
5EBE2AF5180B07D0007B6BF3 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EBE2AF4180B07D0007B6BF3 /* Foundation.framework */; };
@@ -326,7 +325,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5EBC59A2180B268600B683A7 /* FRPPhotoModel.m in Sources */,
5EBC599E180B247500B683A7 /* FRPCell.m in Sources */,
5EBC59A9180B2C4F00B683A7 /* FRPGalleryFlowLayout.m in Sources */,
5EBE2B03180B07D0007B6BF3 /* main.m in Sources */,

View File

@@ -8,6 +8,10 @@
#import <UIKit/UIKit.h>
@class FRPPhotoModel;
@interface FRPCell : UICollectionViewCell
-(void)setPhotoModel:(FRPPhotoModel *)photoModel;
@end

View File

@@ -7,25 +7,46 @@
//
#import "FRPCell.h"
#import "FRPPhotoModel.m"
@interface FRPCell ()
@property (nonatomic, weak) UIImageView *imageView;
@property (nonatomic, strong) RACDisposable *subscription;
@end
@implementation FRPCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
if (!self) return nil;
// Configure self
self.backgroundColor = [UIColor darkGrayColor];
// Configure subivews
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.contentView addSubview:imageView];
self.imageView = imageView;
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
-(void)prepareForReuse {
[super prepareForReuse];
[self.subscription dispose], self.subscription = nil;
}
-(void)setPhotoModel:(FRPPhotoModel *)photoModel {
self.subscription = [[[RACObserve(photoModel, thumbnailData) filter:^BOOL(id value) {
return ![value isKindOfClass:[NSNull class]];
}] map:^id(id value) {
return [UIImage imageWithData:value];
}] setKeyPath:@"image" onObject:self.imageView];
}
*/
@end

View File

@@ -25,7 +25,7 @@ static NSString *CellIdentifier = @"Cell";
{
FRPGalleryFlowLayout *flowLayout = [[FRPGalleryFlowLayout alloc] init];
self = [super initWithCollectionViewLayout:flowLayout];
self = [self initWithCollectionViewLayout:flowLayout];
if (!self) return nil;
return self;
@@ -72,7 +72,7 @@ static NSString *CellIdentifier = @"Cell";
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
FRPCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
cell.backgroundColor = [UIColor purpleColor];
[cell setPhotoModel:self.photosArray[indexPath.row]];
return cell;
}

View File

@@ -25,13 +25,14 @@
if (data) {
id results = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
[subject sendNext:[[results[@"photos"] rac_sequence] map:^id(NSDictionary *photoDictionary) {
[subject sendNext:[[[results[@"photos"] rac_sequence] map:^id(NSDictionary *photoDictionary) {
FRPPhotoModel *model = [FRPPhotoModel new];
//TODO: Set properties
[self configurePhotoModel:model withDictionary:photoDictionary];
[self downloadThumbnailForPhotoModel:model];
return model;
}]];
}] array]];
[subject sendCompleted];
}
else {
@@ -42,4 +43,18 @@
return subject;
}
+(void)configurePhotoModel:(FRPPhotoModel *)photoModel withDictionary:(NSDictionary *)dictionary {
photoModel.photoName = dictionary[@"name"];
photoModel.photographerName = dictionary[@"user"][@"username"];
photoModel.rating = dictionary[@"rating"];
photoModel.thumbnailURL = [dictionary[@"image_url"] firstObject];
}
+(void)downloadThumbnailForPhotoModel:(FRPPhotoModel *)photoModel {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:photoModel.thumbnailURL]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
photoModel.thumbnailData = data;
}];
}
@end

View File

@@ -10,4 +10,10 @@
@interface FRPPhotoModel : NSObject
@property (nonatomic, strong) NSString *photoName;
@property (nonatomic, strong) NSString *photographerName;
@property (nonatomic, strong) NSNumber *rating;
@property (nonatomic, strong) NSString *thumbnailURL;
@property (nonatomic, strong) NSData *thumbnailData;
@end