mirror of
https://github.com/zhigang1992/FunctionalReactivePixels.git
synced 2026-01-12 22:47:31 +08:00
Abstract all the things.
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
/* 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 */; };
|
||||
5EBE2AF7180B07D0007B6BF3 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EBE2AF6180B07D0007B6BF3 /* CoreGraphics.framework */; };
|
||||
5EBE2AF9180B07D0007B6BF3 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EBE2AF8180B07D0007B6BF3 /* UIKit.framework */; };
|
||||
@@ -38,6 +41,12 @@
|
||||
/* Begin PBXFileReference section */
|
||||
5EBC599C180B247500B683A7 /* FRPCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPCell.h; sourceTree = "<group>"; };
|
||||
5EBC599D180B247500B683A7 /* FRPCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPCell.m; sourceTree = "<group>"; };
|
||||
5EBC59A0180B268600B683A7 /* FRPPhotoModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPPhotoModel.h; sourceTree = "<group>"; };
|
||||
5EBC59A1180B268600B683A7 /* FRPPhotoModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPPhotoModel.m; sourceTree = "<group>"; };
|
||||
5EBC59A4180B2AA200B683A7 /* FRPPhotoImporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPPhotoImporter.h; sourceTree = "<group>"; };
|
||||
5EBC59A5180B2AA200B683A7 /* FRPPhotoImporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPPhotoImporter.m; sourceTree = "<group>"; };
|
||||
5EBC59A7180B2C4F00B683A7 /* FRPGalleryFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPGalleryFlowLayout.h; sourceTree = "<group>"; };
|
||||
5EBC59A8180B2C4F00B683A7 /* FRPGalleryFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPGalleryFlowLayout.m; sourceTree = "<group>"; };
|
||||
5EBE2AF1180B07D0007B6BF3 /* FRP.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FRP.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
5EBE2AF4180B07D0007B6BF3 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||
5EBE2AF6180B07D0007B6BF3 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
|
||||
@@ -87,6 +96,26 @@
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
5EBC599F180B267400B683A7 /* UICollectionView Extensions */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5EBC599C180B247500B683A7 /* FRPCell.h */,
|
||||
5EBC599D180B247500B683A7 /* FRPCell.m */,
|
||||
5EBC59A7180B2C4F00B683A7 /* FRPGalleryFlowLayout.h */,
|
||||
5EBC59A8180B2C4F00B683A7 /* FRPGalleryFlowLayout.m */,
|
||||
);
|
||||
name = "UICollectionView Extensions";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
5EBC59A3180B268A00B683A7 /* Models */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5EBC59A0180B268600B683A7 /* FRPPhotoModel.h */,
|
||||
5EBC59A1180B268600B683A7 /* FRPPhotoModel.m */,
|
||||
);
|
||||
name = Models;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
5EBE2AE8180B07D0007B6BF3 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -127,8 +156,10 @@
|
||||
5EBE2B06180B07D0007B6BF3 /* FRPAppDelegate.m */,
|
||||
5EBE2B29180B0AF1007B6BF3 /* FRPGalleryViewController.h */,
|
||||
5EBE2B2A180B0AF1007B6BF3 /* FRPGalleryViewController.m */,
|
||||
5EBC599C180B247500B683A7 /* FRPCell.h */,
|
||||
5EBC599D180B247500B683A7 /* FRPCell.m */,
|
||||
5EBC59A4180B2AA200B683A7 /* FRPPhotoImporter.h */,
|
||||
5EBC59A5180B2AA200B683A7 /* FRPPhotoImporter.m */,
|
||||
5EBC59A3180B268A00B683A7 /* Models */,
|
||||
5EBC599F180B267400B683A7 /* UICollectionView Extensions */,
|
||||
5EBE2B0B180B07D0007B6BF3 /* Images.xcassets */,
|
||||
5EBE2AFD180B07D0007B6BF3 /* Supporting Files */,
|
||||
);
|
||||
@@ -295,8 +326,11 @@
|
||||
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 */,
|
||||
5EBC59A6180B2AA200B683A7 /* FRPPhotoImporter.m in Sources */,
|
||||
5EBE2B2B180B0AF1007B6BF3 /* FRPGalleryViewController.m in Sources */,
|
||||
5EBE2B07180B07D0007B6BF3 /* FRPAppDelegate.m in Sources */,
|
||||
);
|
||||
|
||||
13
FRP/FRPGalleryFlowLayout.h
Normal file
13
FRP/FRPGalleryFlowLayout.h
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// FRPGalleryFlowLayout.h
|
||||
// FRP
|
||||
//
|
||||
// Created by Ash Furrow on 10/13/2013.
|
||||
// Copyright (c) 2013 Ash Furrow. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface FRPGalleryFlowLayout : UICollectionViewFlowLayout
|
||||
|
||||
@end
|
||||
24
FRP/FRPGalleryFlowLayout.m
Normal file
24
FRP/FRPGalleryFlowLayout.m
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// FRPGalleryFlowLayout.m
|
||||
// FRP
|
||||
//
|
||||
// Created by Ash Furrow on 10/13/2013.
|
||||
// Copyright (c) 2013 Ash Furrow. All rights reserved.
|
||||
//
|
||||
|
||||
#import "FRPGalleryFlowLayout.h"
|
||||
|
||||
@implementation FRPGalleryFlowLayout
|
||||
|
||||
-(instancetype)init {
|
||||
if (!(self = [super init])) return nil;
|
||||
|
||||
self.itemSize = CGSizeMake(145, 145);
|
||||
self.minimumInteritemSpacing = 10;
|
||||
self.minimumLineSpacing = 10;
|
||||
self.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#import "FRPGalleryViewController.h"
|
||||
#import "FRPCell.h"
|
||||
#import "FRPGalleryFlowLayout.h"
|
||||
#import "FRPPhotoImporter.h"
|
||||
|
||||
static NSString *CellIdentifier = @"Cell";
|
||||
|
||||
@@ -21,16 +23,11 @@ static NSString *CellIdentifier = @"Cell";
|
||||
|
||||
- (id)init
|
||||
{
|
||||
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
|
||||
FRPGalleryFlowLayout *flowLayout = [[FRPGalleryFlowLayout alloc] init];
|
||||
|
||||
self = [super initWithCollectionViewLayout:flowLayout];
|
||||
if (!self) return nil;
|
||||
|
||||
flowLayout.itemSize = CGSizeMake(145, 145);
|
||||
flowLayout.minimumInteritemSpacing = 10;
|
||||
flowLayout.minimumLineSpacing = 10;
|
||||
flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -52,23 +49,17 @@ static NSString *CellIdentifier = @"Cell";
|
||||
[self.collectionView reloadData];
|
||||
}];
|
||||
|
||||
// Load data
|
||||
[self loadPopularPhotos];
|
||||
}
|
||||
|
||||
#pragma mark - Private Methods
|
||||
|
||||
-(void)loadPopularPhotos {
|
||||
NSURLRequest *request = [AppDelegate.apiHelper urlRequestForPhotoFeature:PXAPIHelperPhotoFeaturePopular resultsPerPage:100 page:1 photoSizes:PXPhotoModelSizeThumbnail sortOrder:PXAPIHelperSortOrderRating except:PXPhotoModelCategoryNude];
|
||||
|
||||
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
|
||||
if (data) {
|
||||
id results = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
||||
|
||||
self.photosArray = results[@"photos"];
|
||||
}
|
||||
else {
|
||||
NSLog(@"Couldn't fetch from 500px: %@", connectionError);
|
||||
}
|
||||
[[FRPPhotoImporter importPhotos] subscribeNext:^(id x) {
|
||||
self.photosArray = x;
|
||||
} error:^(NSError *error) {
|
||||
NSLog(@"Couldn't fetch photos from 500px: %@", error);
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
15
FRP/FRPPhotoImporter.h
Normal file
15
FRP/FRPPhotoImporter.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// FRPPhotoImporter.h
|
||||
// FRP
|
||||
//
|
||||
// Created by Ash Furrow on 10/13/2013.
|
||||
// Copyright (c) 2013 Ash Furrow. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface FRPPhotoImporter : NSObject
|
||||
|
||||
+(RACSubject *)importPhotos;
|
||||
|
||||
@end
|
||||
45
FRP/FRPPhotoImporter.m
Normal file
45
FRP/FRPPhotoImporter.m
Normal file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// FRPPhotoImporter.m
|
||||
// FRP
|
||||
//
|
||||
// Created by Ash Furrow on 10/13/2013.
|
||||
// Copyright (c) 2013 Ash Furrow. All rights reserved.
|
||||
//
|
||||
|
||||
#import "FRPPhotoImporter.h"
|
||||
#import "FRPPhotoModel.h"
|
||||
|
||||
@implementation FRPPhotoImporter
|
||||
|
||||
+(NSURLRequest *)urlRequest {
|
||||
return [AppDelegate.apiHelper urlRequestForPhotoFeature:PXAPIHelperPhotoFeaturePopular resultsPerPage:100 page:1 photoSizes:PXPhotoModelSizeThumbnail sortOrder:PXAPIHelperSortOrderRating except:PXPhotoModelCategoryNude];
|
||||
}
|
||||
|
||||
+(RACSubject *)importPhotos {
|
||||
RACSubject *subject = [RACSubject subject];
|
||||
|
||||
|
||||
NSURLRequest *request = [self urlRequest];
|
||||
|
||||
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
|
||||
if (data) {
|
||||
id results = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
||||
|
||||
[subject sendNext:[[results[@"photos"] rac_sequence] map:^id(NSDictionary *photoDictionary) {
|
||||
FRPPhotoModel *model = [FRPPhotoModel new];
|
||||
|
||||
//TODO: Set properties
|
||||
|
||||
return model;
|
||||
}]];
|
||||
[subject sendCompleted];
|
||||
}
|
||||
else {
|
||||
[subject sendError:connectionError];
|
||||
}
|
||||
}];
|
||||
|
||||
return subject;
|
||||
}
|
||||
|
||||
@end
|
||||
13
FRP/FRPPhotoModel.h
Normal file
13
FRP/FRPPhotoModel.h
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// FRPPhotoModel.h
|
||||
// FRP
|
||||
//
|
||||
// Created by Ash Furrow on 10/13/2013.
|
||||
// Copyright (c) 2013 Ash Furrow. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface FRPPhotoModel : NSObject
|
||||
|
||||
@end
|
||||
13
FRP/FRPPhotoModel.m
Normal file
13
FRP/FRPPhotoModel.m
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// FRPPhotoModel.m
|
||||
// FRP
|
||||
//
|
||||
// Created by Ash Furrow on 10/13/2013.
|
||||
// Copyright (c) 2013 Ash Furrow. All rights reserved.
|
||||
//
|
||||
|
||||
#import "FRPPhotoModel.h"
|
||||
|
||||
@implementation FRPPhotoModel
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user