Skip to content

Commit

Permalink
cleaned up code and refactored to only open scan view after popup but…
Browse files Browse the repository at this point in the history
…ton is pressed
  • Loading branch information
tapickell committed Jan 18, 2014
1 parent 2f25717 commit d8f76dd
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 284 deletions.
199 changes: 39 additions & 160 deletions Giddy Goat Coffee/GGCPunchViewController.m

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions Giddy Goat Coffee/Giddy Goat Coffee/GGCAppDelegate.m
Expand Up @@ -48,46 +48,29 @@ @implementation GGCAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[TestFlight takeOff:@"4b4e8a904763818917de01b7c76985f2_OTg3MzcyMDEyLTA2LTEwIDE5OjQ0OjQ2LjAyNTkxMg"];

//stuff for viewDeck
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSLog(@"alloc window");

UIStoryboard *stb = [UIStoryboard storyboardWithName:@"NewStoryboard" bundle:nil];
NSLog(@"got storyboard");

_punchVC = [stb instantiateViewControllerWithIdentifier:@"punch"];
_firstVC = [stb instantiateViewControllerWithIdentifier:@"specials"];
_secondVC = [stb instantiateViewControllerWithIdentifier:@"coffees"];

IIViewDeckController* deckController = [[IIViewDeckController alloc] initWithCenterViewController:_punchVC
leftViewController:_firstVC
rightViewController:_secondVC];
NSLog(@"added vc's to new deck controller");
deckController.rightLedge = 10;
deckController.leftLedge = 10;

self.window.rootViewController = deckController;
NSLog(@"set deck controller as root view controller");
[self.window makeKeyAndVisible];
NSLog(@"make window key and visible");
//end stuff for viewDeck
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
[TestFlight passCheckpoint:@"APP_DID_ENTER_BACKGROUND"];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
Expand All @@ -102,8 +85,6 @@ - (void)applicationDidBecomeActive:(UIApplication *)application

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
[TestFlight passCheckpoint:@"APP_WILL_TREMINATE"];
}


Expand Down
6 changes: 0 additions & 6 deletions Giddy Goat Coffee/Giddy Goat Coffee/GGCDetailViewController.m
Expand Up @@ -44,25 +44,20 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"detail view did load");
// Do any additional setup after loading the view.
[TestFlight passCheckpoint:@"VIEWING_CREDITS_PAGE"];
}

- (void)viewDidUnload
{
itemNameLabel = nil;
itemDescripLabel = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
Expand All @@ -71,7 +66,6 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}

- (IBAction)backgroundTapped:(id)sender {
//NSLog(@"Background tapped");
[self dismissViewControllerAnimated:YES completion:nil];
}

Expand Down
52 changes: 1 addition & 51 deletions Giddy Goat Coffee/Giddy Goat Coffee/GGCFirstViewController.m
Expand Up @@ -44,27 +44,19 @@ @implementation GGCFirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// [self getMenuDisplay];
NSLog(@"first view did load");

//get downloads on async thread
dispatch_queue_t downloadQueue = dispatch_queue_create("status downloader", NULL);
dispatch_async(downloadQueue, ^{
//get daily specials from @giddygoatupdate
[self getStatusData];
dispatch_async(dispatch_get_main_queue(), ^{
//update label with daily specials from feed
[specialsLabel setText:[updateArray objectAtIndex:1]];
});
});
//dispatch_release(downloadQueue);
}

- (void)viewDidUnload
{
[self setSpecialsLabel:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
Expand All @@ -80,55 +72,34 @@ - (void)getStatusData
arrayPath = [self statusArrayFilePath];
NSArray *arrayFromFile = [NSArray arrayWithContentsOfFile:arrayPath];
if (arrayFromFile) {
//NSLog(@"ArrayFromFile: [0]:%@ [1]:%@", [arrayFromFile objectAtIndex:0], [arrayFromFile objectAtIndex:1]);
NSInteger months;
NSInteger days;
[self compareDates:arrayFromFile months_p:&months days_p:&days];

NSLog(@"Months: %d Days: %d", months, days);

if (days != 0 || months != 0) {
//get fresh feed
//NSLog(@"Getting fresh data");
[self fetchSpecials];
} else {
//NSLog(@"Loading cache data");
updateArray = [[NSMutableArray alloc] initWithContentsOfFile:[self statusArrayFilePath]];
[TestFlight passCheckpoint:@"Loading cached twitFeed"];
////NSLog(@"Update Array: %@", updateArray);
}
} else {
//if no file on file system yet get fresh feed
[self fetchSpecials];
[self fetchSpecials];
}
}

- (void)fetchSpecials
{
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/user_timeline.xml?screen_name=giddygoatupdate&count=1"];
[TestFlight passCheckpoint:@"Getting fresh twitFeed"];
updateArray = [[NSMutableArray alloc] init];

//try to use just strings instead of mutableStrings with append
NSString *updateString = [[NSMutableString alloc] init];
NSString *dateString = [[NSMutableString alloc] init];

NSData *xmlData = [[NSData alloc] initWithContentsOfURL:url];
//convert xml to string and dump to log
//NSString *xmlCheck = [[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding];
////NSLog(@"xmlCheck:\n%@", xmlCheck);

if (xmlData) {
//tbxml = [[TBXML alloc] initWithXMLData:xmlData];
tbxml = [[TBXML alloc] initWithURL:url];

//obtain root element
TBXMLElement * root = tbxml.rootXMLElement;
if (root) {
////NSLog(@"Got Root Element");
TBXMLElement * elem_status = [TBXML childElementNamed:@"status" parentElement:root];
while (elem_status != nil) {
////NSLog(@"elem_status != nil");

TBXMLElement * elem_date = [TBXML childElementNamed:@"created_at" parentElement:elem_status];
dateString = [dateString stringByAppendingString:[TBXML textForElement:elem_date]];
Expand All @@ -140,45 +111,27 @@ - (void)fetchSpecials
}
}
} else {
[TestFlight passCheckpoint:@"TWITTER_FEED_WAS_DOWN!!!"];
//just in case feed is down *July 6, 2012 2:23:59*
dateString = [dateString stringByAppendingString:@"2012-07-06 14:23:59 +0000"];
updateString = [updateString stringByAppendingString:@"No specials listed today. Please check back later."];
}
[updateArray addObject:dateString];
[updateArray addObject:updateString];
////NSLog(@"Saving XML to file system");
[updateArray writeToFile:[self statusArrayFilePath] atomically:YES];
url = nil;
}

- (void)compareDates:(NSArray *)arrayFromFile months_p:(NSInteger *)months_p days_p:(NSInteger *)days_p
{
//select date format for string in
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy";
//get date from array
NSDate *dateFromFile = [dateFormatter dateFromString:[arrayFromFile objectAtIndex:0]];
//NSLog(@"File Date: %@", dateFromFile);
NSDate *now = [NSDate date];
//NSLog(@"Current Date: %@", now);
//convert dates to days and months for comparison
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger units = NSMonthCalendarUnit | NSDayCalendarUnit;
//compare months and days
//NSDateComponents *comp = [cal components:units fromDate:dateFromFile toDate:now options:0];

//trying manual comparison since this comp failed to see 1 day difference in dates maybe due to times???
NSDateComponents *nowComps = [cal components:units fromDate:now];
NSDateComponents *fileComps = [cal components:units fromDate:dateFromFile];
NSInteger dayComp = [nowComps day] - [fileComps day];
NSInteger monthComp = [nowComps month] - [fileComps month];
//NSLog(@"Manual; Months: %d Days: %d", monthComp, dayComp);


//NSDateComponents *comp = [cal components:units fromDate:now toDate:dateFromFile options:0];
//save comparison as nsinteger
////NSLog(@"Months: %d Days: %d", [comp month], [comp day]);
*months_p = monthComp;
*days_p = dayComp;

Expand All @@ -189,16 +142,13 @@ - (NSString *)statusArrayFilePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
// Path to save array data
NSString *arrayPath = [[paths objectAtIndex:0]
stringByAppendingPathComponent:@"status.out"];
return arrayPath;
}


- (IBAction)backToCenter:(id)sender
{
[self.viewDeckController toggleLeftViewAnimated:YES];
[TestFlight passCheckpoint:@"Button nav from specials view"];
}
@end
22 changes: 2 additions & 20 deletions Giddy Goat Coffee/Giddy Goat Coffee/GGCScanViewController.m
Expand Up @@ -57,15 +57,12 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

[self getPunchesOnViewDidLoad];

_spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[_spinner setCenter:CGPointMake(self.view.bounds.size.width/2.0, self.view.bounds.size.height/2.0)]; // I do this because I'm in landscape mode
[_spinner setCenter:CGPointMake(self.view.bounds.size.width/2.0, self.view.bounds.size.height/2.0)];
[_spinner setColor:[UIColor greenColor]];
[self.view addSubview:_spinner]; // spinner is not visible until started

[self.view addSubview:_spinner];
readerView.readerDelegate = self;
}

Expand All @@ -82,7 +79,6 @@ - (void)viewWillDisappear:(BOOL)animated
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


Expand Down Expand Up @@ -126,7 +122,6 @@ - (NSInteger)processNumberOfPunches:(NSInteger)punches

- (void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image
{
// do something useful with results
for(ZBarSymbol *sym in symbols) {
scan = sym.data;
break;
Expand All @@ -136,8 +131,6 @@ - (void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet *)

- (void)updateCardFromServer
{
//get updated pass from server
//pull this out and switch it to update internally
PKPass *myPass = [passes objectAtIndex:0];
NSMutableString *urlString = [[NSMutableString alloc] initWithString:@"http://www.toddpickell.me/card/punchMe.php?cn="];
[urlString appendString:[myPass serialNumber]];
Expand Down Expand Up @@ -173,12 +166,10 @@ - (void)updateCardInternally
- (void)processPunchScan
{
[_spinner startAnimating];
NSLog(@"Scan: %@", scan);
NSString *checkString = @"2a73e02a88ee9bcb965cc0f22c0cabbf68d5e823992884b4514bc242b0146ff16d5cf349c374cf7c";
if ([scan isEqualToString:checkString]) {
[self updateCardInternally];
} else {
NSLog(@"Invalid Scan");
UIAlertView *scanAlert = [[UIAlertView alloc] initWithTitle:@"Invalid Scan" message:@"Scan does not match, please try again. If unable to get scan to work contact administrator." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
if ([_spinner isAnimating]) {
[_spinner stopAnimating];
Expand All @@ -196,8 +187,6 @@ - (void)getPassFromServer:(NSMutableString *)urlString
if (data != NULL) {
updatedPass = [[PKPass alloc] initWithData:data error:nil];
} else {
//warning unable to contact server
NSLog(@"Unable to contact server");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Connection" message:@"Unable to connect to server to update punch card. Please check your network connection and try again later." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
Expand All @@ -206,29 +195,22 @@ - (void)getPassFromServer:(NSMutableString *)urlString
- (IBAction)cancelButtonPressed:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
//This became deprecated after initial release version, need to research more current way acheive same results
//with an updated call so this doesnt break later down the road
}

#pragma mark - old scan methods



- (IBAction)scanPunchCode:(id)sender {
//present scanner
ZBarReaderViewController *reader = [ZBarReaderViewController new];
//reader.readerDelegate = self;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology:ZBAR_QRCODE config:ZBAR_CFG_ENABLE to:0];
reader.readerView.zoom = 1.0;
[self presentViewController:reader animated:YES completion:nil];
//This became deprecated after initial release version, need to research more current way acheive same results
//with an updated call so this doesnt break later down the road
}

- (void)imagePickerController:(UIImagePickerController *)reader didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(@"imagePickerController didFinishPicking");
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
Expand Down

0 comments on commit d8f76dd

Please sign in to comment.