Skip to content

Commit

Permalink
Merge pull request #196 from birarda/18834
Browse files Browse the repository at this point in the history
Code Review for Job #18834
  • Loading branch information
birarda committed Feb 15, 2013
2 parents ff01e52 + e2a7bb1 commit 20bc75e
Show file tree
Hide file tree
Showing 20 changed files with 620 additions and 75 deletions.
93 changes: 69 additions & 24 deletions candpiosapp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions candpiosapp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ - (BOOL)application:(UIApplication *)application

[CPUserSessionHandler hideLoginBannerWithCompletion:nil];

[CPUserDefaultsHandler cleanGeofenceRequestLog];

return YES;
}

Expand Down
4 changes: 4 additions & 0 deletions candpiosapp/Common/CPUserDefaultsHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
+ (void)setNumberOfContactRequests:(NSInteger)numberOfContactRequests;
+ (NSInteger)numberOfContactRequests;

+ (void)addGeofenceRequest:(NSDictionary *)geofenceREquestDictionary;
+ (NSArray *)geofenceRequestLog;
+ (void)cleanGeofenceRequestLog;

+ (void)setPastVenues:(NSArray *)pastVenues;
+ (NSArray *)pastVenues;

Expand Down
43 changes: 43 additions & 0 deletions candpiosapp/Common/CPUserDefaultsHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,49 @@ + (CPVenue *)currentVenue
}
}

NSString* const kUDGeofenceRequestLog = @"geofenceRequestLog";

+ (void)addGeofenceRequest:(NSDictionary *)geofenceRequestDictionary
{
NSMutableArray *geofenceRequestLog = [[self geofenceRequestLog] mutableCopy];

if (!geofenceRequestLog) {
geofenceRequestLog = [NSMutableArray array];
}

[geofenceRequestLog addObject:geofenceRequestDictionary];

SET_DEFAULTS(Object, kUDGeofenceRequestLog, [NSArray arrayWithArray:geofenceRequestLog]);
}

+ (NSArray *)geofenceRequestLog
{
return DEFAULTS(object, kUDGeofenceRequestLog);
}

#define GEOFENCE_REQUEST_DAYS_TO_KEEP 7

+ (void)cleanGeofenceRequestLog
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSMutableArray *geofenceRequestLog = [[self geofenceRequestLog] mutableCopy];

NSTimeInterval secondsToLimit = -GEOFENCE_REQUEST_DAYS_TO_KEEP * 24 * 60 * 60;

for (NSDictionary *geofenceLogDict in [geofenceRequestLog mutableCopy]) {
NSDate *requestDate = geofenceLogDict[@"date"];

if ([requestDate compare:[NSDate dateWithTimeIntervalSinceNow:secondsToLimit]] == NSOrderedAscending) {
[geofenceRequestLog removeObject:geofenceLogDict];
} else {
break;
}
}

SET_DEFAULTS(Object, kUDGeofenceRequestLog, [NSArray arrayWithArray:geofenceRequestLog]);
});
}


NSString* const kUDPastVenues = @"pastVenues";
+ (void)setPastVenues:(NSArray *)pastVenues
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -63,44 +63,61 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.placesArray.count > 0) {
return 1;
}
else {
return 0;
switch (indexPath.row) {
case 0:
return 48;
case 1:
return 60;
default:
return 69;
}
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.placesArray.count > 0) {
return self.placesArray.count;
}
else {
return 0;
}
return self.placesArray.count + 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"AutoCheckinCell";
AutoCheckinCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

CPVenue *venue = [self.placesArray objectAtIndex:indexPath.row];
UITableViewCell *cell;

if (venue) {
cell.venueName.text = venue.name;
cell.venueAddress.text = venue.address;
cell.venue = venue;
if (indexPath.row < 2) {
NSString *topCellIdentifier = indexPath.row == 0 ? @"GeofenceLogButtonCell" : @"AutoCheckInToggleCell";
cell = [tableView dequeueReusableCellWithIdentifier:topCellIdentifier];
cell.contentView.backgroundColor = [UIColor colorWithR:40 G:40 B:40 A:1];
} else {
static NSString *VenueCellIdentifier = @"AutoCheckinCell";
AutoCheckinCell *autoCell = [tableView dequeueReusableCellWithIdentifier:VenueCellIdentifier];

cell.venueSwitch.on = venue.autoCheckin;
CPVenue *venue = [self.placesArray objectAtIndex:(indexPath.row - 2)];

if (venue) {
autoCell.venueName.text = venue.name;
autoCell.venueAddress.text = venue.address;
autoCell.venue = venue;

autoCell.venueSwitch.on = venue.autoCheckin;
}

cell = autoCell;
}

return cell;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// we're heading to the geofence log
// The original text on the back button is too long, just make it "Back"
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
}

- (IBAction)globalCheckinChanged:(UISwitch *)sender {
// Store the choice in NSUserDefaults
[CPUserDefaultsHandler setAutomaticCheckins:sender.on];
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ - (void)stopMonitoringVenue:(CPVenue *)venue
[Flurry logEvent:@"automaticCheckinLocationDisabled"];
}

- (NSDictionary *)geofenceRequestDictionaryForVenue:(CPVenue *)venue isCheckin:(BOOL)isCheckin
{
CLLocationCoordinate2D currentCoordinate = [CPAppDelegate locationManager].location.coordinate;

return @{
@"venueName" : venue.name,
@"venueID" : venue.venueID,
@"lat" : @(currentCoordinate.latitude),
@"lng" : @(currentCoordinate.longitude),
@"date": [NSDate date],
@"type": isCheckin ? @"checkIn" : @"checkOut"
};
}

- (void)autoCheckInForVenue:(CPVenue *)venue
{
// use CPapi to checkin
Expand All @@ -72,16 +86,18 @@ - (void)autoCheckInForVenue:(CPVenue *)venue
[Flurry logEvent:@"autoCheckInRequest" withParameters:json timed:YES];
}
}];

[CPUserDefaultsHandler addGeofenceRequest:[self geofenceRequestDictionaryForVenue:venue isCheckin:YES]];
}

- (void)autoCheckOutForVenue:(CPVenue *)venue
{
CLLocationCoordinate2D currentCoordinate = [CPAppDelegate locationManager].location.coordinate;

NSDictionary *requestObject = @{
@"venueID": venue.venueID,
@"lat": @(currentCoordinate.latitude),
@"lng": @(currentCoordinate.longitude)
@"venueID" : venue.venueID,
@"lat" : @(currentCoordinate.latitude),
@"lng" : @(currentCoordinate.longitude)
};

[[CPObjectManager sharedManager] getObjectsAtPathForRouteNamed:kRouteGeofenceCheckout
Expand All @@ -96,6 +112,8 @@ - (void)autoCheckOutForVenue:(CPVenue *)venue
{
// geofence checkout failed, nothing to do here
}];

[CPUserDefaultsHandler addGeofenceRequest:[self geofenceRequestDictionaryForVenue:venue isCheckin:NO]];
}

-(void)handleGeofenceNotification:(NSString *)message userInfo:(NSDictionary *)userInfo
Expand Down
16 changes: 16 additions & 0 deletions candpiosapp/Geofence/GeofenceLogEntryCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// GeofenceLogEntryCell.h
// candpiosapp
//
// Created by Stephen Birarda on 12/17/12.
// Copyright (c) 2012 Coffee and Power Inc. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface GeofenceLogEntryCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *venueNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *entryDateLabel;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;

@end
29 changes: 29 additions & 0 deletions candpiosapp/Geofence/GeofenceLogEntryCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// GeofenceLogEntryCell.m
// candpiosapp
//
// Created by Stephen Birarda on 12/17/12.
// Copyright (c) 2012 Coffee and Power Inc. All rights reserved.
//

#import "GeofenceLogEntryCell.h"

@implementation GeofenceLogEntryCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}

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

// Configure the view for the selected state
}

@end
13 changes: 13 additions & 0 deletions candpiosapp/Geofence/GeofenceLogTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// GeofenceLogTableViewController.h
// candpiosapp
//
// Created by Stephen Birarda on 12/17/12.
// Copyright (c) 2012 Coffee and Power Inc. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface GeofenceLogTableViewController : UITableViewController

@end
101 changes: 101 additions & 0 deletions candpiosapp/Geofence/GeofenceLogTableViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//
// GeofenceLogTableViewController.m
// candpiosapp
//
// Created by Stephen Birarda on 12/17/12.
// Copyright (c) 2012 Coffee and Power Inc. All rights reserved.
//

#import "GeofenceLogTableViewController.h"
#import "GeofenceLogEntryCell.h"
#import <MessageUI/MFMailComposeViewController.h>

@interface GeofenceLogTableViewController () <MFMailComposeViewControllerDelegate>

@property (strong, nonatomic) NSArray *logEntries;
@property (strong, nonatomic) NSDateFormatter *entryDateFormatter;

@end

@implementation GeofenceLogTableViewController

- (void)viewDidLoad
{
[super viewDidLoad];

self.logEntries = [CPUserDefaultsHandler geofenceRequestLog];

if (![MFMailComposeViewController canSendMail] || self.logEntries.count == 0) {
// hide the email button
self.navigationItem.rightBarButtonItem = nil;
}
}

- (NSDateFormatter *)entryDateFormatter
{
if (!_entryDateFormatter) {
_entryDateFormatter = [[NSDateFormatter alloc] init];
_entryDateFormatter.dateFormat = @"MMMM d - h:mm:ss a";
}

return _entryDateFormatter;
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.logEntries.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"GeofenceLogEntryCell";
GeofenceLogEntryCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

NSDictionary *logEntryDict = [self.logEntries objectAtIndex:indexPath.row];

cell.venueNameLabel.text = logEntryDict[@"venueName"];
cell.entryDateLabel.text = [self.entryDateFormatter stringFromDate:logEntryDict[@"date"]];

NSString *imageName = [logEntryDict[@"type"] isEqualToString:@"checkIn"] ? @"check-in-for-list" : @"check-out-for-list";
cell.iconImageView.image = [UIImage imageNamed:imageName];

return cell;
}

#pragma mark - IBActions
- (IBAction)emailLogButtonPressed:(id)sender
{
MFMailComposeViewController *composeVC = [[MFMailComposeViewController alloc] init];
composeVC.mailComposeDelegate = self;
[composeVC setSubject:[NSString stringWithFormat:@"Geofence log for %@ (%@)",
[CPUserDefaultsHandler currentUser].nickname,
[CPUserDefaultsHandler currentUser].userID]];

NSMutableString *emailBody = [NSMutableString stringWithString:@""];

for (NSDictionary *logEntryDict in self.logEntries) {
[emailBody appendString:[NSString stringWithFormat:@"%@, %@, %@, %@, %@\n",
logEntryDict[@"venueID"],
logEntryDict[@"lat"],
logEntryDict[@"lng"],
[self.entryDateFormatter stringFromDate:logEntryDict[@"date"]],
logEntryDict[@"type"]]];
}

[composeVC setMessageBody:emailBody isHTML:NO];
[composeVC setToRecipients:@[@"[email protected]"]];
[self presentModalViewController:composeVC animated:YES];
}

#pragma mark - MFMailComposeViewControllerDelegate
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error
{
[self dismissModalViewControllerAnimated:YES];
}

@end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added candpiosapp/Geofence/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added candpiosapp/Geofence/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion candpiosapp/Map/MapTabController.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ - (IBAction)locateMe:(id)sender
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied ||
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted) {

NSString *message = @"We're unable to get your location and the application relies on it.\n\nPlease go to your settings and enable location for the app.";
NSString *message = @"We're unable to get your location and the application relies on it.\n\nPlease go to your settings and enable location for the Workclub app.";
[SVProgressHUD showErrorWithStatus:message
duration:kDefaultDismissDelay];
} else {
Expand Down
Loading

0 comments on commit 20bc75e

Please sign in to comment.