diff --git a/FRP.xcodeproj/project.pbxproj b/FRP.xcodeproj/project.pbxproj index 4e86539..e7dc379 100644 --- a/FRP.xcodeproj/project.pbxproj +++ b/FRP.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 2826EB375D254DDD8DE6EAA8 /* libPods-FRP.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 772BE9E4C5824F1C8E5CDC45 /* libPods-FRP.a */; }; + 5E595111180E065F002F44FA /* FRPFullSizePhotoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */; }; + 5E595117180E0C33002F44FA /* FRPPhotoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E595116180E0C33002F44FA /* FRPPhotoViewController.m */; }; 5EBC599E180B247500B683A7 /* FRPCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBC599D180B247500B683A7 /* FRPCell.m */; }; 5EBC59A6180B2AA200B683A7 /* FRPPhotoImporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBC59A5180B2AA200B683A7 /* FRPPhotoImporter.m */; }; 5EBC59A9180B2C4F00B683A7 /* FRPGalleryFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBC59A8180B2C4F00B683A7 /* FRPGalleryFlowLayout.m */; }; @@ -38,6 +40,10 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 5E59510F180E065F002F44FA /* FRPFullSizePhotoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPFullSizePhotoViewController.h; sourceTree = ""; }; + 5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPFullSizePhotoViewController.m; sourceTree = ""; }; + 5E595115180E0C33002F44FA /* FRPPhotoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPPhotoViewController.h; sourceTree = ""; }; + 5E595116180E0C33002F44FA /* FRPPhotoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPPhotoViewController.m; sourceTree = ""; }; 5EBC599C180B247500B683A7 /* FRPCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPCell.h; sourceTree = ""; }; 5EBC599D180B247500B683A7 /* FRPCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPCell.m; sourceTree = ""; }; 5EBC59A0180B268600B683A7 /* FRPPhotoModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPPhotoModel.h; sourceTree = ""; }; @@ -95,6 +101,19 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 5E59510E180E0634002F44FA /* View Controllers */ = { + isa = PBXGroup; + children = ( + 5EBE2B29180B0AF1007B6BF3 /* FRPGalleryViewController.h */, + 5EBE2B2A180B0AF1007B6BF3 /* FRPGalleryViewController.m */, + 5E59510F180E065F002F44FA /* FRPFullSizePhotoViewController.h */, + 5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */, + 5E595115180E0C33002F44FA /* FRPPhotoViewController.h */, + 5E595116180E0C33002F44FA /* FRPPhotoViewController.m */, + ); + name = "View Controllers"; + sourceTree = ""; + }; 5EBC599F180B267400B683A7 /* UICollectionView Extensions */ = { isa = PBXGroup; children = ( @@ -153,10 +172,9 @@ children = ( 5EBE2B05180B07D0007B6BF3 /* FRPAppDelegate.h */, 5EBE2B06180B07D0007B6BF3 /* FRPAppDelegate.m */, - 5EBE2B29180B0AF1007B6BF3 /* FRPGalleryViewController.h */, - 5EBE2B2A180B0AF1007B6BF3 /* FRPGalleryViewController.m */, 5EBC59A4180B2AA200B683A7 /* FRPPhotoImporter.h */, 5EBC59A5180B2AA200B683A7 /* FRPPhotoImporter.m */, + 5E59510E180E0634002F44FA /* View Controllers */, 5EBC59A3180B268A00B683A7 /* Models */, 5EBC599F180B267400B683A7 /* UICollectionView Extensions */, 5EBE2B0B180B07D0007B6BF3 /* Images.xcassets */, @@ -326,8 +344,10 @@ buildActionMask = 2147483647; files = ( 5EBC599E180B247500B683A7 /* FRPCell.m in Sources */, + 5E595111180E065F002F44FA /* FRPFullSizePhotoViewController.m in Sources */, 5EBC59A9180B2C4F00B683A7 /* FRPGalleryFlowLayout.m in Sources */, 5EBE2B03180B07D0007B6BF3 /* main.m in Sources */, + 5E595117180E0C33002F44FA /* FRPPhotoViewController.m in Sources */, 5EBC59A6180B2AA200B683A7 /* FRPPhotoImporter.m in Sources */, 5EBE2B2B180B0AF1007B6BF3 /* FRPGalleryViewController.m in Sources */, 5EBE2B07180B07D0007B6BF3 /* FRPAppDelegate.m in Sources */, diff --git a/FRP/FRP-Info.plist b/FRP/FRP-Info.plist index 77787b9..ec259d3 100644 --- a/FRP/FRP-Info.plist +++ b/FRP/FRP-Info.plist @@ -31,8 +31,6 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight diff --git a/FRP/FRPFullSizePhotoViewController.h b/FRP/FRPFullSizePhotoViewController.h new file mode 100644 index 0000000..7ea97f5 --- /dev/null +++ b/FRP/FRPFullSizePhotoViewController.h @@ -0,0 +1,18 @@ +// +// FRPFullSizePhotoViewController.h +// FRP +// +// Created by Ash Furrow on 10/15/2013. +// Copyright (c) 2013 Ash Furrow. All rights reserved. +// + +#import + +@interface FRPFullSizePhotoViewController : UIViewController + +-(instancetype)initWithPhotoModels:(NSArray *)photoModelArray currentPhotoIndex:(NSInteger)photoIndex; + +@property (nonatomic, readonly) NSArray *photoModelArray; +@property (nonatomic, readonly) NSInteger photoIndex; + +@end diff --git a/FRP/FRPFullSizePhotoViewController.m b/FRP/FRPFullSizePhotoViewController.m new file mode 100644 index 0000000..aa88b96 --- /dev/null +++ b/FRP/FRPFullSizePhotoViewController.m @@ -0,0 +1,81 @@ +// +// FRPFullSizePhotoViewController.m +// FRP +// +// Created by Ash Furrow on 10/15/2013. +// Copyright (c) 2013 Ash Furrow. All rights reserved. +// + +// View Controllers +#import "FRPFullSizePhotoViewController.h" +#import "FRPPhotoViewController.h" + +@interface FRPFullSizePhotoViewController () + +// Private assignment +@property (nonatomic, strong) NSArray *photoModelArray; +@property (nonatomic, assign) NSInteger photoIndex; + +// Private properties +@property (nonatomic, strong) UIPageViewController *pageViewController; + +@end + +@implementation FRPFullSizePhotoViewController + +-(instancetype)initWithPhotoModels:(NSArray *)photoModelArray currentPhotoIndex:(NSInteger)photoIndex +{ + self = [self init]; + if (!self) return nil; + + // Initialized, read-only properties + self.photoModelArray = photoModelArray; + self.photoIndex = photoIndex; + + // View controllers + self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:@{UIPageViewControllerOptionInterPageSpacingKey: @(30)}]; + self.pageViewController.dataSource = self; + [self addChildViewController:self.pageViewController]; + + [self.pageViewController setViewControllers:@[[self photoViewControllerForIndex:photoIndex]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; + + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + // Configure self's view + self.view.backgroundColor = [UIColor blackColor]; + + // Configure subviews + self.pageViewController.view.frame = self.view.bounds; + [self.view addSubview:self.pageViewController.view]; +} + +#pragma mark - Private Methods + +-(FRPPhotoViewController *)photoViewControllerForIndex:(NSInteger)index { + if (index >= 0 && index < self.photoModelArray.count) { + FRPPhotoModel *photoModel = self.photoModelArray[index]; + + FRPPhotoViewController *photoViewController = [[FRPPhotoViewController alloc] initWithPhotoModel:photoModel index:index]; + return photoViewController; + } + + // Index was out of bounds, return nil + return nil; +} + +#pragma mark - UIPageViewControllerDataSource Methods + +- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(FRPPhotoViewController *)viewController { + return [self photoViewControllerForIndex:viewController.photoIndex - 1]; +} + +- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(FRPPhotoViewController *)viewController { + return [self photoViewControllerForIndex:viewController.photoIndex + 1]; +} + +@end diff --git a/FRP/FRPGalleryViewController.m b/FRP/FRPGalleryViewController.m index b9b3b2f..0a021af 100644 --- a/FRP/FRPGalleryViewController.m +++ b/FRP/FRPGalleryViewController.m @@ -6,8 +6,14 @@ // Copyright (c) 2013 Ash Furrow. All rights reserved. // +// View Controllers #import "FRPGalleryViewController.h" +#import "FRPFullSizePhotoViewController.h" + +// Views #import "FRPCell.h" + +// Utilities #import "FRPGalleryFlowLayout.h" #import "FRPPhotoImporter.h" @@ -77,4 +83,12 @@ static NSString *CellIdentifier = @"Cell"; return cell; } +#pragma mark - UICollectionViewDelegate Methods + +// Note: Can't use rac_signalForSelector: here w/o implementing this method. +-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { + FRPFullSizePhotoViewController *viewController = [[FRPFullSizePhotoViewController alloc] initWithPhotoModels:self.photosArray currentPhotoIndex:indexPath.item]; + [self.navigationController pushViewController:viewController animated:YES]; +} + @end diff --git a/FRP/FRPPhotoModel.h b/FRP/FRPPhotoModel.h index b0c0711..0f7b554 100644 --- a/FRP/FRPPhotoModel.h +++ b/FRP/FRPPhotoModel.h @@ -15,5 +15,7 @@ @property (nonatomic, strong) NSNumber *rating; @property (nonatomic, strong) NSString *thumbnailURL; @property (nonatomic, strong) NSData *thumbnailData; +@property (nonatomic, strong) NSString *fullsizedURL; +@property (nonatomic, strong) NSData *fullsizedData; @end diff --git a/FRP/FRPPhotoViewController.h b/FRP/FRPPhotoViewController.h new file mode 100644 index 0000000..848eff7 --- /dev/null +++ b/FRP/FRPPhotoViewController.h @@ -0,0 +1,20 @@ +// +// FRPPhotoViewController.h +// FRP +// +// Created by Ash Furrow on 10/15/2013. +// Copyright (c) 2013 Ash Furrow. All rights reserved. +// + +#import + +@class FRPPhotoModel; + +@interface FRPPhotoViewController : UIViewController + +-(instancetype)initWithPhotoModel:(FRPPhotoModel *)photoModel index:(NSInteger)photoIndex; + +@property (nonatomic, readonly) NSInteger photoIndex; +@property (nonatomic, readonly) FRPPhotoModel *photoModel; + +@end diff --git a/FRP/FRPPhotoViewController.m b/FRP/FRPPhotoViewController.m new file mode 100644 index 0000000..dda4601 --- /dev/null +++ b/FRP/FRPPhotoViewController.m @@ -0,0 +1,60 @@ +// +// FRPPhotoViewController.m +// FRP +// +// Created by Ash Furrow on 10/15/2013. +// Copyright (c) 2013 Ash Furrow. All rights reserved. +// + +#import "FRPPhotoViewController.h" + +// Model +#import "FRPPhotoModel.h" + +@interface FRPPhotoViewController () + +// Private assignment +@property (nonatomic, assign) NSInteger photoIndex; +@property (nonatomic, strong) FRPPhotoModel *photoModel; + +// Private properties +@property (nonatomic, weak) UIImageView *imageView; + +@end + +@implementation FRPPhotoViewController + +-(instancetype)initWithPhotoModel:(FRPPhotoModel *)photoModel index:(NSInteger)photoIndex +{ + self = [self init]; + if (!self) return nil; + + self.photoModel = photoModel; + self.photoIndex = photoIndex; + + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + // Configure self's view + self.view.backgroundColor = [UIColor blackColor]; + + // Configure subviews + UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds]; + RAC(imageView, image) = [RACObserve(self.photoModel, fullsizedData) map:^id(id value) { + return [UIImage imageWithData:value]; + }]; + [self.view addSubview:imageView]; + self.imageView = imageView; +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +@end