Created
May 8, 2012 03:36
-
-
Save casspangell/2632355 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation ProjectsViewController | |
@synthesize imageView, swipeUpGR, theProjects, tapGR, arrayOfImages; | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | |
{ | |
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | |
if (self) | |
{ | |
// Custom initialization | |
arrayOfImages = [[NSMutableArray alloc] init]; | |
theProjects = [[NSMutableArray alloc] init]; | |
currentItem = 0; | |
dataLaoder = [[ProjectsDataLoader alloc] init]; | |
deviceIsPad = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad); | |
if (deviceIsPad) | |
{ | |
baseWidth = 1800.0; | |
baseHeight = 2300.0; | |
} | |
else | |
{ | |
baseWidth = 320.0; | |
baseHeight = 440.0; | |
} | |
} | |
return self; | |
} | |
- (void)dealloc | |
{ | |
[super dealloc]; | |
[theProjects release]; | |
[arrayOfImages release]; | |
[dataLaoder release]; | |
[projectsNOLabel release]; | |
[promotersLabel release]; | |
[titleLabel release]; | |
[categoryImage release]; | |
[imageView release]; | |
[projectDetails release]; | |
} | |
- (IBAction)logoutButtonOnClick:(id)sender | |
{ | |
NSLog(@"click log out projects"); | |
SergeAppDelegate *myDelegate = (SergeAppDelegate*)[[UIApplication sharedApplication] delegate]; | |
[[[[myDelegate navigationController] topViewController] navigationController] popViewControllerAnimated:YES]; | |
[myDelegate.window addSubview:myDelegate.window.rootViewController.view]; | |
[myDelegate.window makeKeyAndVisible]; | |
[FFSFHFKeychainUtils deleteItemForUsername:[[NSUserDefaults standardUserDefaults] valueForKey:@"autoLoginUserName"] andServiceName:@"ff_service" error:nil]; | |
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"autoLoginUserName"]; | |
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"SHOWINSTRUCTIONS"]; | |
[[NSUserDefaults standardUserDefaults] synchronize]; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
} | |
-(void) resetContent | |
{ | |
currentItem = 0; | |
theProjects = [dataLaoder theProjects]; | |
int noOfProjects = [ theProjects count]; | |
if(noOfProjects > 0) | |
{ | |
for(int i =0 ;i < noOfProjects; i++) | |
{ | |
NSLog(@"objectAtIndex: %@", [[theProjects objectAtIndex:i] valueForKey:@"mobile_image"]); | |
[arrayOfImages addObject:[[theProjects objectAtIndex:i] valueForKey:@"main_image"]]; | |
} | |
[self loadImage:0]; | |
} | |
// NSLog(@"array = %@", arrayOfImages); | |
} | |
#pragma mark - View lifecycle | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
UIGestureRecognizer *recognizer; | |
//left | |
recognizer = [[ UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeft:)]; | |
swipeUpGR = (UISwipeGestureRecognizer *)recognizer; | |
swipeUpGR.numberOfTouchesRequired = 1; | |
swipeUpGR.direction = UISwipeGestureRecognizerDirectionRight; | |
[self.view addGestureRecognizer:swipeUpGR]; | |
[recognizer release]; | |
//right | |
recognizer = [[ UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRight:)]; | |
swipeUpGR = (UISwipeGestureRecognizer *)recognizer; | |
swipeUpGR.numberOfTouchesRequired = 1; | |
swipeUpGR.direction = UISwipeGestureRecognizerDirectionLeft; | |
[self.view addGestureRecognizer:swipeUpGR]; | |
[recognizer release]; | |
// taps | |
recognizer = [[ UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; | |
tapGR = (UITapGestureRecognizer *)recognizer; | |
tapGR.numberOfTapsRequired = 1; | |
tapGR.numberOfTouchesRequired = 1; | |
[self.view addGestureRecognizer:tapGR]; | |
[recognizer release]; | |
} | |
-(void) handleLeft:(UISwipeGestureRecognizer *)recognizer { | |
NSLog(@"Left"); | |
int sizeOfArray = [arrayOfImages count]; | |
// int noOfProjects = [theProjects count]; | |
if(currentItem > 0 && currentItem <= sizeOfArray - 1) | |
{ | |
currentItem --; | |
[self loadImage:currentItem]; | |
UIView *currentView = imageView; | |
CATransition *animation = [CATransition animation]; | |
[animation setDuration:0.5]; | |
[animation setType:kCATransitionPush]; | |
[animation setSubtype:kCATransitionFromLeft]; | |
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; | |
[[currentView layer] addAnimation:animation forKey:@"SwitchToView1"]; | |
} | |
} | |
-(void) handleRight:(UISwipeGestureRecognizer *)recognizer { | |
NSLog(@"Right"); | |
int sizeOfArray = [arrayOfImages count]; | |
if(currentItem >= 0 && currentItem < sizeOfArray - 1) | |
{ | |
currentItem ++; | |
[self loadImage:currentItem]; | |
UIView *currentView = imageView; | |
CATransition *animation = [CATransition animation]; | |
[animation setDuration:0.2]; | |
[animation setType:kCATransitionPush]; | |
[animation setSubtype:kCATransitionFromRight]; | |
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; | |
[[currentView layer] addAnimation:animation forKey:@"SwitchToView1"]; | |
} | |
} | |
-(void) handleTap:(UISwipeGestureRecognizer *)recognizer { | |
NSLog(@"Tap"); | |
int sizeOfArray = [arrayOfImages count]; | |
if(currentItem >= 0 && currentItem <= sizeOfArray - 1) | |
{ | |
NSLog(@"film id = %@", [[theProjects objectAtIndex:currentItem] valueForKey:@"film_id"] ); | |
NSString *filmId = [[theProjects objectAtIndex:currentItem] valueForKey:@"film_id"]; | |
SergeAppDelegate *appDelegate = (SergeAppDelegate*)[[UIApplication sharedApplication] delegate]; | |
projectDetails = [[ProjectDetailsViewController alloc] initWithFilmId: filmId andTabIndex:@"0"]; | |
[projectDetails.view setFrame:CGRectMake(0, 20, 320, 480)]; | |
[appDelegate.window addSubview:[projectDetails view]]; | |
[appDelegate.window makeKeyAndVisible]; | |
} | |
} | |
- (void)viewDidUnload | |
{ | |
[super viewDidUnload]; | |
} | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation | |
{ | |
// Return YES for supported orientations | |
return (interfaceOrientation == UIInterfaceOrientationPortrait); | |
} | |
#pragma mark - load images - | |
-(void) loadImage:(int) index | |
{ | |
UIImageView *tempImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, baseWidth, baseHeight)]; | |
tempImage.backgroundColor = [UIColor clearColor]; | |
[imageView addSubview:tempImage]; | |
//movie image | |
NSString *urlFromAPI = [arrayOfImages objectAtIndex:index]; | |
NSURL *urlOfImage = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", @"http://filmfunds.com/api2/getProjects?mobileImages=TRUE", urlFromAPI]]; | |
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:urlOfImage]]; | |
NSLog(@"urlFromAPI: %@, urlOfImage: %@", urlFromAPI, urlOfImage); | |
[image scaleImageToSize:CGSizeMake(baseWidth, baseHeight)]; | |
[tempImage setImage: image]; | |
[image release]; | |
//status title | |
int noOfProjects = [theProjects count]; | |
NSString *statusTitle = [NSString stringWithFormat:@"%@%d%@%d", @"Projects ", index + 1, @"/", noOfProjects]; | |
projectsNOLabel.text = statusTitle; | |
//promoters | |
NSString *promoters = [[theProjects objectAtIndex:index] valueForKey:@"promoters"]; | |
NSString *stringPromotersLabel = [NSString stringWithFormat:@"%@%@", @"Promoters: ", promoters]; | |
promotersLabel.text = stringPromotersLabel; | |
//title | |
NSString *movieTitle = [[theProjects objectAtIndex:index] valueForKey:@"title"]; | |
titleLabel.text = movieTitle; | |
//stage | |
NSString * catString = [[theProjects objectAtIndex:index] valueForKey:@"stage"]; | |
int catInt = [catString intValue]; | |
UIImage * anImage = [UIImage imageNamed:[NSString stringWithFormat:@"cat%i.png",catInt]]; | |
[categoryImage setImage:anImage]; | |
[tempImage release]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment