summaryrefslogtreecommitdiff
path: root/Volta
diff options
context:
space:
mode:
Diffstat (limited to 'Volta')
-rw-r--r--Volta/Controls/VoltaReadOnlyTextField.h13
-rw-r--r--Volta/Controls/VoltaReadOnlyTextField.m19
-rw-r--r--Volta/Views/StatsTabBarController.h2
-rw-r--r--Volta/Views/StatsTabBarController.m30
-rw-r--r--Volta/Views/StatsViewController.m125
-rw-r--r--Volta/Volta-Prefix.pch2
-rw-r--r--Volta/en.lproj/MainStoryboard.storyboard12
7 files changed, 191 insertions, 12 deletions
diff --git a/Volta/Controls/VoltaReadOnlyTextField.h b/Volta/Controls/VoltaReadOnlyTextField.h
new file mode 100644
index 0000000..8ad8f96
--- /dev/null
+++ b/Volta/Controls/VoltaReadOnlyTextField.h
@@ -0,0 +1,13 @@
+//
+// VoltaReadOnlyTextField.h
+// Volta
+//
+// Created by Ronny Fenrich on 2013-06-14.
+// Copyright (c) 2013 Decoder. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface VoltaReadOnlyTextField : UITextField
+
+@end
diff --git a/Volta/Controls/VoltaReadOnlyTextField.m b/Volta/Controls/VoltaReadOnlyTextField.m
new file mode 100644
index 0000000..e1af6de
--- /dev/null
+++ b/Volta/Controls/VoltaReadOnlyTextField.m
@@ -0,0 +1,19 @@
+//
+// VoltaReadOnlyTextField.m
+// Volta
+//
+// Created by Ronny Fenrich on 2013-06-14.
+// Copyright (c) 2013 Decoder. All rights reserved.
+//
+
+#import "VoltaReadOnlyTextField.h"
+
+@implementation VoltaReadOnlyTextField
+
+
+- (CGRect)caretRectForPosition:(UITextPosition *)position
+{
+ return CGRectZero;
+}
+
+@end
diff --git a/Volta/Views/StatsTabBarController.h b/Volta/Views/StatsTabBarController.h
index 7bfb622..6a265e6 100644
--- a/Volta/Views/StatsTabBarController.h
+++ b/Volta/Views/StatsTabBarController.h
@@ -13,5 +13,7 @@
@interface StatsTabBarController : UITabBarController
@property (strong, nonatomic) MGOrderedDictionary *data; // VoltaReading objects
+@property (strong, nonatomic) NSDate *startDate;
+@property (strong, nonatomic) NSDate *endDate;
@end
diff --git a/Volta/Views/StatsTabBarController.m b/Volta/Views/StatsTabBarController.m
index cce66bb..8e53591 100644
--- a/Volta/Views/StatsTabBarController.m
+++ b/Volta/Views/StatsTabBarController.m
@@ -12,6 +12,8 @@
@interface StatsTabBarController ()
+@property (strong, nonatomic) NSDateFormatter *dateFormatter;
+
@end
@implementation StatsTabBarController
@@ -26,6 +28,20 @@
}
+- (NSDateFormatter *)dateFormatter
+{
+ if (!_dateFormatter)
+ {
+ _dateFormatter = [[NSDateFormatter alloc] init];
+ [_dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
+ NSCalendar* calendar = [NSCalendar currentCalendar];
+ [calendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
+ [_dateFormatter setCalendar:calendar];
+ }
+ return _dateFormatter;
+}
+
+
// --------------------------------------------------------------------------------------
- (void)updateData
{
@@ -38,13 +54,14 @@
[httpClient setDefaultHeader:@"Accept" value:@"application/json"];
[httpClient setParameterEncoding:AFJSONParameterEncoding];
- // NSString *startDate = [self.queryDateFormatter stringFromDate:[NSDate date]];
+ NSString *startDateUTC = [self.dateFormatter stringFromDate:self.startDate];
+ NSString *endDateUTC = [self.dateFormatter stringFromDate:self.endDate];
NSError *error;
NSString *token = [SSKeychain passwordForService:KEYCHAIN_API_TOKEN account:KEYCHAIN_ACCOUNT error:&error];
NSMutableURLRequest *request;
- request = [httpClient requestWithMethod:@"GET" path:[NSString stringWithFormat:URL_READINGS, token] parameters:nil];
+ request = [httpClient requestWithMethod:@"GET" path:[NSString stringWithFormat:URL_READINGS, token, startDateUTC, endDateUTC] parameters:nil];
NSLog(@"GET: %@", request);
@@ -55,14 +72,15 @@
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
NSLog(@"%@", JSON);
+ if (!self.data)
+ {
+ self.data = [[MGOrderedDictionary alloc] init];
+ }
+
for (NSDictionary *data in JSON)
{
VoltaReading *aReading = [VoltaReading initFromJSON:data];
NSString *dictKey = aReading.dictionaryKey;
- if (!self.data)
- {
- self.data = [[MGOrderedDictionary alloc] init];
- }
// we now group data by day (calc totals for days usage and cost)
if (![self.data objectForKey:dictKey])
diff --git a/Volta/Views/StatsViewController.m b/Volta/Views/StatsViewController.m
index deb6a19..ed25ab9 100644
--- a/Volta/Views/StatsViewController.m
+++ b/Volta/Views/StatsViewController.m
@@ -7,6 +7,7 @@
//
#import "StatsViewController.h"
+#import "StatsTabBarController.h"
@interface StatsViewController ()<UITextFieldDelegate>
@@ -16,6 +17,10 @@
@property (strong, nonatomic) UIDatePicker *startDatePicker;
@property (strong, nonatomic) UIDatePicker *endDatePicker;
+
+@property (strong, nonatomic) NSDate *currentStartDate;
+@property (strong, nonatomic) NSDate *currentEndDate;
+
@end
@implementation StatsViewController
@@ -43,19 +48,24 @@
[self.startDatePicker setDatePickerMode:UIDatePickerModeDate];
[self.startDatePicker addTarget:self action:@selector(startDatePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
self.startDate.inputView = self.startDatePicker;
+ NSDate *startDateValue = [NSDate dateWithTimeIntervalSince1970:1325448000]; // 1.1.2012
+ [self.startDatePicker setDate:startDateValue];
+ [self startDatePickerValueChanged:nil];
self.endDatePicker = [[UIDatePicker alloc] init];
[self.endDatePicker setDatePickerMode:UIDatePickerModeDate];
[self.endDatePicker addTarget:self action:@selector(endDatePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
self.endDate.inputView = self.endDatePicker;
-
+ NSDate *endDateValue = [NSDate date];
+ [self.endDatePicker setDate:endDateValue];
+ [self endDatePickerValueChanged:nil];
}
- (void)startDatePickerValueChanged:(id)sender
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateStyle:NSDateFormatterShortStyle];
+ [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
self.startDate.text = [dateFormatter stringFromDate:[self.startDatePicker date]];
}
@@ -138,30 +148,139 @@
- (IBAction)statsCurrentMonth:(id)sender
{
- [self showStatsForStartDate:[NSDate date] endDate:[NSDate date]];
+ NSDate *curDate = [NSDate date];
+ NSCalendar* calendar = [NSCalendar currentCalendar];
+ NSDateComponents* comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:curDate];
+
+ // First of month
+ [comps setDay:1];
+ NSDate *startDate = [calendar dateFromComponents:comps];
+
+ // Last of month
+ [comps setMonth:[comps month]+1];
+ [comps setDay:0];
+ [comps setHour:23];
+ [comps setMinute:59];
+ [comps setSecond:59];
+ NSDate *endDate = [calendar dateFromComponents:comps];
+
+ [self showStatsForStartDate:startDate endDate:endDate];
}
- (IBAction)statsLast30days:(id)sender
{
+ NSDate *curDate = [NSDate date];
+ NSCalendar* calendar = [NSCalendar currentCalendar];
+ NSDateComponents* comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:curDate];
+
+ // End of today
+ [comps setHour:23];
+ [comps setMinute:59];
+ [comps setSecond:59];
+ NSDate *endDate = [calendar dateFromComponents:comps];
+
+ // today - 30 days
+ NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
+ [offsetComponents setDay:-30];
+ NSDate *startDate = [calendar dateByAddingComponents:offsetComponents toDate:curDate options:0];
+ comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:startDate];
+ [comps setHour:0];
+ [comps setMinute:0];
+ [comps setSecond:0];
+ NSDate *newStartDate = [calendar dateFromComponents:comps];
+
+ [self showStatsForStartDate:newStartDate endDate:endDate];
}
- (IBAction)statsLast60days:(id)sender
{
+ NSDate *curDate = [NSDate date];
+ NSCalendar* calendar = [NSCalendar currentCalendar];
+ NSDateComponents* comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:curDate];
+
+ // End of today
+ [comps setHour:23];
+ [comps setMinute:59];
+ [comps setSecond:59];
+ NSDate *endDate = [calendar dateFromComponents:comps];
+
+ // today - 60 days
+ NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
+ [offsetComponents setDay:-60];
+ NSDate *startDate = [calendar dateByAddingComponents:offsetComponents toDate:curDate options:0];
+ comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:startDate];
+ [comps setHour:0];
+ [comps setMinute:0];
+ [comps setSecond:0];
+ NSDate *newStartDate = [calendar dateFromComponents:comps];
+
+ [self showStatsForStartDate:newStartDate endDate:endDate];
}
- (IBAction)statsCurrentYear:(id)sender
{
+ NSDate *curDate = [NSDate date];
+ NSCalendar* calendar = [NSCalendar currentCalendar];
+ NSDateComponents* comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:curDate];
+
+ // January 1st
+ [comps setDay:1];
+ [comps setMonth:1];
+ [comps setHour:0];
+ [comps setMinute:0];
+ [comps setSecond:0];
+ NSDate *startDate = [calendar dateFromComponents:comps];
+
+ // Last of month
+ [comps setMonth:12];
+ [comps setDay:31];
+ [comps setHour:23];
+ [comps setMinute:59];
+ [comps setSecond:59];
+ NSDate *endDate = [calendar dateFromComponents:comps];
+
+ [self showStatsForStartDate:startDate endDate:endDate];
}
- (IBAction)statsStartdateEnddate:(id)sender
{
+ [self dismissKeyboard];
+
+ NSCalendar* calendar = [NSCalendar currentCalendar];
+ NSDateComponents* comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:self.startDatePicker.date];
+
+ [comps setHour:0];
+ [comps setMinute:0];
+ [comps setSecond:0];
+ NSDate *startDate = [calendar dateFromComponents:comps];
+
+ comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:self.endDatePicker.date];
+ [comps setHour:23];
+ [comps setMinute:59];
+ [comps setSecond:59];
+ NSDate *endDate = [calendar dateFromComponents:comps];
+
+ [self showStatsForStartDate:startDate endDate:endDate];
}
- (void)showStatsForStartDate:(NSDate *)startDate endDate:(NSDate *)endDate
{
+ self.currentStartDate = startDate;
+ self.currentEndDate = endDate;
[self performSegueWithIdentifier:@"ShowStatisticsSegue" sender:self];
}
+- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+{
+ if ([segue.identifier isEqualToString:@"ShowStatisticsSegue"])
+ {
+ StatsTabBarController *destController = (StatsTabBarController *)segue.destinationViewController;
+ destController.startDate = self.currentStartDate;
+ destController.endDate = self.currentEndDate;
+ }
+}
+
+
@end
diff --git a/Volta/Volta-Prefix.pch b/Volta/Volta-Prefix.pch
index 0ec9e05..bebd7dd 100644
--- a/Volta/Volta-Prefix.pch
+++ b/Volta/Volta-Prefix.pch
@@ -38,7 +38,7 @@
//#define URL_LOGOUT @"/logout"
#define URL_TOKEN @"?auth_token=%@"
-#define URL_READINGS [@"/api/v1/readings" stringByAppendingString:URL_TOKEN]
+#define URL_READINGS [[@"/api/v1/readings" stringByAppendingString:URL_TOKEN] stringByAppendingString:@"&start_date=%@&end_date=%@"]
//#define URL_UPDATE_USER [@"/api/users/%d" stringByAppendingString:URL_TOKEN]
diff --git a/Volta/en.lproj/MainStoryboard.storyboard b/Volta/en.lproj/MainStoryboard.storyboard
index 5c4c898..26c51a7 100644
--- a/Volta/en.lproj/MainStoryboard.storyboard
+++ b/Volta/en.lproj/MainStoryboard.storyboard
@@ -230,7 +230,7 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="256"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
- <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Start Date" minimumFontSize="17" id="FTW-dx-T0r">
+ <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Start Date" minimumFontSize="17" id="FTW-dx-T0r" customClass="VoltaReadOnlyTextField">
<rect key="frame" x="72" y="185" width="120" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
@@ -304,7 +304,7 @@
<action selector="statsLast30days:" destination="lv2-8L-bY1" eventType="touchUpInside" id="A8M-3A-eP8"/>
</connections>
</button>
- <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="End Date" minimumFontSize="17" id="7zh-ce-be2">
+ <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="End Date" minimumFontSize="17" id="7zh-ce-be2" customClass="VoltaReadOnlyTextField">
<rect key="frame" x="232" y="185" width="120" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
@@ -421,6 +421,7 @@
<class className="LoginViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/LoginViewController.h"/>
<relationships>
+ <relationship kind="action" name="backgroundTapped:"/>
<relationship kind="outlet" name="contentView" candidateClass="UIView"/>
<relationship kind="outlet" name="email" candidateClass="UITextField"/>
<relationship kind="outlet" name="logo" candidateClass="UIImageView"/>
@@ -433,8 +434,12 @@
<class className="StatsViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/StatsViewController.h"/>
<relationships>
+ <relationship kind="action" name="backgroundTapped:"/>
+ <relationship kind="action" name="statsCurrentMonth:"/>
+ <relationship kind="action" name="statsCurrentYear:"/>
<relationship kind="action" name="statsLast30days:"/>
<relationship kind="action" name="statsLast60days:"/>
+ <relationship kind="action" name="statsStartdateEnddate:"/>
<relationship kind="outlet" name="content" candidateClass="UIScrollView"/>
<relationship kind="outlet" name="endDate" candidateClass="UITextField"/>
<relationship kind="outlet" name="startDate" candidateClass="UITextField"/>
@@ -443,6 +448,9 @@
<class className="VoltaButton" superclassName="UIButton">
<source key="sourceIdentifier" type="project" relativePath="./Classes/VoltaButton.h"/>
</class>
+ <class className="VoltaReadOnlyTextField" superclassName="UITextField">
+ <source key="sourceIdentifier" type="project" relativePath="./Classes/VoltaReadOnlyTextField.h"/>
+ </class>
</classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>