From 3b5693d56548f402da841d0dd4bfb4fdba53805d Mon Sep 17 00:00:00 2001 From: Eddie Ehlin Date: Sun, 27 Jan 2013 21:20:26 +0100 Subject: Initial support for Settings. First section (global settings) is implemented, left to do is threshold handling (stubs added). --- iBean/iBean.xcodeproj/project.pbxproj | 50 ++- .../UserInterfaceState.xcuserstate | Bin 39507 -> 44255 bytes .../xcdebugger/Breakpoints.xcbkptlist | 18 +- iBean/iBean/AppDelegate+Storage.h | 13 +- iBean/iBean/AppDelegate+Storage.m | 87 ++++- .../iBean/BeanCollectionExtractionViewController.m | 1 + iBean/iBean/Configuration.h | 18 + iBean/iBean/Configuration.m | 5 + iBean/iBean/InstantExtractionViewController.m | 14 +- iBean/iBean/SettingsViewController.h | 30 ++ iBean/iBean/SettingsViewController.m | 140 +++++++ iBean/iBean/Threshold.h | 21 + iBean/iBean/Threshold.m | 20 + iBean/iBean/ThresholdCell.h | 26 ++ iBean/iBean/ThresholdCell.m | 60 +++ iBean/iBean/ThresholdListViewController.h | 20 + iBean/iBean/ThresholdListViewController.m | 129 ++++++ iBean/iBean/ThresholdViewController.h | 20 + iBean/iBean/ThresholdViewController.m | 57 +++ .../iBean.xcdatamodeld/iBean.xcdatamodel/contents | 13 +- iBean/iBean/iPhoneStoryboard.storyboard | 431 ++++++++++++++++++++- 21 files changed, 1127 insertions(+), 46 deletions(-) create mode 100644 iBean/iBean/SettingsViewController.h create mode 100644 iBean/iBean/SettingsViewController.m create mode 100644 iBean/iBean/Threshold.h create mode 100644 iBean/iBean/Threshold.m create mode 100644 iBean/iBean/ThresholdCell.h create mode 100644 iBean/iBean/ThresholdCell.m create mode 100644 iBean/iBean/ThresholdListViewController.h create mode 100644 iBean/iBean/ThresholdListViewController.m create mode 100644 iBean/iBean/ThresholdViewController.h create mode 100644 iBean/iBean/ThresholdViewController.m (limited to 'iBean') diff --git a/iBean/iBean.xcodeproj/project.pbxproj b/iBean/iBean.xcodeproj/project.pbxproj index 09178f0..1bbb776 100644 --- a/iBean/iBean.xcodeproj/project.pbxproj +++ b/iBean/iBean.xcodeproj/project.pbxproj @@ -32,7 +32,12 @@ 020C569316A1E55600D8224C /* ExtractionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 020C569216A1E55600D8224C /* ExtractionViewController.m */; }; 020C569C16A49C8300D8224C /* Configuration+Interface.m in Sources */ = {isa = PBXBuildFile; fileRef = 020C569B16A49C8300D8224C /* Configuration+Interface.m */; }; 024F676D16A4A61D004A1201 /* InstantExtractionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 024F676C16A4A61D004A1201 /* InstantExtractionViewController.m */; }; - 0276252616B5477800EE2F4E /* Configuration.m in Sources */ = {isa = PBXBuildFile; fileRef = 0276252516B5477800EE2F4E /* Configuration.m */; }; + 0276253916B58D6000EE2F4E /* SettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0276253816B58D6000EE2F4E /* SettingsViewController.m */; }; + 0276253C16B59E4C00EE2F4E /* Configuration.m in Sources */ = {isa = PBXBuildFile; fileRef = 0276253B16B59E4C00EE2F4E /* Configuration.m */; }; + 0276253F16B59E4C00EE2F4E /* Threshold.m in Sources */ = {isa = PBXBuildFile; fileRef = 0276253E16B59E4C00EE2F4E /* Threshold.m */; }; + 0276254216B5A64000EE2F4E /* ThresholdListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0276254116B5A64000EE2F4E /* ThresholdListViewController.m */; }; + 0276254516B5AACF00EE2F4E /* ThresholdViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0276254416B5AACF00EE2F4E /* ThresholdViewController.m */; }; + 0276254816B5BC5300EE2F4E /* ThresholdCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 0276254716B5BC5300EE2F4E /* ThresholdCell.m */; }; 02E557AE16A9C1E40080FBBA /* BeanCollectionExtractionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 02E557AD16A9C1E40080FBBA /* BeanCollectionExtractionViewController.m */; }; 02E557B116A9CFB50080FBBA /* BeanCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 02E557B016A9CFB50080FBBA /* BeanCell.m */; }; 02E557BA16AC85A20080FBBA /* BeanCollectionExtractionScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 02E557B916AC85A20080FBBA /* BeanCollectionExtractionScrollView.m */; }; @@ -81,8 +86,18 @@ 020C569B16A49C8300D8224C /* Configuration+Interface.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Configuration+Interface.m"; sourceTree = ""; }; 024F676B16A4A61D004A1201 /* InstantExtractionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InstantExtractionViewController.h; sourceTree = ""; }; 024F676C16A4A61D004A1201 /* InstantExtractionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InstantExtractionViewController.m; sourceTree = ""; }; - 0276252416B5477800EE2F4E /* Configuration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Configuration.h; sourceTree = ""; }; - 0276252516B5477800EE2F4E /* Configuration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Configuration.m; sourceTree = ""; }; + 0276253716B58D6000EE2F4E /* SettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingsViewController.h; sourceTree = ""; }; + 0276253816B58D6000EE2F4E /* SettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingsViewController.m; sourceTree = ""; }; + 0276253A16B59E4C00EE2F4E /* Configuration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Configuration.h; sourceTree = ""; }; + 0276253B16B59E4C00EE2F4E /* Configuration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Configuration.m; sourceTree = ""; }; + 0276253D16B59E4C00EE2F4E /* Threshold.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Threshold.h; sourceTree = ""; }; + 0276253E16B59E4C00EE2F4E /* Threshold.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Threshold.m; sourceTree = ""; }; + 0276254016B5A64000EE2F4E /* ThresholdListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThresholdListViewController.h; sourceTree = ""; }; + 0276254116B5A64000EE2F4E /* ThresholdListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThresholdListViewController.m; sourceTree = ""; }; + 0276254316B5AACF00EE2F4E /* ThresholdViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThresholdViewController.h; sourceTree = ""; }; + 0276254416B5AACF00EE2F4E /* ThresholdViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThresholdViewController.m; sourceTree = ""; }; + 0276254616B5BC5300EE2F4E /* ThresholdCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThresholdCell.h; sourceTree = ""; }; + 0276254716B5BC5300EE2F4E /* ThresholdCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThresholdCell.m; sourceTree = ""; }; 02E557AC16A9C1E40080FBBA /* BeanCollectionExtractionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BeanCollectionExtractionViewController.h; sourceTree = ""; }; 02E557AD16A9C1E40080FBBA /* BeanCollectionExtractionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BeanCollectionExtractionViewController.m; sourceTree = ""; }; 02E557AF16A9CFB50080FBBA /* BeanCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BeanCell.h; sourceTree = ""; }; @@ -137,6 +152,7 @@ 020C559F1691014E00D8224C /* iBean */ = { isa = PBXGroup; children = ( + 0276253316B58C2C00EE2F4E /* Settings */, 020C55D31695C2C800D8224C /* iBean */, 020C55B9169101A300D8224C /* InstantExtraction */, 020C55DF169792F800D8224C /* Data */, @@ -198,9 +214,11 @@ 020C55DF169792F800D8224C /* Data */ = { isa = PBXGroup; children = ( + 0276253D16B59E4C00EE2F4E /* Threshold.h */, + 0276253E16B59E4C00EE2F4E /* Threshold.m */, + 0276253A16B59E4C00EE2F4E /* Configuration.h */, + 0276253B16B59E4C00EE2F4E /* Configuration.m */, 020C5684169F603700D8224C /* Interface */, - 0276252416B5477800EE2F4E /* Configuration.h */, - 0276252516B5477800EE2F4E /* Configuration.m */, 020C567B169F597300D8224C /* BeanCollection.h */, 020C567C169F597300D8224C /* BeanCollection.m */, 020C5678169F597300D8224C /* Bean.h */, @@ -269,6 +287,21 @@ name = "Step 4 - Extraction"; sourceTree = ""; }; + 0276253316B58C2C00EE2F4E /* Settings */ = { + isa = PBXGroup; + children = ( + 0276253716B58D6000EE2F4E /* SettingsViewController.h */, + 0276253816B58D6000EE2F4E /* SettingsViewController.m */, + 0276254016B5A64000EE2F4E /* ThresholdListViewController.h */, + 0276254116B5A64000EE2F4E /* ThresholdListViewController.m */, + 0276254316B5AACF00EE2F4E /* ThresholdViewController.h */, + 0276254416B5AACF00EE2F4E /* ThresholdViewController.m */, + 0276254616B5BC5300EE2F4E /* ThresholdCell.h */, + 0276254716B5BC5300EE2F4E /* ThresholdCell.m */, + ); + name = Settings; + sourceTree = ""; + }; 02E557AA16A9C1B90080FBBA /* BeanCollectionExtraction */ = { isa = PBXGroup; children = ( @@ -367,7 +400,12 @@ 02E557AE16A9C1E40080FBBA /* BeanCollectionExtractionViewController.m in Sources */, 02E557B116A9CFB50080FBBA /* BeanCell.m in Sources */, 02E557BA16AC85A20080FBBA /* BeanCollectionExtractionScrollView.m in Sources */, - 0276252616B5477800EE2F4E /* Configuration.m in Sources */, + 0276253916B58D6000EE2F4E /* SettingsViewController.m in Sources */, + 0276253C16B59E4C00EE2F4E /* Configuration.m in Sources */, + 0276253F16B59E4C00EE2F4E /* Threshold.m in Sources */, + 0276254216B5A64000EE2F4E /* ThresholdListViewController.m in Sources */, + 0276254516B5AACF00EE2F4E /* ThresholdViewController.m in Sources */, + 0276254816B5BC5300EE2F4E /* ThresholdCell.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 7305da1..7b3eccf 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 c76aba4..1563c41 100644 --- a/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist +++ b/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist @@ -8,11 +8,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "iBean/InstantExtractionViewController.m" - timestampString = "380979696.779799" + timestampString = "380990419.117278" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "79" - endingLineNumber = "79" + startingLineNumber = "80" + endingLineNumber = "80" landmarkName = "-haltExtractionTimer" landmarkType = "5"> @@ -21,11 +21,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "iBean/InstantExtractionViewController.m" - timestampString = "380979696.779799" + timestampString = "380990419.117278" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "90" - endingLineNumber = "90" + startingLineNumber = "88" + endingLineNumber = "88" landmarkName = "-timerInterrupted" landmarkType = "5"> @@ -34,11 +34,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "iBean/AppDelegate+Storage.m" - timestampString = "380979696.779799" + timestampString = "380990077.537405" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "190" - endingLineNumber = "190" + startingLineNumber = "271" + endingLineNumber = "271" landmarkName = "-createTimer::::" landmarkType = "5"> diff --git a/iBean/iBean/AppDelegate+Storage.h b/iBean/iBean/AppDelegate+Storage.h index ad94cb6..44c4a0f 100644 --- a/iBean/iBean/AppDelegate+Storage.h +++ b/iBean/iBean/AppDelegate+Storage.h @@ -28,12 +28,15 @@ - (Configuration*) getConfiguration; //Extraction counter methods -/* +- (NSError*) setCountExtractions: (BOOL) countExtractions; - (NSNumber*) getExtractionCount; -- (NSNumber*) increaseExtractionCount; -- (NSNumber*) decreaseExtractionCount; -- (void) resetExtractionCount; -*/ +- (NSError*) setExtractionCount: (NSNumber*) extractionCount; +- (NSNumber*) incrementExtractionCount; + +//Thresholds methods +- (void) processThresholds; + + //Instant extraction related methods - (NSError*) setInstantExtractionTimer: (NSNumber*) extractionTimer; diff --git a/iBean/iBean/AppDelegate+Storage.m b/iBean/iBean/AppDelegate+Storage.m index ca0e81d..fc911f6 100644 --- a/iBean/iBean/AppDelegate+Storage.m +++ b/iBean/iBean/AppDelegate+Storage.m @@ -58,7 +58,7 @@ NSLog(@"getConfiguration - Fetch request resulted in an error!"); UIAlertView *loadErrorAlert = [[UIAlertView alloc] - initWithTitle:@"Load error!" + initWithTitle:@"Configuration error!" message:@"Unable to load iBean configuration." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [loadErrorAlert show]; @@ -70,11 +70,12 @@ { //Set default configuration values: config.instantExtractionTimer = [NSNumber numberWithDouble:25.0f]; +#warning TODO - Add call to iBean core data startup (to add example data) } else { UIAlertView *createConfigurationAlert = [[UIAlertView alloc] - initWithTitle:@"Create config error!" + initWithTitle:@"Configuration error!" message:@"iBean unable to create configuration object.\n(Please check memory available.)" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; @@ -89,6 +90,76 @@ return config; } +//Extraction count related methods +- (NSError*) setCountExtractions: (BOOL) countExtractions +{ + NSError *error = nil; + Configuration *c = [self getConfiguration]; + if (c != nil) + { + c.countExtractions = [NSNumber numberWithBool:countExtractions]; + error = [self save]; + } + + return error; +} + +- (NSNumber*) getExtractionCount +{ + NSNumber *extractionCount = nil; + Configuration* c = [self getConfiguration]; + extractionCount = c != nil ? c.extractionCount : [NSNumber numberWithInt:-1]; + return extractionCount; +} + +- (NSError*) setExtractionCount: (NSNumber*) extractionCount +{ + NSError *error = nil; + Configuration *c = [self getConfiguration]; + if (c != nil) + { + c.extractionCount = extractionCount < 0 ? 0 : extractionCount; + error = [self save]; + + if (error != nil) + { + UIAlertView *setExtractionCountAlert = [[UIAlertView alloc] + initWithTitle:@"Configuration error!" + message:@"iBean unable to set extraction count value." + delegate:nil + cancelButtonTitle:@"OK" otherButtonTitles: nil]; + [setExtractionCountAlert show]; + } + } + + return error; +} + +- (NSNumber*) incrementExtractionCount +{ + Configuration *c = [self getConfiguration]; + + if (c != nil) + { + if ([c.countExtractions boolValue] == YES) + { + if ([self setExtractionCount:[NSNumber numberWithInteger:([c.extractionCount integerValue] + 1)]] != nil) + { + [self processThresholds]; + return c.extractionCount; + } + } + } + return [NSNumber numberWithInteger:-1]; +} + +- (void) processThresholds +{ +#warning TODO - Implement this + //Simply go through the thresholds array and alert on those that are enabled and "active". + //Find out how to make the list of thresholds sorted on the value. +} + #pragma mark - Instant extraction related methods (using Configuraiton) - (NSError*)setInstantExtractionTimer:(NSNumber *)extractionTimer { @@ -98,8 +169,18 @@ if (c != nil) { c.instantExtractionTimer = extractionTimer; - error = [(AppDelegate*) [[UIApplication sharedApplication] delegate] save]; + error = [self save]; } + + if (error != nil) + { + UIAlertView *setInstantExtractionTimerAlert = [[UIAlertView alloc] + initWithTitle:@"Configuration error!" + message:@"iBean unable to set extraction timer setting for instant extraction." + delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; + [setInstantExtractionTimerAlert show]; + } + return error; } diff --git a/iBean/iBean/BeanCollectionExtractionViewController.m b/iBean/iBean/BeanCollectionExtractionViewController.m index 785c981..dea550d 100644 --- a/iBean/iBean/BeanCollectionExtractionViewController.m +++ b/iBean/iBean/BeanCollectionExtractionViewController.m @@ -99,6 +99,7 @@ { NSLog(@"Timer reached its limit!"); [self haltExtractionTimer]; + NSLog(@"Extraction count = %@", [(AppDelegate*) [[UIApplication sharedApplication] delegate] incrementExtractionCount]); } } diff --git a/iBean/iBean/Configuration.h b/iBean/iBean/Configuration.h index 3753bd6..00159ce 100644 --- a/iBean/iBean/Configuration.h +++ b/iBean/iBean/Configuration.h @@ -9,9 +9,27 @@ #import #import +@class Threshold; @interface Configuration : NSManagedObject @property (nonatomic, retain) NSNumber * instantExtractionTimer; +@property (nonatomic, retain) NSNumber * extractionCount; +@property (nonatomic, retain) NSNumber * countExtractions; +@property (nonatomic, retain) NSNumber * useThresholds; +@property (nonatomic, retain) NSOrderedSet *thresholds; +@end + +@interface Configuration (CoreDataGeneratedAccessors) +- (void)insertObject:(Threshold *)value inThresholdsAtIndex:(NSUInteger)idx; +- (void)removeObjectFromThresholdsAtIndex:(NSUInteger)idx; +- (void)insertThresholds:(NSArray *)value atIndexes:(NSIndexSet *)indexes; +- (void)removeThresholdsAtIndexes:(NSIndexSet *)indexes; +- (void)replaceObjectInThresholdsAtIndex:(NSUInteger)idx withObject:(Threshold *)value; +- (void)replaceThresholdsAtIndexes:(NSIndexSet *)indexes withThresholds:(NSArray *)values; +- (void)addThresholdsObject:(Threshold *)value; +- (void)removeThresholdsObject:(Threshold *)value; +- (void)addThresholds:(NSOrderedSet *)values; +- (void)removeThresholds:(NSOrderedSet *)values; @end diff --git a/iBean/iBean/Configuration.m b/iBean/iBean/Configuration.m index cba131b..e086bdd 100644 --- a/iBean/iBean/Configuration.m +++ b/iBean/iBean/Configuration.m @@ -7,10 +7,15 @@ // #import "Configuration.h" +#import "Threshold.h" @implementation Configuration @dynamic instantExtractionTimer; +@dynamic extractionCount; +@dynamic countExtractions; +@dynamic useThresholds; +@dynamic thresholds; @end diff --git a/iBean/iBean/InstantExtractionViewController.m b/iBean/iBean/InstantExtractionViewController.m index 0ab0a9c..4c02b62 100644 --- a/iBean/iBean/InstantExtractionViewController.m +++ b/iBean/iBean/InstantExtractionViewController.m @@ -66,6 +66,7 @@ { NSLog(@"Timer reached its limit!"); [self haltExtractionTimer]; + NSLog(@"Extraction count = %@", [(AppDelegate*) [[UIApplication sharedApplication] delegate] incrementExtractionCount]); } } @@ -116,16 +117,7 @@ - (IBAction)setExtractionTimer:(id)sender { NSError* error = [(AppDelegate*) [[UIApplication sharedApplication] delegate] setInstantExtractionTimer:[NSNumber numberWithDouble:self.extractionSettingStepper.value]]; - if (error != nil) - { - NSLog(@"InstantExtraction unable to save configuration!"); - UIAlertView *saveErrorAlert = [[UIAlertView alloc] - initWithTitle:@"Save error!" - message:@"Unable to save configuration." - delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; - [saveErrorAlert show]; - } - - [self updateExtractionSettingLabel]; + if (error == nil) + [self updateExtractionSettingLabel]; } @end diff --git a/iBean/iBean/SettingsViewController.h b/iBean/iBean/SettingsViewController.h new file mode 100644 index 0000000..86b14bd --- /dev/null +++ b/iBean/iBean/SettingsViewController.h @@ -0,0 +1,30 @@ +// +// SettingsViewController.h +// iBean +// +// Created by Eddie Ehlin on 2013-01-27. +// Copyright (c) 2013 Eddie Ehlin. All rights reserved. +// + +#import +@class Configuration; + +@interface SettingsViewController : UITableViewController + +@property (nonatomic, strong) Configuration *configuration; + +/* Utility methods */ +- (void) initViewController; + +/* UI Outlets */ +@property (weak, nonatomic) IBOutlet UISwitch *countExtractionsSwitch; +@property (weak, nonatomic) IBOutlet UISwitch *useThresholdsSwitch; +@property (weak, nonatomic) IBOutlet UIStepper *extractionCountStepper; +@property (weak, nonatomic) IBOutlet UILabel *extractionCountLabel; + +/* UI Actions */ +- (IBAction)countExtractionsSwitchChanged:(id)sender; +- (IBAction)useThresholdsSwitchChanged:(id)sender; +- (IBAction)extractionCountStepperChanged:(id)sender; + +@end diff --git a/iBean/iBean/SettingsViewController.m b/iBean/iBean/SettingsViewController.m new file mode 100644 index 0000000..cce498f --- /dev/null +++ b/iBean/iBean/SettingsViewController.m @@ -0,0 +1,140 @@ +// +// SettingsViewController.m +// iBean +// +// Created by Eddie Ehlin on 2013-01-27. +// Copyright (c) 2013 Eddie Ehlin. All rights reserved. +// + +#import "SettingsViewController.h" +#import "Configuration+Interface.h" +#import "AppDelegate+Storage.h" + +@interface SettingsViewController () + +@end + +@implementation SettingsViewController + +- (id)initWithStyle:(UITableViewStyle)style +{ + self = [super initWithStyle:style]; + if (self) { + // Custom initialization + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + // Uncomment the following line to preserve selection between presentations. + // self.clearsSelectionOnViewWillAppear = NO; + + // Uncomment the following line to display an Edit button in the navigation bar for this view controller. + // self.navigationItem.rightBarButtonItem = self.editButtonItem; +} + +- (void) viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + [self initViewController]; +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +/***************************************************** + Utility methods + *****************************************************/ +- (void) initViewController +{ + NSLog(@"SettingsViewController - initViewController"); + + //Let's go fetch Configuration! + self.configuration = [(AppDelegate*) [[UIApplication sharedApplication] delegate] getConfiguration]; + + if (self.configuration != nil) + { + self.countExtractionsSwitch.on = [self.configuration.countExtractions boolValue]; + self.useThresholdsSwitch.on = [self.configuration.useThresholds boolValue]; + + self.extractionCountLabel.text = [self.configuration.extractionCount stringValue]; + self.extractionCountStepper.value = [self.configuration.extractionCount integerValue]; + } + else + { + self.countExtractionsSwitch.enabled = NO; + self.useThresholdsSwitch.enabled = NO; + self.extractionCountStepper.enabled = NO; + } +} + +/***************************************************** + UI Actions + *****************************************************/ +- (void) countExtractionsSwitchChanged:(id)sender +{ + if (self.configuration != nil) + { + self.configuration.countExtractions = [NSNumber numberWithBool: self.countExtractionsSwitch.on]; + NSError *error = [(AppDelegate*) [[UIApplication sharedApplication] delegate] save]; + if (error != nil) + { + UIAlertView *setCountExtractionsAlert = [[UIAlertView alloc] + initWithTitle:@"Configuration error!" + message:@"iBean was not able to save configuration attribute for \"Count extractions\"." + delegate:nil + cancelButtonTitle:@"OK" otherButtonTitles: nil]; + [setCountExtractionsAlert show]; + } + } +} + +- (void) useThresholdsSwitchChanged:(id)sender +{ + if (self.configuration != nil) + { + self.configuration.useThresholds = [NSNumber numberWithBool: self.useThresholdsSwitch.on]; + NSError *error = [(AppDelegate*) [[UIApplication sharedApplication] delegate] save]; + if (error != nil) + { + UIAlertView *setUseThresholdsAlert = [[UIAlertView alloc] + initWithTitle:@"Configuration error!" + message:@"iBean was not able to save configuration attribute for \"Thresholds\"." + delegate:nil + cancelButtonTitle:@"OK" otherButtonTitles: nil]; + [setUseThresholdsAlert show]; + } + } +} + +- (void) extractionCountStepperChanged:(id)sender +{ + if (self.configuration != nil) + { + self.configuration.extractionCount = [NSNumber numberWithDouble:self.extractionCountStepper.value]; + + self.extractionCountLabel.text = [self.configuration.extractionCount stringValue]; + NSError *error = [(AppDelegate*) [[UIApplication sharedApplication] delegate] save]; + if (error != nil) + { + UIAlertView *setExtractionCountAlert = [[UIAlertView alloc] + initWithTitle:@"Configuration error!" + message:@"iBean was not able to save configuration attribute for \"Extraction count\"." + delegate:nil + cancelButtonTitle:@"OK" otherButtonTitles: nil]; + [setExtractionCountAlert show]; + } + } +} + +/***************************************************** + Delegates + *****************************************************/ + +@end diff --git a/iBean/iBean/Threshold.h b/iBean/iBean/Threshold.h new file mode 100644 index 0000000..7034bcd --- /dev/null +++ b/iBean/iBean/Threshold.h @@ -0,0 +1,21 @@ +// +// Threshold.h +// iBean +// +// Created by Eddie Ehlin on 2013-01-27. +// Copyright (c) 2013 Eddie Ehlin. All rights reserved. +// + +#import +#import + +@class Configuration; + +@interface Threshold : NSManagedObject + +@property (nonatomic, retain) NSString * name; +@property (nonatomic, retain) NSNumber * value; +@property (nonatomic, retain) NSNumber * enabled; +@property (nonatomic, retain) Configuration *configuration; + +@end diff --git a/iBean/iBean/Threshold.m b/iBean/iBean/Threshold.m new file mode 100644 index 0000000..e8c6d85 --- /dev/null +++ b/iBean/iBean/Threshold.m @@ -0,0 +1,20 @@ +// +// Threshold.m +// iBean +// +// Created by Eddie Ehlin on 2013-01-27. +// Copyright (c) 2013 Eddie Ehlin. All rights reserved. +// + +#import "Threshold.h" +#import "Configuration.h" + + +@implementation Threshold + +@dynamic name; +@dynamic value; +@dynamic enabled; +@dynamic configuration; + +@end diff --git a/iBean/iBean/ThresholdCell.h b/iBean/iBean/ThresholdCell.h new file mode 100644 index 0000000..30c2db0 --- /dev/null +++ b/iBean/iBean/ThresholdCell.h @@ -0,0 +1,26 @@ +// +// ThresholdCell.h +// iBean +// +// Created by Eddie Ehlin on 2013-01-27. +// Copyright (c) 2013 Eddie Ehlin. All rights reserved. +// + +#import +@class Threshold; + +@interface ThresholdCell : UITableViewCell + +@property (strong, nonatomic) Threshold* threshold; + +@property (weak, nonatomic) IBOutlet UISwitch *enabledSwitch; +@property (weak, nonatomic) IBOutlet UILabel *nameLabel; +@property (weak, nonatomic) IBOutlet UILabel *valueLabel; + +/* Utility methods */ +- (void) initWithThresholdEntity: (Threshold*) threshold; + +/* UI Actions */ +- (IBAction)switchChanged:(id)sender; + +@end diff --git a/iBean/iBean/ThresholdCell.m b/iBean/iBean/ThresholdCell.m new file mode 100644 index 0000000..b18bd57 --- /dev/null +++ b/iBean/iBean/ThresholdCell.m @@ -0,0 +1,60 @@ +// +// ThresholdCell.m +// iBean +// +// Created by Eddie Ehlin on 2013-01-27. +// Copyright (c) 2013 Eddie Ehlin. All rights reserved. +// + +#import "ThresholdCell.h" +#import "Threshold.h" + +@implementation ThresholdCell + +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier +{ + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; + if (self) { + // Initialization code + NSLog(@"ThresholdCell - initWithStyle"); + } + return self; +} + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated +{ + [super setSelected:selected animated:animated]; + + // Configure the view for the selected state +} + +/***************************************************** + Utility methods + *****************************************************/ +- (void) initWithThresholdEntity:(Threshold *)threshold +{ + self.threshold = threshold; + if (self.threshold != nil) + { + self.nameLabel.text = self.threshold.name; + self.valueLabel.text = [self.threshold.value stringValue]; + self.enabledSwitch.on = [self.threshold.enabled boolValue]; + } + + //Setup UI action + [self.enabledSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; +} + +/***************************************************** + UI Actions + *****************************************************/ +- (void) switchChanged:(id)sender +{ + if (self.threshold != nil) + { + self.threshold.enabled = [NSNumber numberWithBool:self.enabledSwitch.on]; +#warning TODO - Trigger save!? + } +} + +@end diff --git a/iBean/iBean/ThresholdListViewController.h b/iBean/iBean/ThresholdListViewController.h new file mode 100644 index 0000000..eb909d7 --- /dev/null +++ b/iBean/iBean/ThresholdListViewController.h @@ -0,0 +1,20 @@ +// +// ThresholdListViewController.h +// iBean +// +// Created by Eddie Ehlin on 2013-01-27. +// Copyright (c) 2013 Eddie Ehlin. All rights reserved. +// + +#import + +@interface ThresholdListViewController : UIViewController + +/* Utility methods */ +- (void) initViewController; + +/* UI Outlets */ + +/* UI Actions */ + +@end diff --git a/iBean/iBean/ThresholdListViewController.m b/iBean/iBean/ThresholdListViewController.m new file mode 100644 index 0000000..d6ce20e --- /dev/null +++ b/iBean/iBean/ThresholdListViewController.m @@ -0,0 +1,129 @@ +// +// ThresholdListViewController.m +// iBean +// +// Created by Eddie Ehlin on 2013-01-27. +// Copyright (c) 2013 Eddie Ehlin. All rights reserved. +// + +#import "ThresholdListViewController.h" + +@interface ThresholdListViewController () + +@end + +@implementation ThresholdListViewController + +- (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)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +/***************************************************** + Utility methods + *****************************************************/ + + +/***************************************************** + UI Actions + *****************************************************/ + + +/***************************************************** + Delegates + *****************************************************/ +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ +#warning Potentially incomplete method implementation. + // Return the number of sections. + return 0; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ +#warning Incomplete method implementation. + // Return the number of rows in the section. + return 0; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString *CellIdentifier = @"ThresholdCell"; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; + + // Configure the cell... + + return cell; +} + +/* + // Override to support conditional editing of the table view. + - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath + { + // Return NO if you do not want the specified item to be editable. + return YES; + } + */ + +/* + // Override to support editing the table view. + - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath + { + if (editingStyle == UITableViewCellEditingStyleDelete) { + // Delete the row from the data source + [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; + } + else if (editingStyle == UITableViewCellEditingStyleInsert) { + // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view + } + } + */ + +/* + // Override to support rearranging the table view. + - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath + { + } + */ + +/* + // Override to support conditional rearranging of the table view. + - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath + { + // Return NO if you do not want the item to be re-orderable. + return YES; + } + */ + +#pragma mark - Table view delegate + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + // Navigation logic may go here. Create and push another view controller. + /* + <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; + // ... + // Pass the selected object to the new view controller. + [self.navigationController pushViewController:detailViewController animated:YES]; + */ +} + +@end diff --git a/iBean/iBean/ThresholdViewController.h b/iBean/iBean/ThresholdViewController.h new file mode 100644 index 0000000..dc63752 --- /dev/null +++ b/iBean/iBean/ThresholdViewController.h @@ -0,0 +1,20 @@ +// +// ThresholdViewController.h +// iBean +// +// Created by Eddie Ehlin on 2013-01-27. +// Copyright (c) 2013 Eddie Ehlin. All rights reserved. +// + +#import + +@interface ThresholdViewController : UITableViewController + +/* Utility methods */ +- (void) initViewController; + +/* UI Outlets */ + +/* UI Actions */ + +@end diff --git a/iBean/iBean/ThresholdViewController.m b/iBean/iBean/ThresholdViewController.m new file mode 100644 index 0000000..1769dfe --- /dev/null +++ b/iBean/iBean/ThresholdViewController.m @@ -0,0 +1,57 @@ +// +// ThresholdViewController.m +// iBean +// +// Created by Eddie Ehlin on 2013-01-27. +// Copyright (c) 2013 Eddie Ehlin. All rights reserved. +// + +#import "ThresholdViewController.h" + +@interface ThresholdViewController () + +@end + +@implementation ThresholdViewController + +- (id)initWithStyle:(UITableViewStyle)style +{ + self = [super initWithStyle:style]; + if (self) { + // Custom initialization + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + // Uncomment the following line to preserve selection between presentations. + // self.clearsSelectionOnViewWillAppear = NO; + + // Uncomment the following line to display an Edit button in the navigation bar for this view controller. + // self.navigationItem.rightBarButtonItem = self.editButtonItem; +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +/***************************************************** + Utility methods + *****************************************************/ + + +/***************************************************** + UI Actions + *****************************************************/ + + +/***************************************************** + Delegates + *****************************************************/ + +@end diff --git a/iBean/iBean/iBean.xcdatamodeld/iBean.xcdatamodel/contents b/iBean/iBean/iBean.xcdatamodeld/iBean.xcdatamodel/contents index f89e12d..f421adc 100644 --- a/iBean/iBean/iBean.xcdatamodeld/iBean.xcdatamodel/contents +++ b/iBean/iBean/iBean.xcdatamodeld/iBean.xcdatamodel/contents @@ -16,11 +16,22 @@ + + + + + + + + + + - + + \ No newline at end of file diff --git a/iBean/iBean/iPhoneStoryboard.storyboard b/iBean/iBean/iPhoneStoryboard.storyboard index 2cb8195..683bc9f 100644 --- a/iBean/iBean/iPhoneStoryboard.storyboard +++ b/iBean/iBean/iPhoneStoryboard.storyboard @@ -57,7 +57,7 @@ - + @@ -128,7 +128,7 @@ - + @@ -143,12 +143,375 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -166,7 +529,7 @@ - + @@ -258,7 +621,7 @@ - + @@ -338,7 +701,7 @@ - + @@ -440,7 +803,7 @@ - + @@ -494,7 +857,7 @@ - + @@ -612,7 +975,7 @@ - + @@ -631,7 +994,7 @@ - + @@ -785,7 +1148,26 @@ - + + + + + + + + + + + + + + + + + + + + @@ -890,6 +1272,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -897,7 +1305,8 @@ + + - \ No newline at end of file -- cgit v1.2.3