Skip to content
This repository has been archived by the owner on Dec 6, 2018. It is now read-only.

Commit

Permalink
Initial work on FRPFullSizePhotoViewModel.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashfurrow committed Oct 22, 2013
1 parent 682d24b commit 7c3b80d
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 20 deletions.
18 changes: 16 additions & 2 deletions FRP.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
5E59511F18121D09002F44FA /* FRPLoginViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5E59511E18121D09002F44FA /* FRPLoginViewController.xib */; };
5E730B0E1815F3E4003FCB43 /* FRPGalleryViewModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E730B0D1815F3E4003FCB43 /* FRPGalleryViewModel.m */; };
5E730B101815F78B003FCB43 /* FRPGalleryViewModelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E730B0F1815F78B003FCB43 /* FRPGalleryViewModelTests.m */; };
5E730B141815FE97003FCB43 /* FRPFullSizePhotoViewModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E730B131815FE97003FCB43 /* FRPFullSizePhotoViewModel.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 */; };
Expand Down Expand Up @@ -57,6 +58,8 @@
5E730B0C1815F3E4003FCB43 /* FRPGalleryViewModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPGalleryViewModel.h; sourceTree = "<group>"; };
5E730B0D1815F3E4003FCB43 /* FRPGalleryViewModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPGalleryViewModel.m; sourceTree = "<group>"; };
5E730B0F1815F78B003FCB43 /* FRPGalleryViewModelTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPGalleryViewModelTests.m; sourceTree = "<group>"; };
5E730B121815FE97003FCB43 /* FRPFullSizePhotoViewModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPFullSizePhotoViewModel.h; sourceTree = "<group>"; };
5E730B131815FE97003FCB43 /* FRPFullSizePhotoViewModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPFullSizePhotoViewModel.m; sourceTree = "<group>"; };
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>"; };
Expand Down Expand Up @@ -120,8 +123,7 @@
isa = PBXGroup;
children = (
5E730B0B1815F39D003FCB43 /* Gallery */,
5E59510F180E065F002F44FA /* FRPFullSizePhotoViewController.h */,
5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */,
5E730B111815FE81003FCB43 /* Full Size Photo */,
5E595115180E0C33002F44FA /* FRPPhotoViewController.h */,
5E595116180E0C33002F44FA /* FRPPhotoViewController.m */,
5E595118180E21E0002F44FA /* FRPPhotoDetailViewController.h */,
Expand All @@ -144,6 +146,17 @@
name = Gallery;
sourceTree = "<group>";
};
5E730B111815FE81003FCB43 /* Full Size Photo */ = {
isa = PBXGroup;
children = (
5E59510F180E065F002F44FA /* FRPFullSizePhotoViewController.h */,
5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */,
5E730B121815FE97003FCB43 /* FRPFullSizePhotoViewModel.h */,
5E730B131815FE97003FCB43 /* FRPFullSizePhotoViewModel.m */,
);
name = "Full Size Photo";
sourceTree = "<group>";
};
5EBC599F180B267400B683A7 /* UICollectionView Extensions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -418,6 +431,7 @@
5E595117180E0C33002F44FA /* FRPPhotoViewController.m in Sources */,
5EBC59A6180B2AA200B683A7 /* FRPPhotoImporter.m in Sources */,
5EBE2B2B180B0AF1007B6BF3 /* FRPGalleryViewController.m in Sources */,
5E730B141815FE97003FCB43 /* FRPFullSizePhotoViewModel.m in Sources */,
5EBE2B07180B07D0007B6BF3 /* FRPAppDelegate.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
6 changes: 4 additions & 2 deletions FRP/FRPFullSizePhotoViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

@end


@class FRPFullSizePhotoViewModel;

@interface FRPFullSizePhotoViewController : UIViewController

-(instancetype)initWithPhotoModels:(NSArray *)photoModelArray currentPhotoIndex:(NSInteger)photoIndex;
@property (nonatomic, strong) FRPFullSizePhotoViewModel *viewModel;

@property (nonatomic, readonly) NSArray *photoModelArray;
@property (nonatomic, weak) id<FRPFullSizePhotoViewControllerDelegate> delegate;

@end
25 changes: 10 additions & 15 deletions FRP/FRPFullSizePhotoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,41 @@

// Models
#import "FRPPhotoModel.h"
#import "FRPFullSizePhotoViewModel.h"

@interface FRPFullSizePhotoViewController () <UIPageViewControllerDataSource, UIPageViewControllerDelegate>

// Private assignment
@property (nonatomic, strong) NSArray *photoModelArray;

// Private properties
@property (nonatomic, strong) UIPageViewController *pageViewController;

@end

@implementation FRPFullSizePhotoViewController

-(instancetype)initWithPhotoModels:(NSArray *)photoModelArray currentPhotoIndex:(NSInteger)photoIndex
-(instancetype)init
{
self = [self init];
self = [super init];
if (!self) return nil;

// Initialized, read-only properties
self.photoModelArray = photoModelArray;

// Configure self
self.title = [self.photoModelArray[photoIndex] photoName];

// View controllers
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:@{UIPageViewControllerOptionInterPageSpacingKey: @(30)}];
self.pageViewController.dataSource = self;
self.pageViewController.delegate = self;
[self addChildViewController:self.pageViewController];

[self.pageViewController setViewControllers:@[[self photoViewControllerForIndex:photoIndex]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

// Configure child view controllers
[self.pageViewController setViewControllers:@[[self photoViewControllerForIndex:self.viewModel.initialPhotoIndex]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

// Configure self
self.title = [self.viewModel.initialPhotoModel photoName];

@weakify(self);
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
infoButton.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
Expand Down Expand Up @@ -82,8 +77,8 @@ - (void)viewDidLoad
#pragma mark - Private Methods

-(FRPPhotoViewController *)photoViewControllerForIndex:(NSInteger)index {
if (index >= 0 && index < self.photoModelArray.count) {
FRPPhotoModel *photoModel = self.photoModelArray[index];
if (index >= 0 && index < self.viewModel.photoArray.count) {
FRPPhotoModel *photoModel = self.viewModel.photoArray[index];

FRPPhotoViewController *photoViewController = [[FRPPhotoViewController alloc] initWithPhotoModel:photoModel index:index];
return photoViewController;
Expand Down
22 changes: 22 additions & 0 deletions FRP/FRPFullSizePhotoViewModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// FRPFullSizePhotoViewModel.h
// FRP
//
// Created by Ash Furrow on 10/21/2013.
// Copyright (c) 2013 Ash Furrow. All rights reserved.
//

#import <Foundation/Foundation.h>

@class FRPPhotoModel;

@interface FRPFullSizePhotoViewModel : NSObject

-(instancetype)initWithPhotoModelArray:(NSArray *)photoModelArray initialPhotoIndex:(NSInteger)initialPhotoIndex;

@property (nonatomic, readonly) NSArray *photoArray;
@property (nonatomic, readonly) NSInteger initialPhotoIndex;

-(FRPPhotoModel *)initialPhotoModel;

@end
39 changes: 39 additions & 0 deletions FRP/FRPFullSizePhotoViewModel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// FRPFullSizePhotoViewModel.m
// FRP
//
// Created by Ash Furrow on 10/21/2013.
// Copyright (c) 2013 Ash Furrow. All rights reserved.
//

#import "FRPFullSizePhotoViewModel.h"

// Model
#import "FRPPhotoModel.h"


@interface FRPFullSizePhotoViewModel ()

// Private access
@property (nonatomic, strong) NSArray *photoArray;
@property (nonatomic, assign) NSInteger initialPhotoIndex;

@end

@implementation FRPFullSizePhotoViewModel

-(instancetype)initWithPhotoModelArray:(NSArray *)photoModelArray initialPhotoIndex:(NSInteger)initialPhotoIndex {
self = [self init];
if (!self) return nil;

self.photoArray = photoModelArray;
self.initialPhotoIndex = initialPhotoIndex;

return self;
}

-(FRPPhotoModel *)initialPhotoModel {
return self.photoArray[self.initialPhotoIndex];
}

@end
8 changes: 7 additions & 1 deletion FRP/FRPGalleryViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#import "FRPFullSizePhotoViewController.h"
#import "FRPLoginViewController.h"

// View models
#import "FRPGalleryViewModel.h"
#import "FRPFullSizePhotoViewModel.h"

// Views
#import "FRPCell.h"
Expand Down Expand Up @@ -67,7 +69,11 @@ - (void)viewDidLoad

[[self rac_signalForSelector:@selector(collectionView:didSelectItemAtIndexPath:) fromProtocol:@protocol(UICollectionViewDelegate)] subscribeNext:^(RACTuple *arguments) {
@strongify(self);
FRPFullSizePhotoViewController *viewController = [[FRPFullSizePhotoViewController alloc] initWithPhotoModels:self.viewModel.photosArray currentPhotoIndex:[(NSIndexPath *)arguments.second item]];

FRPFullSizePhotoViewModel *viewModel = [[FRPFullSizePhotoViewModel alloc] initWithPhotoModelArray:self.viewModel.photosArray initialPhotoIndex:[(NSIndexPath *)arguments.second item]];

FRPFullSizePhotoViewController *viewController = [[FRPFullSizePhotoViewController alloc] init];
viewController.viewModel = viewModel;
viewController.delegate = (id<FRPFullSizePhotoViewControllerDelegate>)self;
[self.navigationController pushViewController:viewController animated:YES];
}];
Expand Down

0 comments on commit 7c3b80d

Please sign in to comment.