Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

Commit

Permalink
Added a new screen to the application, showing the latest activity in…
Browse files Browse the repository at this point in the history
… the FFCRM server
  • Loading branch information
Adrian Kosmaczewski committed Sep 29, 2011
1 parent 4a45ae2 commit e0d5e37
Show file tree
Hide file tree
Showing 32 changed files with 772 additions and 3,948 deletions.
39 changes: 39 additions & 0 deletions Classes/Controllers/SBActivitiesController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// SBActivitiesController.h
// Senbei
//
// Created by Adrian on 9/29/11.
// Copyright (c) 2011, akosma software / Adrian Kosmaczewski
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// This product includes software developed by akosma software.
// 4. Neither the name of the akosma software nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY ADRIAN KOSMACZEWSKI ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL ADRIAN KOSMACZEWSKI BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import <UIKit/UIKit.h>

@interface SBActivitiesController : UITableViewController

@end
173 changes: 173 additions & 0 deletions Classes/Controllers/SBActivitiesController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
//
// SBActivitiesController.m
// Senbei
//
// Created by Adrian on 9/29/11.
// Copyright (c) 2011, akosma software / Adrian Kosmaczewski
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// This product includes software developed by akosma software.
// 4. Neither the name of the akosma software nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY ADRIAN KOSMACZEWSKI ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL ADRIAN KOSMACZEWSKI BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import "SBActivitiesController.h"
#import "SBModels.h"
#import "SBHelpers.h"
#import "SBCommentsController.h"

@interface SBActivitiesController ()

@property (nonatomic, retain) NSArray *activities;

@end


@implementation SBActivitiesController

@synthesize activities = _activities;

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_activities release];
[super dealloc];
}

#pragma mark - Public methods

- (void)refresh
{
[[SBNetworkManager sharedSBNetworkManager] loadActivities];
}

#pragma mark - UIViewController methods

- (void)viewDidLoad
{
[super viewDidLoad];
self.title = NSLocalizedString(@"ACTIVITIES_TITLE", @"Title of the activities controller");
self.tableView.rowHeight = 70.0;

UIBarButtonItem *reloadItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:@selector(refresh)] autorelease];
self.navigationItem.rightBarButtonItem = reloadItem;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveActivities:)
name:SBNetworkManagerDidRetrieveActivitiesNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(refresh)
name:SBNetworkManagerDidPostCommentNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(refresh)
name:SBNetworkManagerDidDeleteCommentNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(refresh)
name:SBNetworkManagerDidCreateTaskNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(refresh)
name:SBNetworkManagerDidMarkTaskAsDoneNotification
object:nil];

[self refresh];
}

#pragma mark - NSNotification handler methods

- (void)didReceiveActivities:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
self.activities = [userInfo objectForKey:@"data"];
[self.tableView reloadData];
}

#pragma mark - Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.activities count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
cell.detailTextLabel.numberOfLines = 0;
}

SBActivity *activity = [self.activities objectAtIndex:indexPath.row];
cell.textLabel.text = activity.info;
NSString *date = [activity.createdAt stringFormattedWithCurrentLocale];
NSString *info = [[NSString stringWithFormat:@"%@ %@", activity.action, activity.subjectType] capitalizedString];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@\n%@", info, date];

if ([activity.action isEqualToString:@"deleted"] || [activity.subjectType isEqualToString:@"Task"])
{
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}

return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SBActivity *activity = [self.activities objectAtIndex:indexPath.row];
if (![activity.action isEqualToString:@"deleted"] && ![activity.subjectType isEqualToString:@"Task"])
{
NSString *subjectType = activity.subjectType;
Class modelClass = [SBBaseEntity classForSubjectType:subjectType];
SBBaseEntity *entity = [[[modelClass alloc] init] autorelease];
entity.objectId = activity.subjectId;
entity.name = @"";

SBCommentsController *commentsController = [[[SBCommentsController alloc] init] autorelease];
commentsController.entity = entity;
[self.navigationController pushViewController:commentsController
animated:YES];
}
}

@end
2 changes: 1 addition & 1 deletion Classes/Controllers/SBListController.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@

@property (nonatomic) UITableViewCellAccessoryType accessoryType;
@property (nonatomic, retain) Class listedClass;
@property (nonatomic, assign) id<SBListControllerDelegate> delegate;
@property (nonatomic, assign) IBOutlet id<SBListControllerDelegate> delegate;

@end
2 changes: 2 additions & 0 deletions Classes/Controllers/SBRootController.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@class SBSettingsController;
@class SBTasksController;
@class SBListController;
@class SBActivitiesController;

@interface SBRootController : UITabBarController <UITabBarControllerDelegate,
SBListControllerDelegate,
Expand All @@ -52,6 +53,7 @@
@property (nonatomic, retain) IBOutlet SBListController *opportunitiesController;
@property (nonatomic, retain) IBOutlet SBListController *leadsController;
@property (nonatomic, retain) IBOutlet SBListController *campaignsController;
@property (nonatomic, retain) IBOutlet SBActivitiesController *activitiesController;
@property (nonatomic, retain) IBOutlet SBSettingsController *settingsController;
@property (nonatomic, retain) IBOutlet SBTasksController *tasksController;

Expand Down
46 changes: 36 additions & 10 deletions Classes/Controllers/SBRootController.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#import "SBTasksController.h"
#import "SBCommentsController.h"
#import "SBWebBrowserController.h"
#import "SBActivitiesController.h"
#import "SBNotifications.h"

typedef enum {
Expand All @@ -50,7 +51,8 @@
SBViewControllerOpportunities = 4,
SBViewControllerLeads = 5,
SBViewControllerCampaigns = 6,
SBViewControllerMore = 7
SBViewControllerMore = 7,
SBViewControllerActivities = 8
} SBViewController;

NSString *getValueForPropertyFromPerson(ABRecordRef person, ABPropertyID property, ABMultiValueIdentifier identifierForValue)
Expand All @@ -72,6 +74,7 @@ @interface SBRootController ()
@property (nonatomic, retain) UINavigationController *settingsNavController;
@property (nonatomic, retain) UINavigationController *tasksNavController;
@property (nonatomic, retain) UINavigationController *commentsNavController;
@property (nonatomic, retain) UINavigationController *activitiesNavController;

@end

Expand All @@ -86,6 +89,7 @@ @implementation SBRootController
@synthesize settingsController = _settingsController;
@synthesize tasksController = _tasksController;
@synthesize commentsController = _commentsController;
@synthesize activitiesController = _activitiesController;

@synthesize accountsNavController = _accountsNavController;
@synthesize contactsNavController = _contactsNavController;
Expand All @@ -95,6 +99,7 @@ @implementation SBRootController
@synthesize settingsNavController = _settingsNavController;
@synthesize tasksNavController = _tasksNavController;
@synthesize commentsNavController = _commentsNavController;
@synthesize activitiesNavController = _activitiesNavController;

- (void)dealloc
{
Expand All @@ -114,6 +119,8 @@ - (void)dealloc
[_settingsNavController release];
[_tasksNavController release];
[_commentsNavController release];
[_activitiesController release];
[_activitiesNavController release];
[super dealloc];
}

Expand Down Expand Up @@ -153,13 +160,14 @@ - (void)viewDidLoad
name:SBNetworkManagerDidRetrieveLeadsNotification
object:nil];
self.leadsController.listedClass = [SBLead class];

self.leadsController.tabBarItem.image = [UIImage imageNamed:@"leads.png"];
self.contactsController.tabBarItem.image = [UIImage imageNamed:@"contacts.png"];
self.campaignsController.tabBarItem.image = [UIImage imageNamed:@"campaigns.png"];
self.tasksController.tabBarItem.image = [UIImage imageNamed:@"tasks.png"];
self.accountsController.tabBarItem.image = [UIImage imageNamed:@"accounts.png"];
self.opportunitiesController.tabBarItem.image = [UIImage imageNamed:@"opportunities.png"];

self.leadsController.tabBarItem.image = [UIImage imageNamed:@"leads"];
self.contactsController.tabBarItem.image = [UIImage imageNamed:@"contacts"];
self.campaignsController.tabBarItem.image = [UIImage imageNamed:@"campaigns"];
self.tasksController.tabBarItem.image = [UIImage imageNamed:@"tasks"];
self.accountsController.tabBarItem.image = [UIImage imageNamed:@"accounts"];
self.opportunitiesController.tabBarItem.image = [UIImage imageNamed:@"opportunities"];
self.activitiesController.tabBarItem.image = [UIImage imageNamed:@"activities"];

self.leadsNavController = [[[UINavigationController alloc] initWithRootViewController:self.leadsController] autorelease];
self.contactsNavController = [[[UINavigationController alloc] initWithRootViewController:self.contactsController] autorelease];
Expand All @@ -168,13 +176,15 @@ - (void)viewDidLoad
self.accountsNavController = [[[UINavigationController alloc] initWithRootViewController:self.accountsController] autorelease];
self.opportunitiesNavController = [[[UINavigationController alloc] initWithRootViewController:self.opportunitiesController] autorelease];
self.settingsNavController = [[[UINavigationController alloc] initWithRootViewController:self.settingsController] autorelease];
self.activitiesNavController = [[[UINavigationController alloc] initWithRootViewController:self.activitiesController] autorelease];

// Restore the order of the tab bars following the preferences of the user
NSArray *order = [SBSettingsManager sharedSBSettingsManager].tabOrder;
NSMutableArray *controllers = [[NSMutableArray alloc] initWithCapacity:7];
NSMutableArray *controllers = [[NSMutableArray alloc] initWithCapacity:8];
if (order == nil)
{
// Probably first run, or never reordered controllers
[controllers addObject:self.activitiesController.navigationController];
[controllers addObject:self.tasksController.navigationController];
[controllers addObject:self.accountsController.navigationController];
[controllers addObject:self.contactsController.navigationController];
Expand Down Expand Up @@ -216,6 +226,10 @@ - (void)viewDidLoad
case SBViewControllerTasks:
[controllers addObject:self.tasksController.navigationController];
break;

case SBViewControllerActivities:
[controllers addObject:self.activitiesController.navigationController];
break;

default:
break;
Expand Down Expand Up @@ -257,7 +271,11 @@ - (void)viewDidLoad
case SBViewControllerTasks:
self.selectedViewController = self.tasksController.navigationController;
break;


case SBViewControllerActivities:
self.selectedViewController = self.activitiesController.navigationController;
break;

case SBViewControllerMore:
self.selectedViewController = self.moreNavigationController;
default:
Expand Down Expand Up @@ -314,6 +332,10 @@ - (void)tabBarController:(UITabBarController *)tabBarController
{
settings.currentTab = SBViewControllerMore;
}
else if (viewController == self.activitiesController.navigationController)
{
settings.currentTab = SBViewControllerActivities;
}
}

- (void)tabBarController:(UITabBarController *)tabBarController
Expand Down Expand Up @@ -353,6 +375,10 @@ - (void)tabBarController:(UITabBarController *)tabBarController
{
[order addObject:[NSNumber numberWithInt:SBViewControllerSettings]];
}
else if (controller == self.activitiesController.navigationController)
{
[order addObject:[NSNumber numberWithInt:SBViewControllerActivities]];
}
}
[SBSettingsManager sharedSBSettingsManager].tabOrder = order;
}
Expand Down
1 change: 1 addition & 0 deletions Classes/Helpers/SBHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@
#import "NSString+Senbei.h"
#import "SBSettingsManager.h"
#import "ASIHTTPRequest+Senbei.h"
#import "SBNotifications.h"
Loading

0 comments on commit e0d5e37

Please sign in to comment.