summaryrefslogtreecommitdiff
path: root/Volta/Views/DataTableViewController.m
diff options
context:
space:
mode:
authorRonny Fenrich <Fenrich@Gmail.com>2013-06-14 11:42:17 -0600
committerRonny Fenrich <Fenrich@Gmail.com>2013-06-14 11:42:17 -0600
commitc721c485f56cc2034f499a61c02117f31cc73da4 (patch)
tree1989be521806bc34591f8ecc7ea2993c5f6afe93 /Volta/Views/DataTableViewController.m
parent0d40c8c8a1850559a9204b717585ba42ad4f2e9f (diff)
Finished Table view display of usage data
Diffstat (limited to 'Volta/Views/DataTableViewController.m')
-rw-r--r--Volta/Views/DataTableViewController.m105
1 files changed, 105 insertions, 0 deletions
diff --git a/Volta/Views/DataTableViewController.m b/Volta/Views/DataTableViewController.m
new file mode 100644
index 0000000..15667f3
--- /dev/null
+++ b/Volta/Views/DataTableViewController.m
@@ -0,0 +1,105 @@
+//
+// DataTableViewController.m
+// Volta
+//
+// Created by Ronny Fenrich on 2013-06-14.
+// Copyright (c) 2013 Decoder. All rights reserved.
+//
+
+#import "DataTableViewController.h"
+#import "VoltaReading.h"
+#import "MGOrderedDictionary.h"
+#import "StatsTabBarController.h"
+
+@interface DataTableViewController ()
+
+@property (strong, nonatomic) MGOrderedDictionary *data; // VoltaReading objects
+
+
+@end
+
+@implementation DataTableViewController
+
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(updatedDataNotification)
+ name:NOTIFICATION_UPDATED_STATS_DATA
+ object:nil];
+
+}
+
+- (void)updatedDataNotification
+{
+ [self.tableView reloadData];
+}
+
+- (MGOrderedDictionary *)data
+{
+ // get data from parent tabbar controller
+ StatsTabBarController *parentTabBarController = (StatsTabBarController *)self.parentViewController;
+ return parentTabBarController.data;
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+ return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ if (!self.data)
+ {
+ return 1; // Loading
+ }
+ else if (self.data.allKeys.count == 0)
+ {
+ return 1; // no data
+ }
+ else
+ {
+ return self.data.allKeys.count;
+ }
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ if (!self.data)
+ {
+ // still loading data
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LoadingCell"];
+ return cell;
+ }
+ else if (self.data.count == 0)
+ {
+ // no results
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NoResultsCell"];
+ return cell;
+ }
+
+ // Configure the data cell...
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReadingCell"];
+
+ NSString *dataKey = [self.data.allKeys objectAtIndex:indexPath.row];
+ VoltaReading *reading = [self.data objectForKey:dataKey];
+
+ UILabel *dateLabel = (UILabel *)[cell viewWithTag:1];
+ dateLabel.text = dataKey;
+ UILabel *kWhLabel = (UILabel *)[cell viewWithTag:2];
+ float kWh = reading.usage / 1000.0f;
+ kWhLabel.text = [NSString stringWithFormat:@"%.2f kWh", kWh];
+ UILabel *costLabel = (UILabel *)[cell viewWithTag:3];
+ float cost = reading.cost / 100000.0f;
+ costLabel.text = [NSString stringWithFormat:@"%.2f $", cost];
+
+ return cell;
+}
+
+
+
+@end