aboutsummaryrefslogtreecommitdiffstats
path: root/iBean
diff options
context:
space:
mode:
Diffstat (limited to 'iBean')
-rw-r--r--iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstatebin44255 -> 43058 bytes
-rw-r--r--iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist32
-rw-r--r--iBean/iBean/AppDelegate+Storage.h2
-rw-r--r--iBean/iBean/AppDelegate+Storage.m17
-rw-r--r--iBean/iBean/BeanCollection+Interface.m3
-rw-r--r--iBean/iBean/Configuration+Interface.h4
-rw-r--r--iBean/iBean/Configuration+Interface.m42
-rw-r--r--iBean/iBean/SettingsViewController.m10
-rw-r--r--iBean/iBean/ThresholdCell.m14
-rw-r--r--iBean/iBean/ThresholdListViewController.h9
-rw-r--r--iBean/iBean/ThresholdListViewController.m174
-rw-r--r--iBean/iBean/ThresholdViewController.h17
-rw-r--r--iBean/iBean/ThresholdViewController.m83
-rw-r--r--iBean/iBean/iPhoneStoryboard.storyboard61
14 files changed, 399 insertions, 69 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 7b3eccf..673cad7 100644
--- a/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate
+++ b/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate
Binary files differ
diff --git a/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist b/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
index 1563c41..d07f366 100644
--- a/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
+++ b/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -34,13 +34,39 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "iBean/AppDelegate+Storage.m"
- timestampString = "380990077.537405"
+ timestampString = "381268321.748787"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "271"
- endingLineNumber = "271"
+ startingLineNumber = "288"
+ endingLineNumber = "288"
landmarkName = "-createTimer::::"
landmarkType = "5">
</FileBreakpoint>
+ <FileBreakpoint
+ shouldBeEnabled = "No"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ filePath = "iBean/ThresholdViewController.m"
+ timestampString = "381271322.430192"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "86"
+ endingLineNumber = "86"
+ landmarkName = "-commitThreshold:"
+ landmarkType = "5">
+ </FileBreakpoint>
+ <FileBreakpoint
+ shouldBeEnabled = "Yes"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ filePath = "iBean/ThresholdListViewController.m"
+ timestampString = "381273377.804792"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "140"
+ endingLineNumber = "140"
+ landmarkName = "-tableView:commitEditingStyle:forRowAtIndexPath:"
+ landmarkType = "5">
+ </FileBreakpoint>
</FileBreakpoints>
</Bucket>
diff --git a/iBean/iBean/AppDelegate+Storage.h b/iBean/iBean/AppDelegate+Storage.h
index 44c4a0f..f668396 100644
--- a/iBean/iBean/AppDelegate+Storage.h
+++ b/iBean/iBean/AppDelegate+Storage.h
@@ -10,6 +10,7 @@
@class Configuration;
@class BeanCollection;
@class Bean;
+@class Threshold;
/*
Main purpose of this category is to have all storage (core data) related
@@ -35,6 +36,7 @@
//Thresholds methods
- (void) processThresholds;
+- (Threshold*) createThreshold;
diff --git a/iBean/iBean/AppDelegate+Storage.m b/iBean/iBean/AppDelegate+Storage.m
index fc911f6..fe62969 100644
--- a/iBean/iBean/AppDelegate+Storage.m
+++ b/iBean/iBean/AppDelegate+Storage.m
@@ -160,6 +160,23 @@
//Find out how to make the list of thresholds sorted on the value.
}
+- (Threshold*) createThreshold
+{
+ Threshold *t = nil;
+
+ if (self.managedObjectContext != nil)
+ {
+ t = [NSEntityDescription insertNewObjectForEntityForName:@"Threshold" inManagedObjectContext:self.managedObjectContext];
+
+ //Set default values
+ if (t != nil)
+ {
+ //TODO: Set default values here...
+ }
+ }
+ return t;
+}
+
#pragma mark - Instant extraction related methods (using Configuraiton)
- (NSError*)setInstantExtractionTimer:(NSNumber *)extractionTimer
{
diff --git a/iBean/iBean/BeanCollection+Interface.m b/iBean/iBean/BeanCollection+Interface.m
index e01e25e..efc35c6 100644
--- a/iBean/iBean/BeanCollection+Interface.m
+++ b/iBean/iBean/BeanCollection+Interface.m
@@ -34,7 +34,8 @@
NSLog(@"BeanCollection+Interface - removeBeansObjectAtIndex: Index out of range!");
}
-- (void)replaceBeansAtIndexes:(NSIndexSet *)beanIndexes withBeans:(NSArray *)beans {
+- (void)replaceBeansAtIndexes:(NSIndexSet *)beanIndexes withBeans:(NSArray *)beans
+{
/*
[self willChange:NSKeyValueChangeReplacement valuesAtIndexes:indexes forKey:@"beans"];
NSMutableOrderedSet *tmpOrderedSet = [NSMutableOrderedSet orderedSetWithOrderedSet:[self mutableOrderedSetValueForKey:@"beans"]];
diff --git a/iBean/iBean/Configuration+Interface.h b/iBean/iBean/Configuration+Interface.h
index d2660b7..6e66cfe 100644
--- a/iBean/iBean/Configuration+Interface.h
+++ b/iBean/iBean/Configuration+Interface.h
@@ -10,4 +10,8 @@
@interface Configuration (Interface)
+- (void) addThresholdsObject: (Threshold *)t;
+- (void) removeObjectFromThresholdsAtIndex:(NSUInteger)thresholdIndex;
+- (void)replaceThresholdsAtIndexes:(NSIndexSet *)thresholdIndexes withThresholds:(NSArray *)thresholds;
+
@end
diff --git a/iBean/iBean/Configuration+Interface.m b/iBean/iBean/Configuration+Interface.m
index 549997e..230f529 100644
--- a/iBean/iBean/Configuration+Interface.m
+++ b/iBean/iBean/Configuration+Interface.m
@@ -10,4 +10,46 @@
@implementation Configuration (Interface)
+- (void) addThresholdsObject:(Threshold *)t
+{
+ NSMutableOrderedSet *tmpSet = [self mutableOrderedSetValueForKey:@"thresholds"];
+ [tmpSet addObject:t];
+}
+
+- (void) removeObjectFromThresholdsAtIndex:(NSUInteger)thresholdIndex
+{
+ /*
+ NSIndexSet* indexes = [NSIndexSet indexSetWithIndex:idx];
+ [self willChange:NSKeyValueChangeRemoval valuesAtIndexes:indexes forKey:@"beans"];
+ NSMutableOrderedSet *tmpOrderedSet = [NSMutableOrderedSet orderedSetWithOrderedSet:[self mutableOrderedSetValueForKey:@"beans"]];
+ [tmpOrderedSet removeObjectAtIndex:idx];
+ [self setPrimitiveValue:tmpOrderedSet forKey:@"beans"];
+ [self didChange:NSKeyValueChangeRemoval valuesAtIndexes:indexes forKey:@"beans"];
+ */
+
+ NSMutableOrderedSet *tmpSet = [self mutableOrderedSetValueForKey:@"thresholds"];
+ if (thresholdIndex >= 0 && thresholdIndex < tmpSet.count)
+ [tmpSet removeObjectAtIndex:thresholdIndex];
+ else
+ NSLog(@"Configuration+Interface - removeObjectFromThresholdsAtIndex: Index out of range!");
+}
+
+- (void)replaceThresholdsAtIndexes:(NSIndexSet *)thresholdsIndexes withBeans:(NSArray *)thresholds
+{
+ /*
+ [self willChange:NSKeyValueChangeReplacement valuesAtIndexes:indexes forKey:@"beans"];
+ NSMutableOrderedSet *tmpOrderedSet = [NSMutableOrderedSet orderedSetWithOrderedSet:[self mutableOrderedSetValueForKey:@"beans"]];
+ [tmpOrderedSet replaceObjectsAtIndexes:indexes withObjects:values];
+ [self setPrimitiveValue:tmpOrderedSet forKey:@"beans"];
+ [self didChange:NSKeyValueChangeReplacement valuesAtIndexes:indexes forKey:@"beans"];
+ */
+
+ if (thresholds.count > 0)
+ {
+ NSMutableOrderedSet *tmpSet = [self mutableOrderedSetValueForKey:@"thresholds"];
+ [tmpSet replaceObjectsAtIndexes:thresholdsIndexes withObjects:thresholds];
+ }
+
+}
+
@end
diff --git a/iBean/iBean/SettingsViewController.m b/iBean/iBean/SettingsViewController.m
index cce498f..242bee1 100644
--- a/iBean/iBean/SettingsViewController.m
+++ b/iBean/iBean/SettingsViewController.m
@@ -9,6 +9,7 @@
#import "SettingsViewController.h"
#import "Configuration+Interface.h"
#import "AppDelegate+Storage.h"
+#import "ThresholdListViewController.h"
@interface SettingsViewController ()
@@ -48,6 +49,15 @@
// Dispose of any resources that can be recreated.
}
+- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+{
+ if ([segue.identifier isEqualToString:@"SettingsThresholdSegue"])
+ {
+ ThresholdListViewController *thresholdListViewController = segue.destinationViewController;
+ [thresholdListViewController initWithConfiguration:self.configuration];
+ }
+}
+
/*****************************************************
Utility methods
*****************************************************/
diff --git a/iBean/iBean/ThresholdCell.m b/iBean/iBean/ThresholdCell.m
index b18bd57..bc89b4b 100644
--- a/iBean/iBean/ThresholdCell.m
+++ b/iBean/iBean/ThresholdCell.m
@@ -8,6 +8,7 @@
#import "ThresholdCell.h"
#import "Threshold.h"
+#import "AppDelegate+Storage.h"
@implementation ThresholdCell
@@ -53,7 +54,18 @@
if (self.threshold != nil)
{
self.threshold.enabled = [NSNumber numberWithBool:self.enabledSwitch.on];
-#warning TODO - Trigger save!?
+ NSError* error = [(AppDelegate*) [[UIApplication sharedApplication] delegate] save];
+ if (error != nil)
+ {
+ //Rollback
+ [(AppDelegate*) [[UIApplication sharedApplication] delegate] rollback];
+
+ UIAlertView *switchChangedSaveAlert = [[UIAlertView alloc] initWithTitle:@"Save error!" message:@"iBean was unable to save threshold state!\nPlease try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
+ [switchChangedSaveAlert show];
+
+ #warning TODO - Make sure that rollback resets the value back to previous one!!!!!
+ self.enabledSwitch.on = [self.threshold.enabled boolValue];
+ }
}
}
diff --git a/iBean/iBean/ThresholdListViewController.h b/iBean/iBean/ThresholdListViewController.h
index eb909d7..1ec6266 100644
--- a/iBean/iBean/ThresholdListViewController.h
+++ b/iBean/iBean/ThresholdListViewController.h
@@ -7,14 +7,23 @@
//
#import <UIKit/UIKit.h>
+@class Configuration;
@interface ThresholdListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
+@property (nonatomic, strong) Configuration* configuration;
+@property (nonatomic, strong) UIBarButtonItem *thresholdListEditDoneButton;
+
/* Utility methods */
- (void) initViewController;
+- (void) initWithConfiguration: (Configuration*) configuration;
/* UI Outlets */
+@property (weak, nonatomic) IBOutlet UITableView *thresholdListTableView;
+@property (weak, nonatomic) IBOutlet UIToolbar *thresholdListBottomToolbar;
+@property (strong, nonatomic) IBOutlet UIBarButtonItem *thresholdListEditButton;
/* UI Actions */
+- (IBAction)toggleEditMode:(id)sender;
@end
diff --git a/iBean/iBean/ThresholdListViewController.m b/iBean/iBean/ThresholdListViewController.m
index d6ce20e..57db263 100644
--- a/iBean/iBean/ThresholdListViewController.m
+++ b/iBean/iBean/ThresholdListViewController.m
@@ -7,6 +7,10 @@
//
#import "ThresholdListViewController.h"
+#import "ThresholdViewController.h"
+#import "Configuration+Interface.h"
+#import "ThresholdCell.h"
+#import "AppDelegate+Storage.h"
@interface ThresholdListViewController ()
@@ -29,21 +33,65 @@
// 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.
}
+- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+{
+ if ([segue.identifier isEqualToString:@"ThresholdsAddNewThresholdSegue"])
+ {
+ ThresholdViewController* thresholdViewController = segue.destinationViewController;
+ [thresholdViewController initWithConfigurationAndThresholdIndex:self.configuration : -1];
+ }
+ else if ([segue.identifier isEqualToString:@"ThresholdsEditThresholdSegue"])
+ {
+ ThresholdViewController* thresholdViewController = segue.destinationViewController;
+ [thresholdViewController initWithConfigurationAndThresholdIndex:self.configuration :self.thresholdListTableView.indexPathForSelectedRow.row];
+ }
+}
+
/*****************************************************
Utility methods
*****************************************************/
+- (void) initViewController
+{
+ NSLog(@"ThresholdListViewController - initViewController");
+ [self.thresholdListTableView reloadData];
+ self.thresholdListEditDoneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(toggleEditMode:)];
+}
+- (void) initWithConfiguration:(Configuration *)configuration
+{
+ self.configuration = configuration;
+}
/*****************************************************
UI Actions
*****************************************************/
-
+#pragma mark - IBActions
+- (void) toggleEditMode:(id)sender
+{
+ NSMutableArray *bottomToolbarItems = [NSMutableArray arrayWithArray:self.thresholdListBottomToolbar.items];
+ if (self.thresholdListTableView.editing)
+ {
+ [bottomToolbarItems replaceObjectAtIndex:0 withObject:self.thresholdListEditButton];
+ }
+ else
+ {
+ [bottomToolbarItems replaceObjectAtIndex:0 withObject:self.thresholdListEditDoneButton];
+ }
+ [self.thresholdListTableView setEditing:!self.thresholdListTableView.editing animated:YES];
+ [self.thresholdListBottomToolbar setItems:bottomToolbarItems animated:YES];
+}
/*****************************************************
Delegates
@@ -52,78 +100,98 @@
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
-#warning Potentially incomplete method implementation.
// Return the number of sections.
- return 0;
+ return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
-#warning Incomplete method implementation.
// Return the number of rows in the section.
- return 0;
+ return self.configuration.thresholds.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ThresholdCell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+ ThresholdCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
+ [cell initWithThresholdEntity:[self.configuration.thresholds objectAtIndex:indexPath.row]];
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
+// Override to support conditional editing of the table view.
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(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];
- */
+ // Return NO if you do not want the specified item to be editable (we want to be able to REMOVE though).
+ 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
+ if (self.configuration != nil)
+ {
+ [self.configuration removeObjectFromThresholdsAtIndex: indexPath.row];
+ }
+ [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
+
+ //Commit change!
+ if ([(AppDelegate*) [[UIApplication sharedApplication] delegate] save] != nil)
+ {
+ UIAlertView *deleteRowAlert = [[UIAlertView alloc] initWithTitle:@"Configuration error!" message:@"iBean was unable to delete threshold!\nPlease try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
+ [deleteRowAlert show];
+
+ //Rollback and reload table view
+ [(AppDelegate*) [[UIApplication sharedApplication] delegate] rollback];
+ [self.thresholdListTableView reloadData];
+ }
+
+ }
+ 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 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;
+}
+
+// Override to support rearranging the table view.
+//http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/tableview_iphone/ManageReorderRow/ManageReorderRow.html
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
+{
+ if (self.configuration != nil && fromIndexPath.row != toIndexPath.row)
+ {
+ NSLog(@"From: %d, To: %d", fromIndexPath.row, toIndexPath.row);
+ if (toIndexPath.row < (self.configuration.thresholds.count - 1))
+ {
+ NSMutableIndexSet *thresholdIndexes = [NSMutableIndexSet indexSetWithIndex:fromIndexPath.row];
+ [thresholdIndexes addIndex:toIndexPath.row];
+ NSArray *thresholds = [NSArray arrayWithObjects:[self.configuration.thresholds objectAtIndex:fromIndexPath.row], [self.configuration.thresholds objectAtIndex:toIndexPath.row], nil];
+ [self.configuration replaceThresholdsAtIndexes:thresholdIndexes withThresholds:thresholds];
+
+ //Commit change
+ if ([(AppDelegate*) [[UIApplication sharedApplication] delegate] save] != nil)
+ {
+ UIAlertView *deleteRowAlert = [[UIAlertView alloc] initWithTitle:@"Configuration error!" message:@"iBean was unable to move threshold!\nPlease try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
+ [deleteRowAlert show];
+
+ //Rollback and reload table view
+ [(AppDelegate*) [[UIApplication sharedApplication] delegate] rollback];
+ [self.thresholdListTableView reloadData];
+ }
+ }
+ }
+}
+
+
@end
diff --git a/iBean/iBean/ThresholdViewController.h b/iBean/iBean/ThresholdViewController.h
index dc63752..29d4874 100644
--- a/iBean/iBean/ThresholdViewController.h
+++ b/iBean/iBean/ThresholdViewController.h
@@ -7,14 +7,29 @@
//
#import <UIKit/UIKit.h>
+@class Threshold;
+@class Configuration;
-@interface ThresholdViewController : UITableViewController
+@interface ThresholdViewController : UITableViewController <UITextFieldDelegate>
+
+@property (nonatomic, assign) NSInteger thresholdObjectIndex;
+@property (nonatomic, strong) Configuration* configuration;
/* Utility methods */
- (void) initViewController;
+- (void) initWithConfigurationAndThresholdIndex: (Configuration*) configuration: (NSInteger) thresholdIndex;
/* UI Outlets */
+@property (weak, nonatomic) IBOutlet UITextField *thresholdNameTextField;
+@property (weak, nonatomic) IBOutlet UILabel *thresholdValueLabel;
+@property (weak, nonatomic) IBOutlet UIStepper *thresholdValueStepper;
+@property (weak, nonatomic) IBOutlet UISwitch *thresholdEnabledSwitch;
/* UI Actions */
+- (IBAction)valueStepperChanged:(id)sender;
+- (IBAction)commitThreshold:(id)sender;
+
+/* UITextFieldDelegate */
+- (BOOL)textFieldShouldReturn:(UITextField *)textField;
@end
diff --git a/iBean/iBean/ThresholdViewController.m b/iBean/iBean/ThresholdViewController.m
index 1769dfe..2e01373 100644
--- a/iBean/iBean/ThresholdViewController.m
+++ b/iBean/iBean/ThresholdViewController.m
@@ -6,7 +6,10 @@
// Copyright (c) 2013 Eddie Ehlin. All rights reserved.
//
+#import "AppDelegate+Storage.h"
#import "ThresholdViewController.h"
+#import "Threshold.h"
+#import "Configuration+Interface.h"
@interface ThresholdViewController ()
@@ -34,6 +37,12 @@
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
+- (void) viewWillAppear:(BOOL)animated
+{
+ [super viewWillAppear:animated];
+ [self initViewController];
+}
+
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
@@ -43,15 +52,89 @@
/*****************************************************
Utility methods
*****************************************************/
+- (void) initViewController
+{
+ NSLog(@"ThresholdViewController - initViewController");
+
+ if (self.thresholdObjectIndex >= 0 && self.thresholdObjectIndex <= self.configuration.thresholds.count)
+ {
+ //We are editing an existing threshold!
+ Threshold *tmpThreshold = [self.configuration.thresholds objectAtIndex:self.thresholdObjectIndex];
+ self.thresholdNameTextField.text = tmpThreshold.name;
+ self.thresholdEnabledSwitch.on = [tmpThreshold.enabled boolValue];
+ self.thresholdValueStepper.value = [tmpThreshold.value doubleValue];
+ [self valueStepperChanged:self];
+ }
+
+}
+- (void) initWithConfigurationAndThresholdIndex: (Configuration*) configuration: (NSInteger) thresholdIndex;
+{
+ self.configuration = configuration;
+ self.thresholdObjectIndex = thresholdIndex;
+}
/*****************************************************
UI Actions
*****************************************************/
+- (void) valueStepperChanged:(id)sender
+{
+ self.thresholdValueLabel.text = [[NSNumber numberWithDouble:self.thresholdValueStepper.value] stringValue];
+}
+
+- (void) commitThreshold:(id)sender
+{
+ Threshold* threshold = nil;
+ NSError* commitError = nil;
+ if (self.thresholdObjectIndex >= 0)
+ {
+ threshold = [self.configuration.thresholds objectAtIndex:self.thresholdObjectIndex];
+ }
+ else
+ {
+ threshold = [(AppDelegate*) [[UIApplication sharedApplication] delegate] createThreshold];
+ [self.configuration addThresholdsObject:threshold];
+ }
+
+ if (threshold != nil)
+ {
+ threshold.name = self.thresholdNameTextField.text;
+ threshold.value = [NSNumber numberWithDouble:self.thresholdValueStepper.value];
+ threshold.enabled = [NSNumber numberWithBool:self.thresholdEnabledSwitch.on];
+
+ //Commit changes and save succeeds then return to list of thresholds.
+ commitError = [(AppDelegate*) [[UIApplication sharedApplication] delegate] save];
+ }
+
+ if (threshold == nil || commitError != nil)
+ {
+ //Rollback & present error!
+ [(AppDelegate*) [[UIApplication sharedApplication] delegate] rollback];
+
+ UIAlertView *commitThresholdAlert = [[UIAlertView alloc] initWithTitle:@"Save error!" message:@"iBean was unable to save threshold!\nPlease try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
+ [commitThresholdAlert show];
+ }
+ else
+ {
+ [self.navigationController popViewControllerAnimated:YES];
+ }
+}
/*****************************************************
Delegates
*****************************************************/
+//Purpose: When "return" is pressed the keyboard will go away and "change" event will be triggered.
+- (BOOL)textFieldShouldReturn:(UITextField *)textField
+{
+ //Return key makes the keyboard go away.
+ if (textField == self.thresholdNameTextField)
+ {
+ [textField resignFirstResponder];
+ return YES;
+ }
+
+ return NO;
+}
@end
diff --git a/iBean/iBean/iPhoneStoryboard.storyboard b/iBean/iBean/iPhoneStoryboard.storyboard
index 683bc9f..cec0cd1 100644
--- a/iBean/iBean/iPhoneStoryboard.storyboard
+++ b/iBean/iBean/iPhoneStoryboard.storyboard
@@ -286,7 +286,7 @@
<constraint firstItem="8gp-G0-eVi" firstAttribute="top" secondItem="noJ-aA-kKf" secondAttribute="top" constant="11" id="RKe-IJ-EL2"/>
</constraints>
<connections>
- <segue destination="XZe-6y-tUN" kind="push" id="vNf-1Q-64U"/>
+ <segue destination="XZe-6y-tUN" kind="push" identifier="SettingsThresholdSegue" id="vNf-1Q-64U"/>
</connections>
</tableViewCell>
</cells>
@@ -371,7 +371,11 @@
</tableView>
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ixE-eI-jK9">
<items>
- <barButtonItem systemItem="edit" id="pfh-Br-yHh"/>
+ <barButtonItem systemItem="edit" id="pfh-Br-yHh">
+ <connections>
+ <action selector="toggleEditMode:" destination="XZe-6y-tUN" id="7ax-FO-rsP"/>
+ </connections>
+ </barButtonItem>
<barButtonItem style="plain" systemItem="flexibleSpace" id="QcW-iO-KPT"/>
<barButtonItem systemItem="add" id="Hw8-N9-QUf">
<connections>
@@ -393,6 +397,11 @@
</constraints>
</view>
<navigationItem key="navigationItem" title="Thresholds" id="g7z-WC-gGh"/>
+ <connections>
+ <outlet property="thresholdListBottomToolbar" destination="ixE-eI-jK9" id="ozU-hU-IYT"/>
+ <outlet property="thresholdListEditButton" destination="pfh-Br-yHh" id="pK0-WR-tae"/>
+ <outlet property="thresholdListTableView" destination="hI0-rM-L5l" id="1je-zh-DDw"/>
+ </connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="2Uy-KG-psE" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
@@ -416,13 +425,16 @@
<rect key="frame" x="10" y="1" width="300" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
- <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="nJO-Vo-PIR">
+ <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Descriptive name of threshold goes here" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="nJO-Vo-PIR">
<constraints>
- <constraint firstAttribute="width" constant="260" id="XOl-1f-qtC"/>
+ <constraint firstAttribute="width" constant="260" id="C3o-PY-diC"/>
<constraint firstAttribute="height" constant="30" id="nXA-Jn-d5M"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="done"/>
+ <connections>
+ <outlet property="delegate" destination="0Fo-5M-9Kc" id="XQI-QU-ohX"/>
+ </connections>
</textField>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
@@ -451,7 +463,7 @@
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="highlightedColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</label>
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Threshold value" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Dth-cf-hBc">
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="0" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Dth-cf-hBc">
<constraints>
<constraint firstAttribute="height" constant="21" id="C26-OZ-vR9"/>
</constraints>
@@ -459,7 +471,11 @@
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<color key="highlightedColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</label>
- <stepper opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" maximumValue="100" translatesAutoresizingMaskIntoConstraints="NO" id="FfU-8X-ael"/>
+ <stepper opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" maximumValue="1000000" translatesAutoresizingMaskIntoConstraints="NO" id="FfU-8X-ael">
+ <connections>
+ <action selector="valueStepperChanged:" destination="0Fo-5M-9Kc" eventType="valueChanged" id="VZF-S2-nBq"/>
+ </connections>
+ </stepper>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
@@ -505,8 +521,18 @@
</connections>
</tableView>
<navigationItem key="navigationItem" title="Threshold" id="Ozv-hq-I7e">
- <barButtonItem key="rightBarButtonItem" systemItem="save" id="cAv-1a-lwW"/>
+ <barButtonItem key="rightBarButtonItem" systemItem="save" id="cAv-1a-lwW">
+ <connections>
+ <action selector="commitThreshold:" destination="0Fo-5M-9Kc" id="4G9-19-uTP"/>
+ </connections>
+ </barButtonItem>
</navigationItem>
+ <connections>
+ <outlet property="thresholdEnabledSwitch" destination="sja-Le-4gL" id="KnO-wm-qa9"/>
+ <outlet property="thresholdNameTextField" destination="nJO-Vo-PIR" id="N4U-un-QTr"/>
+ <outlet property="thresholdValueLabel" destination="Dth-cf-hBc" id="T0F-ci-Xqi"/>
+ <outlet property="thresholdValueStepper" destination="FfU-8X-ael" id="tbI-6k-Ic6"/>
+ </connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x2h-49-oUN" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
@@ -1013,7 +1039,7 @@
</constraints>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" indentationWidth="10" reuseIdentifier="BeanCell" rowHeight="60" id="GFY-k6-GqL" customClass="BeanCell">
- <rect key="frame" x="0.0" y="46" width="320" height="61"/>
+ <rect key="frame" x="0.0" y="46" width="320" height="62"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="10" y="1" width="300" height="59"/>
@@ -1287,6 +1313,7 @@
<class className="ThresholdCell" superclassName="UITableViewCell">
<source key="sourceIdentifier" type="project" relativePath="./Classes/ThresholdCell.h"/>
<relationships>
+ <relationship kind="action" name="switchChanged:"/>
<relationship kind="outlet" name="enabledSwitch" candidateClass="UISwitch"/>
<relationship kind="outlet" name="nameLabel" candidateClass="UILabel"/>
<relationship kind="outlet" name="valueLabel" candidateClass="UILabel"/>
@@ -1294,9 +1321,23 @@
</class>
<class className="ThresholdListViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/ThresholdListViewController.h"/>
+ <relationships>
+ <relationship kind="action" name="toggleEditMode:"/>
+ <relationship kind="outlet" name="thresholdListBottomToolbar" candidateClass="UIToolbar"/>
+ <relationship kind="outlet" name="thresholdListEditButton" candidateClass="UIBarButtonItem"/>
+ <relationship kind="outlet" name="thresholdListTableView" candidateClass="UITableView"/>
+ </relationships>
</class>
<class className="ThresholdViewController" superclassName="UITableViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/ThresholdViewController.h"/>
+ <relationships>
+ <relationship kind="action" name="commitThreshold:"/>
+ <relationship kind="action" name="valueStepperChanged:"/>
+ <relationship kind="outlet" name="thresholdEnabledSwitch" candidateClass="UISwitch"/>
+ <relationship kind="outlet" name="thresholdNameTextField" candidateClass="UITextField"/>
+ <relationship kind="outlet" name="thresholdValueLabel" candidateClass="UILabel"/>
+ <relationship kind="outlet" name="thresholdValueStepper" candidateClass="UIStepper"/>
+ </relationships>
</class>
</classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
@@ -1305,8 +1346,8 @@
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
<inferredMetricsTieBreakers>
- <segue reference="EsA-2d-QNt"/>
- <segue reference="CyX-df-8ge"/>
<segue reference="utz-eo-nc3"/>
+ <segue reference="CyX-df-8ge"/>
+ <segue reference="qk2-F5-M1s"/>
</inferredMetricsTieBreakers>
</document> \ No newline at end of file