From f1ca62e3237aceda58b60f29b3cceb7d6ec33d37 Mon Sep 17 00:00:00 2001 From: Eddie Ehlin Date: Sat, 12 Jan 2013 20:44:24 +0100 Subject: Added ExtractionViewController and also closed the Add-new-bean-collection-loop. --- iBean/iBean.xcodeproj/project.pbxproj | 32 ++++-- .../UserInterfaceState.xcuserstate | Bin 34150 -> 33585 bytes iBean/iBean/AddBeanViewController.h | 1 + iBean/iBean/AddBeanViewController.m | 18 +++- iBean/iBean/AppDelegate+Storage.m | 1 + iBean/iBean/EditBeanViewController.m | 18 +++- iBean/iBean/ExtractionViewController.h | 29 ++++++ iBean/iBean/ExtractionViewController.m | 108 +++++++++++++++++++++ iBean/iBean/iPhoneStoryboard.storyboard | 26 ++++- 9 files changed, 218 insertions(+), 15 deletions(-) create mode 100644 iBean/iBean/ExtractionViewController.h create mode 100644 iBean/iBean/ExtractionViewController.m (limited to 'iBean') diff --git a/iBean/iBean.xcodeproj/project.pbxproj b/iBean/iBean.xcodeproj/project.pbxproj index e3df510..68cbbd0 100644 --- a/iBean/iBean.xcodeproj/project.pbxproj +++ b/iBean/iBean.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ 020C5680169F5E9A00D8224C /* Bean+Interface.m in Sources */ = {isa = PBXBuildFile; fileRef = 020C567F169F5E9900D8224C /* Bean+Interface.m */; }; 020C5683169F5FBB00D8224C /* BeanCollection+Interface.m in Sources */ = {isa = PBXBuildFile; fileRef = 020C5682169F5FBB00D8224C /* BeanCollection+Interface.m */; }; 020C568F16A1CE0E00D8224C /* EditBeanViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 020C568E16A1CE0E00D8224C /* EditBeanViewController.m */; }; + 020C569316A1E55600D8224C /* ExtractionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 020C569216A1E55600D8224C /* ExtractionViewController.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -74,6 +75,8 @@ 020C5682169F5FBB00D8224C /* BeanCollection+Interface.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "BeanCollection+Interface.m"; sourceTree = ""; }; 020C568D16A1CE0E00D8224C /* EditBeanViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditBeanViewController.h; sourceTree = ""; }; 020C568E16A1CE0E00D8224C /* EditBeanViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EditBeanViewController.m; sourceTree = ""; }; + 020C569116A1E55600D8224C /* ExtractionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtractionViewController.h; sourceTree = ""; }; + 020C569216A1E55600D8224C /* ExtractionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExtractionViewController.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -172,9 +175,10 @@ isa = PBXGroup; children = ( 020C56081698F58900D8224C /* BeanCollectionList */, - 020C56091698F59F00D8224C /* BeanCollectionInfo */, - 020C56071698F4DC00D8224C /* BeanCollectionBeanList */, - 020C566E169E1ACB00D8224C /* Bean */, + 020C56091698F59F00D8224C /* Step 1 - BeanCollectionInfo */, + 020C56071698F4DC00D8224C /* Step 2 - BeanCollectionBeanList */, + 020C566E169E1ACB00D8224C /* Step 3 - Bean */, + 020C569016A1E50200D8224C /* Step 4 - Extraction */, 020C55DF169792F800D8224C /* Data */, ); name = iBean; @@ -192,13 +196,13 @@ name = Data; sourceTree = ""; }; - 020C56071698F4DC00D8224C /* BeanCollectionBeanList */ = { + 020C56071698F4DC00D8224C /* Step 2 - BeanCollectionBeanList */ = { isa = PBXGroup; children = ( 020C56041698A85000D8224C /* BeanCollectionBeanListViewController.h */, 020C56051698A85000D8224C /* BeanCollectionBeanListViewController.m */, ); - name = BeanCollectionBeanList; + name = "Step 2 - BeanCollectionBeanList"; sourceTree = ""; }; 020C56081698F58900D8224C /* BeanCollectionList */ = { @@ -210,16 +214,16 @@ name = BeanCollectionList; sourceTree = ""; }; - 020C56091698F59F00D8224C /* BeanCollectionInfo */ = { + 020C56091698F59F00D8224C /* Step 1 - BeanCollectionInfo */ = { isa = PBXGroup; children = ( 020C560116989D4500D8224C /* BeanCollectionInfoViewController.h */, 020C560216989D4500D8224C /* BeanCollectionInfoViewController.m */, ); - name = BeanCollectionInfo; + name = "Step 1 - BeanCollectionInfo"; sourceTree = ""; }; - 020C566E169E1ACB00D8224C /* Bean */ = { + 020C566E169E1ACB00D8224C /* Step 3 - Bean */ = { isa = PBXGroup; children = ( 020C5670169E1B0100D8224C /* AddBeanViewController.h */, @@ -227,7 +231,7 @@ 020C568D16A1CE0E00D8224C /* EditBeanViewController.h */, 020C568E16A1CE0E00D8224C /* EditBeanViewController.m */, ); - name = Bean; + name = "Step 3 - Bean"; sourceTree = ""; }; 020C5684169F603700D8224C /* Interface */ = { @@ -241,6 +245,15 @@ name = Interface; sourceTree = ""; }; + 020C569016A1E50200D8224C /* Step 4 - Extraction */ = { + isa = PBXGroup; + children = ( + 020C569116A1E55600D8224C /* ExtractionViewController.h */, + 020C569216A1E55600D8224C /* ExtractionViewController.m */, + ); + name = "Step 4 - Extraction"; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -322,6 +335,7 @@ 020C5680169F5E9A00D8224C /* Bean+Interface.m in Sources */, 020C5683169F5FBB00D8224C /* BeanCollection+Interface.m in Sources */, 020C568F16A1CE0E00D8224C /* EditBeanViewController.m in Sources */, + 020C569316A1E55600D8224C /* ExtractionViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; 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 9d36b94..e41083a 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/AddBeanViewController.h b/iBean/iBean/AddBeanViewController.h index 0778f36..e246b6e 100644 --- a/iBean/iBean/AddBeanViewController.h +++ b/iBean/iBean/AddBeanViewController.h @@ -24,6 +24,7 @@ @property (weak, nonatomic) IBOutlet UIStepper *amountStepper; @property (weak, nonatomic) IBOutlet UILabel *grinderSettingLabel; @property (weak, nonatomic) IBOutlet UIStepper *grinderSettingStepper; +@property (weak, nonatomic) IBOutlet UINavigationBar *addBeanNavigationBar; /* UI Actions */ - (IBAction) amountStepperChanged:(id)sender; diff --git a/iBean/iBean/AddBeanViewController.m b/iBean/iBean/AddBeanViewController.m index f2faa54..be5cc8e 100644 --- a/iBean/iBean/AddBeanViewController.m +++ b/iBean/iBean/AddBeanViewController.m @@ -112,7 +112,23 @@ /***************************************************** Delegate *****************************************************/ -#pragma mark - UITextField delagate related methods +#pragma mark - UITextFieldDelegate methods +- (void) textFieldDidBeginEditing:(UITextField *)textField +{ + if (textField == self.beanNameTextField) + { + [[[self.addBeanNavigationBar.items objectAtIndex:0] rightBarButtonItem] setEnabled:NO]; + } +} + +- (void) textFieldDidEndEditing:(UITextField *)textField +{ + if (textField == self.beanNameTextField) + { + [[[self.addBeanNavigationBar.items objectAtIndex:0] rightBarButtonItem] setEnabled:YES]; + } +} + //Purpose: When "return" is pressed the keyboard will go away and "change" event will be triggered. - (BOOL)textFieldShouldReturn:(UITextField *)textField { diff --git a/iBean/iBean/AppDelegate+Storage.m b/iBean/iBean/AppDelegate+Storage.m index 4f8fc0d..013ce10 100644 --- a/iBean/iBean/AppDelegate+Storage.m +++ b/iBean/iBean/AppDelegate+Storage.m @@ -107,6 +107,7 @@ if (bc != nil) { bc.created = [NSDate date]; + bc.extractionTime = [NSNumber numberWithDouble:25.0f]; } } diff --git a/iBean/iBean/EditBeanViewController.m b/iBean/iBean/EditBeanViewController.m index 5f1a84c..59b3d8d 100644 --- a/iBean/iBean/EditBeanViewController.m +++ b/iBean/iBean/EditBeanViewController.m @@ -120,7 +120,23 @@ /***************************************************** Delegate *****************************************************/ -#pragma mark - UITextField delagate related methods +#pragma mark - UITextFieldDelegate methods +- (void) textFieldDidBeginEditing:(UITextField *)textField +{ + if (textField == self.beanNameTextField) + { + [self.navigationItem.rightBarButtonItem setEnabled:NO]; + } +} + +- (void) textFieldDidEndEditing:(UITextField *)textField +{ + if (textField == self.beanNameTextField) + { + [self.navigationItem.rightBarButtonItem setEnabled:YES]; + } +} + //Purpose: When "return" is pressed the keyboard will go away and "change" event will be triggered. - (BOOL)textFieldShouldReturn:(UITextField *)textField { diff --git a/iBean/iBean/ExtractionViewController.h b/iBean/iBean/ExtractionViewController.h new file mode 100644 index 0000000..3844440 --- /dev/null +++ b/iBean/iBean/ExtractionViewController.h @@ -0,0 +1,29 @@ +// +// ExtractionViewController.h +// iBean +// +// Created by Eddie Ehlin on 2013-01-12. +// Copyright (c) 2013 Eddie Ehlin. All rights reserved. +// + +#import +@class BeanCollection; + +@interface ExtractionViewController : UIViewController + +@property (nonatomic, strong) BeanCollection *beanCollection; +@property (nonatomic, assign) BOOL editMode; + +/* Utility methods */ +- (void) initViewController; +- (void) initWithModeAndBeanCollection:(BOOL)editMode: (BeanCollection*) bc; +- (BOOL) commitBeanCollection; + +/* UI Outlets */ +@property (weak, nonatomic) IBOutlet UIStepper *extractionSettingStepper; +@property (weak, nonatomic) IBOutlet UILabel *extractionSettingLabel; + +/* UI Actions */ +- (IBAction) extractionSettingStepperChanged:(id)sender; + +@end diff --git a/iBean/iBean/ExtractionViewController.m b/iBean/iBean/ExtractionViewController.m new file mode 100644 index 0000000..a96b895 --- /dev/null +++ b/iBean/iBean/ExtractionViewController.m @@ -0,0 +1,108 @@ +// +// ExtractionViewController.m +// iBean +// +// Created by Eddie Ehlin on 2013-01-12. +// Copyright (c) 2013 Eddie Ehlin. All rights reserved. +// + +#import "ExtractionViewController.h" +#import "BeanCollection+Interface.h" +#import "AppDelegate+Storage.h" + +@interface ExtractionViewController () + +@end + +@implementation ExtractionViewController + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view. +} + +- (void) viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + [self initViewController]; +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender +{ + //Check if we should perform the segue back to bean collection list. + if ([identifier isEqualToString:@"CommitBeanCollectionSegue"]) + { + return [self commitBeanCollection]; + } + + return YES; +} + +/***************************************************** + Utility methods + *****************************************************/ +- (void) initViewController +{ + NSLog(@"ExtractionViewController - initViewController"); + + + //No need to check self.editMode here, since bean collection + //receives a default value of 25.0 for extraction time. + if (self.beanCollection != nil) + { + self.extractionSettingLabel.text = [NSString stringWithFormat:@"%1.1f", [self.beanCollection.extractionTime doubleValue]]; + self.extractionSettingStepper.value = [self.beanCollection.extractionTime doubleValue]; + } +} + +- (void) initWithModeAndBeanCollection:(BOOL)editMode: (BeanCollection*) bc +{ + NSLog(@"ExtractionViewController - initWithModeAndBeanCollection"); + self.editMode = editMode; + self.beanCollection = bc; +} + +- (BOOL) commitBeanCollection +{ + NSError *commitError = nil; + commitError = [(AppDelegate*) [[UIApplication sharedApplication] delegate] save]; + + if (commitError != nil) + { +#warning TODO - Display error messsag! + return NO; + } + + //Bean collection successfully saved, lets go back to list of bean collections. + return YES; +} + +/***************************************************** + UI Actions + *****************************************************/ +- (void) extractionSettingStepperChanged:(id)sender +{ + self.extractionSettingLabel.text = [NSString stringWithFormat:@"%1.1f", self.extractionSettingStepper.value]; + if (self.beanCollection != nil) + { + self.beanCollection.extractionTime = [NSNumber numberWithDouble:self.extractionSettingStepper.value]; + } +} + +@end diff --git a/iBean/iBean/iPhoneStoryboard.storyboard b/iBean/iBean/iPhoneStoryboard.storyboard index 1c18432..94023a4 100644 --- a/iBean/iBean/iPhoneStoryboard.storyboard +++ b/iBean/iBean/iPhoneStoryboard.storyboard @@ -440,10 +440,10 @@ - + - + @@ -453,7 +453,11 @@ - + + + + + @@ -592,6 +600,7 @@ + @@ -631,6 +640,7 @@ + @@ -680,6 +690,14 @@ + + + + + + + + -- cgit v1.2.3