Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#import "HomeViewPresenter.h"
#import "HomeView.h"
#import "HomeViewController.h"
#import "ImageViewController.h"
#import "ImageViewPresenter.h"
#import "UIImageHelper.h"
@interface HomeViewPresenter () {
UIImageHelper *imageHelper_;
}
@end
@implementation HomeViewPresenter
+ (HomeViewController *)createViewController {
HomeViewPresenter *presenter = [HomeViewPresenter new];
HomeViewController *viewController = [[HomeViewController alloc] initWithPresenter:presenter];
return viewController;
}
- (id)initWithImageHelper:(UIImageHelper *)imageHelper {
self = [super init];
if (self) {
imageHelper_ = imageHelper;
}
return self;
}
- (void)viewLoaded {
HomeView *homeView = [[self homeViewController] homeView];
if ([imageHelper_ isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[[homeView cameraButton] addTarget:self
action:@selector(cameraButtonSelected:)
forControlEvents:UIControlEventTouchUpInside];
} else {
[[homeView cameraButton] setEnabled:NO];
}
[[homeView galleryButton] addTarget:self
action:@selector(galleryButtonSelected:)
forControlEvents:UIControlEventTouchUpInside];
[[homeView inspireButton] addTarget:self
action:@selector(inspireButtonSelected:)
forControlEvents:UIControlEventTouchUpInside];
}
- (HomeViewController *)homeViewController {
return (HomeViewController *)[self viewController];
}
#pragma mark private
- (void)cameraButtonSelected:(id)sender {
[[self homeViewController] showImagePickerWithType:UIImagePickerControllerSourceTypeCamera
delegate:self
];
}
- (void)galleryButtonSelected:(id)sender {
[[self homeViewController] showImagePickerWithType:UIImagePickerControllerSourceTypePhotoLibrary
delegate:self];
}
- (void)inspireButtonSelected:(id)sender {
// TODO(cate): Implement.
NSLog(@"inspire button pressed");
}
#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = info[UIImagePickerControllerOriginalImage];
ImageViewController *imageViewController =
[ImageViewPresenter createViewControllerWithImage:image];
[[[self viewController] navigationController] pushViewController:imageViewController
animated:YES];
[[self viewController] dismissViewControllerAnimated:YES withCompletionBlock:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[[self viewController] dismissViewControllerAnimated:YES withCompletionBlock:nil];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment