From c0120a7416208d34d8303b985bcdc78a5ffa16a1 Mon Sep 17 00:00:00 2001 From: Eddie Ehlin Date: Tue, 22 Jan 2013 22:08:20 +0100 Subject: Added timer handling (using core timer) to BeanCollectionExtractionViewController. --- .../UserInterfaceState.xcuserstate | Bin 37321 -> 39557 bytes .../xcdebugger/Breakpoints.xcbkptlist | 13 ------ .../iBean/BeanCollectionExtractionViewController.h | 7 ++- .../iBean/BeanCollectionExtractionViewController.m | 50 +++++++++++++++++++++ iBean/iBean/InstantExtractionViewController.h | 1 + iBean/iBean/InstantExtractionViewController.m | 13 +++--- iBean/iBean/iPhoneStoryboard.storyboard | 6 ++- 7 files changed, 69 insertions(+), 21 deletions(-) diff --git a/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate b/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate index 7208623..c566724 100644 Binary files a/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate and b/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist b/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist index e8320d9..75119b6 100644 --- a/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist +++ b/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist @@ -3,19 +3,6 @@ type = "1" version = "1.0"> - - @property (nonatomic, strong) BeanCollection *beanCollection; +@property (nonatomic, assign) double extractionProgress; +@property (nonatomic, assign) BOOL extractionInProgress; /* Utility methods */ - (void) initViewController; - (void) initWithBeanCollection:(BeanCollection*) bc; +- (void) updateExtractionProgress; +- (void) haltExtractionTimer; +- (void) timerInterrupted; /* UI Outlets */ @property (weak, nonatomic) IBOutlet UITableView *beanTableView; @@ -24,6 +29,6 @@ @property (weak, nonatomic) IBOutlet UIButton *extractionButton; /* UI Actions */ - +- (IBAction) startExtraction:(id)sender; @end diff --git a/iBean/iBean/BeanCollectionExtractionViewController.m b/iBean/iBean/BeanCollectionExtractionViewController.m index 4c26ab6..785c981 100644 --- a/iBean/iBean/BeanCollectionExtractionViewController.m +++ b/iBean/iBean/BeanCollectionExtractionViewController.m @@ -11,6 +11,7 @@ #import "BeanCollection+Interface.h" #import "BeanCell.h" #import "Bean+Interface.h" +#import "AppDelegate+Storage.h" @interface BeanCollectionExtractionViewController () @@ -87,7 +88,39 @@ - (void) initWithBeanCollection:(BeanCollection *)bc { self.beanCollection = bc; +} + +- (void) updateExtractionProgress +{ + self.extractionProgress -= 0.1f; + self.extractionProgressLabel.text = [NSString stringWithFormat:@"%1.1f", self.extractionProgress]; + if (self.extractionProgress <= 0.0f) + { + NSLog(@"Timer reached its limit!"); + [self haltExtractionTimer]; + } +} + +- (void) haltExtractionTimer +{ + if ([(AppDelegate*) [[UIApplication sharedApplication] delegate] getTimer] != nil) + { + [(AppDelegate*) [[UIApplication sharedApplication] delegate] haltTimer:YES]; + + //Return UI to "Start extraction" state. + [self timerInterrupted]; + } +} + +- (void) timerInterrupted +{ + NSLog(@"BeanCollectionExtractionViewController - timerInterrupted"); + + //Return UI to "Start extraction" state. + [self.extractionButton setTitle:@"Start extraction" forState:UIControlStateNormal]; + self.extractionProgressLabel.text = [self.beanCollection.extractionTime stringValue]; + self.extractionInProgress = NO; } /***************************************************** @@ -95,6 +128,23 @@ *****************************************************/ #pragma mark - UI action methods +- (void) startExtraction:(id)sender +{ + //Extraction in progress? + if ([(AppDelegate*) [[UIApplication sharedApplication] delegate] getTimer] == nil || self.extractionInProgress == NO) + { + self.extractionProgress = [self.beanCollection.extractionTime doubleValue]; + [self.extractionButton setTitle:@"Stop extraction" forState:UIControlStateNormal]; + self.extractionInProgress = YES; + + [(AppDelegate*) [[UIApplication sharedApplication] delegate] createTimer:self :@selector(updateExtractionProgress) :nil :YES]; + } + else if ([(AppDelegate*) [[UIApplication sharedApplication] delegate] getTimer] != nil) + { + [self haltExtractionTimer]; + } +} + /***************************************************** Delegates *****************************************************/ diff --git a/iBean/iBean/InstantExtractionViewController.h b/iBean/iBean/InstantExtractionViewController.h index 4fded92..92b265e 100644 --- a/iBean/iBean/InstantExtractionViewController.h +++ b/iBean/iBean/InstantExtractionViewController.h @@ -12,6 +12,7 @@ @interface InstantExtractionViewController : UIViewController @property (nonatomic, assign) double extractionProgress; +@property (nonatomic, assign) BOOL extractionInProgress; @property (nonatomic, strong) Configuration *configuration; /* Utility methods */ diff --git a/iBean/iBean/InstantExtractionViewController.m b/iBean/iBean/InstantExtractionViewController.m index 3c53faa..d0205c8 100644 --- a/iBean/iBean/InstantExtractionViewController.m +++ b/iBean/iBean/InstantExtractionViewController.m @@ -87,10 +87,10 @@ { if ([(AppDelegate*) [[UIApplication sharedApplication] delegate] getTimer] != nil) { - [(AppDelegate*) [[UIApplication sharedApplication] delegate] haltTimer:NO]; + [(AppDelegate*) [[UIApplication sharedApplication] delegate] haltTimer:YES]; //Return UI to "Start extraction" state. - [self timerInterrupted]; + //[self timerInterrupted]; } } @@ -101,6 +101,7 @@ //Return UI to "Start extraction" state. [self.extractionButton setTitle:@"Start extraction" forState:UIControlStateNormal]; [self.extractionSettingStepper setEnabled:YES]; + self.extractionInProgress = NO; } /***************************************************** @@ -108,17 +109,17 @@ *****************************************************/ #pragma mark - IBActions - (IBAction)startExtraction:(id)sender { - - //Extraction in progress? - if ([(AppDelegate*) [[UIApplication sharedApplication] delegate] getTimer] == nil) + + if (([(AppDelegate*) [[UIApplication sharedApplication] delegate] getTimer] == nil) || self.extractionInProgress == NO) { self.extractionProgress = 0.0f; [self.extractionButton setTitle:@"Stop extraction" forState:UIControlStateNormal]; [self.extractionSettingStepper setEnabled:NO]; + self.extractionInProgress = YES; [(AppDelegate*) [[UIApplication sharedApplication] delegate] createTimer:self :@selector(updateExtractionProgressLabel) :nil :YES]; } - else + else if (([(AppDelegate*) [[UIApplication sharedApplication] delegate] getTimer] != nil)) { [self haltExtractionTimer]; } diff --git a/iBean/iBean/iPhoneStoryboard.storyboard b/iBean/iBean/iPhoneStoryboard.storyboard index df40f8a..2cb8195 100644 --- a/iBean/iBean/iPhoneStoryboard.storyboard +++ b/iBean/iBean/iPhoneStoryboard.storyboard @@ -743,10 +743,13 @@