2010-09-30 12:27:22 -05:00
|
|
|
//
|
|
|
|
// MGMAccounts.m
|
|
|
|
// VoiceMob
|
|
|
|
//
|
|
|
|
// Created by Mr. Gecko on 9/27/10.
|
2013-07-20 06:56:17 -05:00
|
|
|
// Copyright (c) 2011 Mr. Gecko's Media (James Coleman). http://mrgeckosmedia.com/
|
2010-09-30 12:27:22 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "MGMAccounts.h"
|
|
|
|
#import "MGMAccountController.h"
|
2013-07-20 06:56:17 -05:00
|
|
|
#import "MGMBadgeView.h"
|
2010-09-30 12:27:22 -05:00
|
|
|
#import "MGMAccountSetup.h"
|
2013-07-20 06:56:17 -05:00
|
|
|
#import "MGMVoiceUser.h"
|
2010-09-30 12:27:22 -05:00
|
|
|
#import "MGMVMAddons.h"
|
|
|
|
#import <MGMUsers/MGMUsers.h>
|
2010-10-01 22:03:15 -05:00
|
|
|
#import <VoiceBase/VoiceBase.h>
|
2010-09-30 12:27:22 -05:00
|
|
|
|
|
|
|
NSString * const MGMAccountCellIdentifier = @"MGMAccountCellIdentifier";
|
|
|
|
|
|
|
|
@implementation MGMAccounts
|
|
|
|
- (id)initWithAccountController:(MGMAccountController *)theAccountController {
|
2013-07-20 06:56:17 -05:00
|
|
|
if ((self = [super init])) {
|
2010-09-30 12:27:22 -05:00
|
|
|
accountController = theAccountController;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
- (void)dealloc {
|
2013-07-20 06:56:17 -05:00
|
|
|
#if releaseDebug
|
|
|
|
NSLog(@"%s Releasing", __PRETTY_FUNCTION__);
|
|
|
|
#endif
|
2010-09-30 12:27:22 -05:00
|
|
|
[self releaseView];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIView *)view {
|
|
|
|
if (tableView==nil) {
|
|
|
|
if (![[NSBundle mainBundle] loadNibNamed:[[UIDevice currentDevice] appendDeviceSuffixToString:@"Accounts"] owner:self options:nil]) {
|
|
|
|
NSLog(@"Unable to load Accounts");
|
|
|
|
} else {
|
|
|
|
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
|
|
|
|
[notificationCenter addObserver:tableView selector:@selector(reloadData) name:MGMUserStartNotification object:nil];
|
|
|
|
[notificationCenter addObserver:tableView selector:@selector(reloadData) name:MGMUserDoneNotification object:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tableView;
|
|
|
|
}
|
|
|
|
- (void)releaseView {
|
2013-07-20 06:56:17 -05:00
|
|
|
#if releaseDebug
|
|
|
|
NSLog(@"%s Releasing", __PRETTY_FUNCTION__);
|
|
|
|
#endif
|
|
|
|
[tableView release];
|
|
|
|
tableView = nil;
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
2010-09-30 12:27:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
return [[MGMUser users] count];
|
|
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2013-07-20 06:56:17 -05:00
|
|
|
MGMBadgeView *cell = (MGMBadgeView *)[tableView dequeueReusableCellWithIdentifier:MGMAccountCellIdentifier];
|
2010-09-30 12:27:22 -05:00
|
|
|
if (cell==nil) {
|
2013-07-20 06:56:17 -05:00
|
|
|
cell = [[[MGMBadgeView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MGMAccountCellIdentifier] autorelease];
|
2010-09-30 12:27:22 -05:00
|
|
|
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
|
|
|
|
}
|
|
|
|
NSArray *users = [MGMUser users];
|
|
|
|
if ([users count]<=[indexPath indexAtPosition:1]) {
|
2013-07-20 06:56:17 -05:00
|
|
|
[cell setName:@"Unknown"];
|
2010-09-30 12:27:22 -05:00
|
|
|
} else {
|
2013-07-20 06:56:17 -05:00
|
|
|
[cell setName:[[MGMUser userNames] objectAtIndex:[indexPath indexAtPosition:1]]];
|
2010-09-30 12:27:22 -05:00
|
|
|
MGMUser *user = [MGMUser userWithID:[users objectAtIndex:[indexPath indexAtPosition:1]]];
|
2013-07-20 06:56:17 -05:00
|
|
|
id<MGMAccountProtocol> account = [accountController contactControllerWithUser:user];
|
|
|
|
if ([account isKindOfClass:[MGMVoiceUser class]]) {
|
|
|
|
int count = [accountController badgeValueForInstance:[(MGMVoiceUser *)account instance]];
|
|
|
|
if (count!=0)
|
|
|
|
[cell setBadge:[[NSNumber numberWithInt:count] stringValue]];
|
|
|
|
else
|
|
|
|
[cell setBadge:nil];
|
|
|
|
} else {
|
|
|
|
[cell setBadge:nil];
|
|
|
|
}
|
|
|
|
#if MGMSPENABLED
|
2010-09-30 12:27:22 -05:00
|
|
|
if ([[user settingForKey:MGMSAccountType] isEqual:MGMSSIP]) {
|
|
|
|
if ([user settingForKey:MGMSIPAccountFullName]!=nil && ![[user settingForKey:MGMSIPAccountFullName] isEqual:@""])
|
2013-07-20 06:56:17 -05:00
|
|
|
[cell setName:[user settingForKey:MGMSIPAccountFullName]];
|
2010-09-30 12:27:22 -05:00
|
|
|
}
|
2013-07-20 06:56:17 -05:00
|
|
|
#endif
|
2010-09-30 12:27:22 -05:00
|
|
|
}
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
- (BOOL)tableView:(UITableView *)theTableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
- (UITableViewCellEditingStyle)tableView:(UITableView *)theTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
return UITableViewCellEditingStyleDelete;
|
|
|
|
}
|
|
|
|
- (NSString *)tableView:(UITableView *)theTableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
return @"Remove";
|
|
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)theTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
MGMUser *user = [MGMUser userWithID:[[MGMUser users] objectAtIndex:[indexPath indexAtPosition:1]]];
|
|
|
|
if ([user isStarted]) {
|
|
|
|
[user done];
|
|
|
|
if ([user isStarted])
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[user remove];
|
|
|
|
[tableView reloadData];
|
|
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
MGMUser *user = [MGMUser userWithID:[[MGMUser users] objectAtIndex:[indexPath indexAtPosition:1]]];
|
|
|
|
[accountController showUser:user];
|
|
|
|
}
|
|
|
|
@end
|