From b36ffa25882b548c800ee609965196ef3332e9c4 Mon Sep 17 00:00:00 2001 From: Eddie Ehlin Date: Mon, 21 Jan 2013 22:37:24 +0100 Subject: Implemented core timer support and InstantExtraction is now using it. --- .../UserInterfaceState.xcuserstate | Bin 36973 -> 37321 bytes .../xcdebugger/Breakpoints.xcbkptlist | 54 +++++++++++++++++++++ iBean/iBean/AppDelegate+Storage.h | 5 ++ iBean/iBean/AppDelegate+Storage.m | 41 ++++++++++++++++ iBean/iBean/AppDelegate.h | 3 ++ iBean/iBean/InstantExtractionViewController.h | 2 +- iBean/iBean/InstantExtractionViewController.m | 22 ++++++--- 7 files changed, 118 insertions(+), 9 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 863f4fe..7208623 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 05301bc..e8320d9 100644 --- a/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist +++ b/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist @@ -2,4 +2,58 @@ + + + + + + + + + + diff --git a/iBean/iBean/AppDelegate+Storage.h b/iBean/iBean/AppDelegate+Storage.h index bec63e0..f444572 100644 --- a/iBean/iBean/AppDelegate+Storage.h +++ b/iBean/iBean/AppDelegate+Storage.h @@ -33,4 +33,9 @@ - (BeanCollection*) createBeanCollection; - (Bean*) createBean; +#pragma mark - iBean timer methods +- (NSTimer*) getTimer; +- (NSTimer*) createTimer:(id) callbackTarget: (SEL) selector: (id)userInfo: (BOOL)repeats; +- (void) haltTimer: (BOOL)interrupt; + @end diff --git a/iBean/iBean/AppDelegate+Storage.m b/iBean/iBean/AppDelegate+Storage.m index 5668bd5..4532397 100644 --- a/iBean/iBean/AppDelegate+Storage.m +++ b/iBean/iBean/AppDelegate+Storage.m @@ -153,6 +153,47 @@ return b; } +#pragma mark - iBean timer related methods +- (NSTimer*) getTimer +{ + return self.timer; +} + +- (NSTimer*) createTimer:(id) callbackTarget: (SEL) selector: (id)userInfo: (BOOL)repeats +{ + if (self.timer != nil) + { + BOOL interruptCallbackTarget = self.timerCallbackTarget != callbackTarget; + [self haltTimer: interruptCallbackTarget]; + } + + self.timerCallbackTarget = callbackTarget; + self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:callbackTarget selector:selector userInfo:userInfo repeats:repeats]; + + return self.timer; +} + + +- (void) haltTimer: (BOOL) interrupt +{ + if (self.timer != nil) + { + [self.timer invalidate]; + self.timer = nil; + + if (self.timerCallbackTarget != nil && interrupt == YES) + { + //Must call the target to notify that it's timer has been interrupted... + //First we must make sure that target has implemented timerInterrupted method. + if ([self.timerCallbackTarget respondsToSelector:@selector(timerInterrupted)]) + { + [self.timerCallbackTarget performSelector:@selector(timerInterrupted)]; + } + } + } +} + + @end diff --git a/iBean/iBean/AppDelegate.h b/iBean/iBean/AppDelegate.h index 40084d5..b09db3e 100644 --- a/iBean/iBean/AppDelegate.h +++ b/iBean/iBean/AppDelegate.h @@ -12,6 +12,9 @@ @property (strong, nonatomic) UIWindow *window; +@property (nonatomic, strong) id timerCallbackTarget; +@property (nonatomic, strong) NSTimer *timer; + @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; diff --git a/iBean/iBean/InstantExtractionViewController.h b/iBean/iBean/InstantExtractionViewController.h index e8ec739..4fded92 100644 --- a/iBean/iBean/InstantExtractionViewController.h +++ b/iBean/iBean/InstantExtractionViewController.h @@ -12,7 +12,6 @@ @interface InstantExtractionViewController : UIViewController @property (nonatomic, assign) double extractionProgress; -@property (nonatomic, strong) NSTimer* timer; @property (nonatomic, strong) Configuration *configuration; /* Utility methods */ @@ -20,6 +19,7 @@ - (void) updateExtractionSettingLabel; - (void) updateExtractionProgressLabel; - (void) haltExtractionTimer; +- (void) timerInterrupted; /* UI Outlets */ @property (weak, nonatomic) IBOutlet UILabel *extractionSettingLabel; diff --git a/iBean/iBean/InstantExtractionViewController.m b/iBean/iBean/InstantExtractionViewController.m index 699d2c8..3c53faa 100644 --- a/iBean/iBean/InstantExtractionViewController.m +++ b/iBean/iBean/InstantExtractionViewController.m @@ -85,17 +85,24 @@ - (void) haltExtractionTimer { - if (self.timer != nil) + if ([(AppDelegate*) [[UIApplication sharedApplication] delegate] getTimer] != nil) { - [self.timer invalidate]; - self.timer = nil; + [(AppDelegate*) [[UIApplication sharedApplication] delegate] haltTimer:NO]; //Return UI to "Start extraction" state. - [self.extractionButton setTitle:@"Start extraction" forState:UIControlStateNormal]; - [self.extractionSettingStepper setEnabled:YES]; + [self timerInterrupted]; } } +- (void) timerInterrupted +{ + NSLog(@"InstantExtractionViewController - timerInterrupted"); + + //Return UI to "Start extraction" state. + [self.extractionButton setTitle:@"Start extraction" forState:UIControlStateNormal]; + [self.extractionSettingStepper setEnabled:YES]; +} + /***************************************************** UI Actions *****************************************************/ @@ -103,14 +110,13 @@ - (IBAction)startExtraction:(id)sender { //Extraction in progress? - if (self.timer == nil) + if ([(AppDelegate*) [[UIApplication sharedApplication] delegate] getTimer] == nil) { self.extractionProgress = 0.0f; [self.extractionButton setTitle:@"Stop extraction" forState:UIControlStateNormal]; [self.extractionSettingStepper setEnabled:NO]; - self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(updateExtractionProgressLabel) userInfo:nil repeats:YES]; - + [(AppDelegate*) [[UIApplication sharedApplication] delegate] createTimer:self :@selector(updateExtractionProgressLabel) :nil :YES]; } else { -- cgit v1.2.3