From 5a21cbfb85b34f498a758c66f663b45b822dc262 Mon Sep 17 00:00:00 2001 From: Eddie Ehlin Date: Sat, 29 Dec 2012 19:14:18 +0100 Subject: InstaBean functionality implemented, except for CoreData. --- .../UserInterfaceState.xcuserstate | Bin 18900 -> 20760 bytes .../xcdebugger/Breakpoints.xcbkptlist | 20 +++++ iBean/iBean/InstaBeanViewController.h | 19 ++++- iBean/iBean/InstaBeanViewController.m | 85 ++++++++++++++------- .../en.lproj/MainStoryboard_iPhone.storyboard | 20 ++--- 5 files changed, 104 insertions(+), 40 deletions(-) create mode 100644 iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist (limited to 'iBean') 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 a6b65d0..c1a02c2 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 new file mode 100644 index 0000000..34b12d6 --- /dev/null +++ b/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist @@ -0,0 +1,20 @@ + + + + + + + diff --git a/iBean/iBean/InstaBeanViewController.h b/iBean/iBean/InstaBeanViewController.h index 7dbb6de..65ae31b 100644 --- a/iBean/iBean/InstaBeanViewController.h +++ b/iBean/iBean/InstaBeanViewController.h @@ -9,10 +9,23 @@ #import @interface InstaBeanViewController : UIViewController -@property (weak, nonatomic) IBOutlet UILabel *extractionTimerLabel; +@property (weak, nonatomic) IBOutlet UILabel *extractionProgressLabel; +@property (weak, nonatomic) IBOutlet UIStepper *extractionSettingStepper; +@property (weak, nonatomic) IBOutlet UILabel *extractionSettingLabel; @property (weak, nonatomic) IBOutlet UIButton *extractionButton; -@property (weak, nonatomic) IBOutlet UIStepper *extractionSetupStepper; -@property (weak, nonatomic) IBOutlet UILabel *extractionTimerSettingLabel; + +@property (nonatomic) double extractionProgress; @property (nonatomic) BOOL extractionInProgress; +@property (weak, nonatomic) NSTimer* timer; + +//Utility methods +- (void) updateExtractionSettingLabel; +- (void) initInstaBean; +- (void) updateExtractionProgressLabel; +- (void) haltExtractionTimer; + +//Event/signal based methods +- (IBAction)setExtractionTimer:(id)sender; +- (IBAction)startExtraction:(id)sender; @end diff --git a/iBean/iBean/InstaBeanViewController.m b/iBean/iBean/InstaBeanViewController.m index e528122..dd67379 100644 --- a/iBean/iBean/InstaBeanViewController.m +++ b/iBean/iBean/InstaBeanViewController.m @@ -14,22 +14,12 @@ @implementation InstaBeanViewController -/* -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil -{ - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; - if (self) { - // Custom initialization - } - return self; -} - */ - - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"InstaBean viewDidLoad"); - // Do any additional setup after loading the view. + [self initInstaBean]; + } - (void)didReceiveMemoryWarning @@ -39,33 +29,74 @@ } -//Insta bean methods -- (IBAction)setTimerInterval:(id)sender { - NSString *timerSetting = [NSString stringWithFormat:@"%1.0f", [self.extractionSetupStepper value]]; - NSLog(@"%@", timerSetting); - [self.extractionTimerSettingLabel setText:timerSetting]; +//------------------------------------------------------------------- +// UTILITY METHODS +//------------------------------------------------------------------- +- (void) updateExtractionSettingLabel { + NSString *timerSetting = [NSString stringWithFormat:@"%1.0f", [self.extractionSettingStepper value]]; + self.extractionSettingLabel.text = timerSetting; +} + +- (void) updateExtractionProgressLabel { + self.extractionProgress += 0.1f; + self.extractionProgressLabel.text = [NSString stringWithFormat:@"%1.1f", self.extractionProgress]; + + if (self.extractionProgress >= self.extractionSettingStepper.value) + { + NSLog(@"Timer reached its limit!"); + [self haltExtractionTimer]; + } +} + +- (void) haltExtractionTimer +{ + if (self.timer != nil) + { + [self.timer invalidate]; + self.timer = nil; + [self.extractionButton setTitle:@"Start extraction" forState:UIControlStateNormal]; + self.extractionInProgress = NO; + [self.extractionSettingStepper setEnabled:YES]; + } +} + +//------------------------------------------------------------------- +// ACTION METHODS +//------------------------------------------------------------------- + +- (void) initInstaBean +{ + NSLog(@"Loading & setting stepper!"); + //TODO: Read from storage.. + [self.extractionSettingStepper setValue:25.0f]; + [self updateExtractionSettingLabel]; +} + +- (IBAction)setExtractionTimer:(id)sender { + [self updateExtractionSettingLabel]; } - (IBAction)startExtraction:(id)sender { + if (self.extractionInProgress == NO) { - //Update button text to "Stop extraction" self.extractionInProgress = YES; + self.extractionProgress = 0.0f; + self.extractionProgressLabel.text = @"0.0"; [self.extractionButton setTitle:@"Stop extraction" forState:UIControlStateNormal]; - [self.extractionButton setTintColor:[UIColor redColor]]; + [self.extractionSettingStepper setEnabled:NO]; + + if (self.timer == nil) + { + self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(updateExtractionProgressLabel) userInfo:nil repeats:YES]; + } //TODO: Set red background image. - //TODO: Start timer. + } else { - [self.extractionButton setTitle:@"Start extraction" forState:UIControlStateNormal]; - self.extractionInProgress = NO; - [self.extractionButton setTintColor:[UIColor greenColor]]; //TODO: Set green background image. - //TODO: Halt timer + [self haltExtractionTimer]; } - } - - @end diff --git a/iBean/iBean/en.lproj/MainStoryboard_iPhone.storyboard b/iBean/iBean/en.lproj/MainStoryboard_iPhone.storyboard index 0e1a2c4..a65aaa4 100644 --- a/iBean/iBean/en.lproj/MainStoryboard_iPhone.storyboard +++ b/iBean/iBean/en.lproj/MainStoryboard_iPhone.storyboard @@ -68,12 +68,12 @@ - + - +