aboutsummaryrefslogtreecommitdiffstats
path: root/iBean/iBean
diff options
context:
space:
mode:
authorEddie Ehlin <eddiex@eddiex.se>2013-02-02 16:57:43 +0100
committerEddie Ehlin <eddiex@eddiex.se>2013-02-02 16:57:43 +0100
commit084457c9420cfc1e6677cb33434afcc64366229f (patch)
treea9864bc9586554619c17b005ff3a8956978965b5 /iBean/iBean
parent30d48ecfeac942473a4b08de2ac37816793984b0 (diff)
downloadiBean-084457c9420cfc1e6677cb33434afcc64366229f.tar.gz
iBean-084457c9420cfc1e6677cb33434afcc64366229f.zip
Thresholds will be processed upon every change of extraction count, and they will be presented in a ordered manner (value).
Diffstat (limited to 'iBean/iBean')
-rw-r--r--iBean/iBean/AppDelegate+Storage.h3
-rw-r--r--iBean/iBean/AppDelegate+Storage.m79
-rw-r--r--iBean/iBean/AppDelegate.h1
-rw-r--r--iBean/iBean/EditBeanViewController.h2
-rw-r--r--iBean/iBean/SettingsViewController.m8
-rw-r--r--iBean/iBean/ThresholdListViewController.m35
6 files changed, 82 insertions, 46 deletions
diff --git a/iBean/iBean/AppDelegate+Storage.h b/iBean/iBean/AppDelegate+Storage.h
index f668396..abaef29 100644
--- a/iBean/iBean/AppDelegate+Storage.h
+++ b/iBean/iBean/AppDelegate+Storage.h
@@ -17,7 +17,7 @@
methods etc. in one area. Just to keep it clean.
*/
-@interface AppDelegate (Storage)
+@interface AppDelegate (Storage) <UIAlertViewDelegate>
#pragma mark - Common storage related methods
- (NSError*) save;
@@ -36,6 +36,7 @@
//Thresholds methods
- (void) processThresholds;
+- (void) processActiveThreshold;
- (Threshold*) createThreshold;
diff --git a/iBean/iBean/AppDelegate+Storage.m b/iBean/iBean/AppDelegate+Storage.m
index fe62969..8448f3e 100644
--- a/iBean/iBean/AppDelegate+Storage.m
+++ b/iBean/iBean/AppDelegate+Storage.m
@@ -9,6 +9,7 @@
#import "AppDelegate+Storage.h"
#import "Configuration+Interface.h"
#import "BeanCollection.h"
+#include "Threshold.h"
@implementation AppDelegate (Storage)
@@ -130,6 +131,10 @@
cancelButtonTitle:@"OK" otherButtonTitles: nil];
[setExtractionCountAlert show];
}
+ else
+ {
+ [self processThresholds];
+ }
}
return error;
@@ -143,9 +148,8 @@
{
if ([c.countExtractions boolValue] == YES)
{
- if ([self setExtractionCount:[NSNumber numberWithInteger:([c.extractionCount integerValue] + 1)]] != nil)
+ if ([self setExtractionCount:[NSNumber numberWithInteger:([c.extractionCount integerValue] + 1)]] == nil)
{
- [self processThresholds];
return c.extractionCount;
}
}
@@ -155,9 +159,65 @@
- (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.
+ //First out, lets sort the thresholds
+ Configuration *configuration = [self getConfiguration];
+
+ if (configuration != nil)
+ {
+ if ([configuration.useThresholds boolValue] == YES)
+ {
+ self.activeThresholdsToProcess = [[NSMutableArray alloc] init];
+ NSArray *sortedThresholds = [configuration.thresholds sortedArrayUsingComparator:
+ ^NSComparisonResult(id obj1, id obj2)
+ {
+ Threshold* t1 = obj1;
+ Threshold* t2 = obj2;
+
+ if ([[t1 value] integerValue] > [[t2 value] integerValue])
+ {
+ return (NSComparisonResult)NSOrderedDescending;
+ }
+
+ if ([[t1 value] integerValue] < [[t2 value] integerValue])
+ {
+ return (NSComparisonResult)NSOrderedAscending;
+ }
+
+ return (NSComparisonResult)NSOrderedSame;
+ }];
+
+ //Time to go through all thresholds and se which one(s) that are hit!
+ for (Threshold *t in sortedThresholds)
+ {
+ if ([configuration.extractionCount integerValue] >= [t.value integerValue] && [t.enabled boolValue] == YES)
+ {
+ NSLog(@"Threshold %@ active (%@ >= %@)", t.name, configuration.extractionCount, t.value);
+ [self.activeThresholdsToProcess addObject:t];
+ }
+ }
+
+ //Now, let's go through all active thresholds.
+ [self processActiveThreshold];
+ }
+ }
+}
+
+- (void) processActiveThreshold
+{
+ if (self.activeThresholdsToProcess != nil)
+ {
+ if (self.activeThresholdsToProcess.count > 0)
+ {
+ Threshold *t = [self.activeThresholdsToProcess objectAtIndex:0];
+ [self.activeThresholdsToProcess removeObject:t];
+ UIAlertView *thresholdAlert = [[UIAlertView alloc] initWithTitle:@"Threshold reached!" message:t.name delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
+ [thresholdAlert show];
+ }
+ else
+ {
+ self.activeThresholdsToProcess = nil;
+ }
+ }
}
- (Threshold*) createThreshold
@@ -317,7 +377,14 @@
}
}
-
+#pragma mark - UIAlertView delegate
+- (void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
+{
+ if (self.activeThresholdsToProcess != nil)
+ {
+ [self processActiveThreshold];
+ }
+}
@end
diff --git a/iBean/iBean/AppDelegate.h b/iBean/iBean/AppDelegate.h
index b09db3e..b2f867d 100644
--- a/iBean/iBean/AppDelegate.h
+++ b/iBean/iBean/AppDelegate.h
@@ -14,6 +14,7 @@
@property (nonatomic, strong) id timerCallbackTarget;
@property (nonatomic, strong) NSTimer *timer;
+@property (nonatomic, strong) NSMutableArray* activeThresholdsToProcess;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
diff --git a/iBean/iBean/EditBeanViewController.h b/iBean/iBean/EditBeanViewController.h
index 7d0d8fd..83d7ac9 100644
--- a/iBean/iBean/EditBeanViewController.h
+++ b/iBean/iBean/EditBeanViewController.h
@@ -14,7 +14,7 @@
@property (nonatomic, assign) NSUInteger editBeanIndex;
/* Utility methods */
-- (void) initWithModeAndBeanCollectionAndBeanIndex:(BOOL)editMode: (BeanCollection*) bc: (NSUInteger) beanIndex;
+- (void) initWithModeAndBeanCollectionAndBeanIndex:(BOOL)editMode: (BeanCollection*)bc: (NSUInteger) beanIndex;
- (void) initViewController;
/* UI Outlets */
diff --git a/iBean/iBean/SettingsViewController.m b/iBean/iBean/SettingsViewController.m
index 242bee1..4b8f723 100644
--- a/iBean/iBean/SettingsViewController.m
+++ b/iBean/iBean/SettingsViewController.m
@@ -127,10 +127,8 @@
{
if (self.configuration != nil)
{
- self.configuration.extractionCount = [NSNumber numberWithDouble:self.extractionCountStepper.value];
-
+ NSError *error = [(AppDelegate*) [[UIApplication sharedApplication] delegate] setExtractionCount:[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]
@@ -140,6 +138,10 @@
cancelButtonTitle:@"OK" otherButtonTitles: nil];
[setExtractionCountAlert show];
}
+ else
+ {
+ self.extractionCountLabel.text = [self.configuration.extractionCount stringValue];
+ }
}
}
diff --git a/iBean/iBean/ThresholdListViewController.m b/iBean/iBean/ThresholdListViewController.m
index 57db263..18f087a 100644
--- a/iBean/iBean/ThresholdListViewController.m
+++ b/iBean/iBean/ThresholdListViewController.m
@@ -158,40 +158,5 @@
}
}
-// 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