Skip to content

Commit

Permalink
History Detail
Browse files Browse the repository at this point in the history
  • Loading branch information
awmwong committed Jul 28, 2013
1 parent 51d4904 commit e38d40c
Show file tree
Hide file tree
Showing 7 changed files with 700 additions and 0 deletions.
10 changes: 10 additions & 0 deletions covrme.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
92BCAA0F17A4DBA8002AD070 /* SVProgressHUD.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 92BCAA0C17A4DBA8002AD070 /* SVProgressHUD.bundle */; };
92BCAA1017A4DBA8002AD070 /* SVProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = 92BCAA0E17A4DBA8002AD070 /* SVProgressHUD.m */; };
92BCAA1217A4DD18002AD070 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92BCAA1117A4DD17002AD070 /* QuartzCore.framework */; };
92BCAA1617A4DE16002AD070 /* CMHistoryDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 92BCAA1417A4DE16002AD070 /* CMHistoryDetailViewController.m */; };
92BCAA1717A4DE16002AD070 /* CMHistoryDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 92BCAA1517A4DE16002AD070 /* CMHistoryDetailViewController.xib */; };
92C6313E1785E149000069AF /* CMRegistrationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 92C6313D1785E149000069AF /* CMRegistrationViewController.m */; };
92D6054E17A4B9B4008A9C7C /* CMTonesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 92D6054C17A4B9B4008A9C7C /* CMTonesViewController.m */; };
92D6054F17A4B9B4008A9C7C /* CMTonesViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 92D6054D17A4B9B4008A9C7C /* CMTonesViewController.xib */; };
Expand Down Expand Up @@ -246,6 +248,9 @@
92BCAA0D17A4DBA8002AD070 /* SVProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVProgressHUD.h; sourceTree = "<group>"; };
92BCAA0E17A4DBA8002AD070 /* SVProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVProgressHUD.m; sourceTree = "<group>"; };
92BCAA1117A4DD17002AD070 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
92BCAA1317A4DE16002AD070 /* CMHistoryDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CMHistoryDetailViewController.h; sourceTree = "<group>"; };
92BCAA1417A4DE16002AD070 /* CMHistoryDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CMHistoryDetailViewController.m; sourceTree = "<group>"; };
92BCAA1517A4DE16002AD070 /* CMHistoryDetailViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = CMHistoryDetailViewController.xib; path = Source/CMHistoryDetailViewController.xib; sourceTree = "<group>"; };
92C6313C1785E149000069AF /* CMRegistrationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CMRegistrationViewController.h; sourceTree = "<group>"; };
92C6313D1785E149000069AF /* CMRegistrationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CMRegistrationViewController.m; sourceTree = "<group>"; };
92D6054B17A4B9B4008A9C7C /* CMTonesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CMTonesViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -623,6 +628,7 @@
92F5FE1117A48919002EF496 /* CMDoorbellManagementViewController.xib */,
92E8C4BD17715CBD00B06215 /* CMFrontDoorViewController.xib */,
92E8C4B317715B2D00B06215 /* CMHistoryListViewController.xib */,
92BCAA1517A4DE16002AD070 /* CMHistoryDetailViewController.xib */,
92F43E911780E85800B627CB /* CMRegistrationViewController.xib */,
92E8C4B817715C5500B06215 /* CMSettingsViewController.xib */,
92D6054D17A4B9B4008A9C7C /* CMTonesViewController.xib */,
Expand Down Expand Up @@ -1105,6 +1111,8 @@
children = (
92E8C4B117715B2D00B06215 /* CMHistoryListViewController.h */,
92E8C4B217715B2D00B06215 /* CMHistoryListViewController.m */,
92BCAA1317A4DE16002AD070 /* CMHistoryDetailViewController.h */,
92BCAA1417A4DE16002AD070 /* CMHistoryDetailViewController.m */,
);
name = History;
sourceTree = "<group>";
Expand Down Expand Up @@ -1239,6 +1247,7 @@
92F5FE1E17A4B6BB002EF496 /* knock.wav in Resources */,
92D6054F17A4B9B4008A9C7C /* CMTonesViewController.xib in Resources */,
92BCAA0F17A4DBA8002AD070 /* SVProgressHUD.bundle in Resources */,
92BCAA1717A4DE16002AD070 /* CMHistoryDetailViewController.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1327,6 +1336,7 @@
92F5FE1C17A494BE002EF496 /* CMDoorbell.m in Sources */,
92D6054E17A4B9B4008A9C7C /* CMTonesViewController.m in Sources */,
92BCAA1017A4DBA8002AD070 /* SVProgressHUD.m in Sources */,
92BCAA1617A4DE16002AD070 /* CMHistoryDetailViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
5 changes: 5 additions & 0 deletions covrme/Source/CMAPIClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ typedef void(^CMAPIClientCompletionBlock)();
success:(CMAPIClientSuccessBlock)success
failure:(CMAPIClientFailureBlock)failure;

- (void)getHistoryDetailWithDoorbellID:(NSString *)doorbellID
visitorID:(NSString *)visitorID
success:(CMAPIClientSuccessBlock)success
failure:(CMAPIClientFailureBlock)failure;

- (void)getNewDoorPictureWithParameters:(NSDictionary *)params
success:(CMAPIClientSuccessBlock)success
failure:(CMAPIClientFailureBlock)failure;
Expand Down
24 changes: 24 additions & 0 deletions covrme/Source/CMAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,30 @@ - (void)getHistoryWithDoorbellID:(NSString *)ID
}];
}

- (void)getHistoryDetailWithDoorbellID:(NSString *)doorbellID
visitorID:(NSString *)visitorID
success:(CMAPIClientSuccessBlock)success
failure:(CMAPIClientFailureBlock)failure
{

if (![self token] || ![self token].length) {
return;
}

NSDictionary *params = @{@"authtoken": [self token]};

NSString *path = [NSString stringWithFormat:@"doorbells/%@/visitors/%@", doorbellID, visitorID];

[self getPath:path
parameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject) {
success(operation, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
failure(operation.response, error);
}];
}


- (void)sendMessageToDoorbellID:(NSString *)doorbellID
withVisitorID:(NSString *)visitorID
withMessage:(NSString *)message
Expand Down
26 changes: 26 additions & 0 deletions covrme/Source/CMHistoryDetailViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// CMHistoryDetailViewController.h
// covrme
//
// Created by Anthony Wong on 2013-07-28.
//
//

#import <UIKit/UIKit.h>

@interface CMHistoryDetailViewController : UIViewController

@property (nonatomic, copy) NSString *doorbellID;
@property (nonatomic, copy) NSString *visitorID;

@property (nonatomic, copy) NSString *dateString;
@property (nonatomic, copy) NSString *timeString;
@property (nonatomic, copy) NSString *typeString;
@property (nonatomic, copy) NSString *statusString;

@property (weak, nonatomic) IBOutlet UIImageView *headerImageView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

- (id)initWithDoorbellID:(NSString *)doorbellID visitorID:(NSString *)visitorID;

@end
147 changes: 147 additions & 0 deletions covrme/Source/CMHistoryDetailViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
//
// CMHistoryDetailViewController.m
// covrme
//
// Created by Anthony Wong on 2013-07-28.
//
//

#import "CMHistoryDetailViewController.h"
#import "CMAPIClient.h"
#import "UIImageView+AFNetworking.h"

@interface CMHistoryDetailViewController ()

@end

@implementation CMHistoryDetailViewController


- (id)initWithDoorbellID:(NSString *)doorbellID visitorID:(NSString *)visitorID
{
self = [super initWithNibName:@"CMHistoryDetailViewController" bundle:nil];

if (self) {
self.doorbellID = doorbellID;
self.visitorID = visitorID;
}

return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.userInteractionEnabled = NO;
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

[SVProgressHUD showWithStatus:@"Loading" maskType:SVProgressHUDMaskTypeBlack];

[[CMAPIClient sharedClient] getHistoryDetailWithDoorbellID:self.doorbellID
visitorID:self.visitorID
success:^(AFHTTPRequestOperation *operation, id responseObject) {
[self parseResponse:responseObject];

[self.tableView reloadData];
[SVProgressHUD dismiss];
} failure:^(NSHTTPURLResponse *response, NSError *error) {
[SVProgressHUD dismiss];
}];


}

- (void)parseResponse:(NSDictionary *)response
{
NSString *thumbnail = [NSString stringWithFormat:@"%@=s%@", [response valueForKey:@"photo_thumbnail_url"], @"300"];
NSURL *url = [NSURL URLWithString:thumbnail];

[self.headerImageView setImageWithURL:url
placeholderImage:[UIImage imageNamed:@"prof_thumb_placeholder"]];

self.headerImageView.contentMode = UIViewContentModeScaleAspectFill;
self.headerImageView.clipsToBounds = YES;

self.typeString = [response valueForKey:@"description"];


// RFC3339 date formatting
NSString *timeStamp = [response valueForKey:@"when"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ";

NSDate *date;
NSError *error;
[formatter getObjectValue:&date forString:timeStamp range:nil error:&error];

NSString *formattedString = [NSDateFormatter localizedStringFromDate:date
dateStyle:NSDateFormatterShortStyle
timeStyle:NSDateFormatterNoStyle];

self.dateString = formattedString;

formattedString = [NSDateFormatter localizedStringFromDate:date
dateStyle:NSDateFormatterNoStyle
timeStyle:NSDateFormatterShortStyle];
self.timeString = formattedString;

// TODO: Real status string.
self.statusString = @"Missed";
}

#pragma mark - UITableView Delegates

- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =
[self.tableView dequeueReusableCellWithIdentifier:@"CMHistoryDetailTableViewCell"];

if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:@"CMHistoryDetailTableViewCell"];
}

if (indexPath.section == 0) {
switch (indexPath.row) {
case 0:
cell.textLabel.text = @"Date";
cell.detailTextLabel.text = self.dateString;
break;
case 1:
cell.textLabel.text = @"Time";
cell.detailTextLabel.text = self.timeString;
default:
break;
}
} else if (indexPath.section == 1) {
switch (indexPath.row) {
case 0:
cell.textLabel.text = @"Type";
cell.detailTextLabel.text = self.typeString;
break;
case 1:
cell.textLabel.text = @"Status";
cell.detailTextLabel.text = self.statusString;
default:
break;
}
}

return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
@end
Loading

0 comments on commit e38d40c

Please sign in to comment.