Use calllog id as parameters for HistoryDetailsView

Fix issue when core is recreated
This commit is contained in:
Yann Diorcet 2013-02-21 11:02:19 +01:00
parent dccd31d927
commit b672051864
5 changed files with 84 additions and 17 deletions

View file

@ -26,6 +26,7 @@
@interface HistoryDetailsViewController : UIViewController<UICompositeViewDelegate> {
@private
ABRecordRef contact;
LinphoneCallLog *callLog;
NSDateFormatter *dateFormatter;
}
@property (nonatomic, retain) IBOutlet UIImageView *avatarImage;
@ -41,7 +42,7 @@
@property (nonatomic, retain) IBOutlet UIButton *callButton;
@property (nonatomic, retain) IBOutlet UIButton *messageButton;
@property (nonatomic, retain) IBOutlet UIButton *addContactButton;
@property (nonatomic, assign) LinphoneCallLog *callLog;
@property (nonatomic, assign) NSString *callLogId;
- (IBAction)onBackClick:(id)event;
- (IBAction)onContactClick:(id)event;

View file

@ -24,7 +24,7 @@
@implementation HistoryDetailsViewController
@synthesize callLog;
@synthesize callLogId;
@synthesize avatarImage;
@synthesize addressLabel;
@synthesize dateLabel;
@ -57,6 +57,7 @@
[[NSNotificationCenter defaultCenter] removeObserver:self];
[dateFormatter release];
[callLogId release];
[avatarImage release];
[addressLabel release];
@ -98,8 +99,8 @@ static UICompositeViewDescription *compositeDescription = nil;
#pragma mark - Property Functions
- (void)setCallLog:(LinphoneCallLog *)acallLog {
self->callLog = acallLog;
- (void)setCallLogId:(NSString *)acallLogId {
self->callLogId = [acallLogId copy];
[self update];
}
@ -123,6 +124,11 @@ static UICompositeViewDescription *compositeDescription = nil;
selector:@selector(update)
name:kLinphoneAddressBookUpdate
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(coreUpdateEvent:)
name:kLinphoneCoreUpdate
object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
@ -131,6 +137,17 @@ static UICompositeViewDescription *compositeDescription = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self
name:kLinphoneAddressBookUpdate
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:kLinphoneCoreUpdate
object:nil];
}
#pragma mark - Event Functions
- (void)coreUpdateEvent:(NSNotification*)notif {
[self update];
}
@ -161,8 +178,25 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (void)update {
// Don't update if callLog is null
if(![LinphoneManager isLcReady]) {
return;
}
// Look for the call log
callLog = NULL;
const MSList *list = linphone_core_get_call_logs([LinphoneManager getLc]);
while(list != NULL) {
LinphoneCallLog *log = (LinphoneCallLog *)list->data;
const char *cid = linphone_call_log_get_call_id(log);
if(cid != NULL && [callLogId isEqualToString:[NSString stringWithUTF8String:cid]]) {
callLog = log;
}
list = list->next;
}
// Pop if callLog is null
if(callLog == NULL) {
[[PhoneMainView instance] popCurrentView];
return;
}

View file

@ -62,6 +62,36 @@
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(loadData)
name:kLinphoneAddressBookUpdate
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(coreUpdateEvent:)
name:kLinphoneCoreUpdate
object:nil];
[self loadData];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:kLinphoneAddressBookUpdate
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:kLinphoneCoreUpdate
object:nil];
}
#pragma mark - Event Functions
- (void)coreUpdateEvent:(NSNotification*)notif {
// Invalid all pointers
[self loadData];
}
@ -81,17 +111,19 @@
- (void)loadData {
[callLogs removeAllObjects];
const MSList * logs = linphone_core_get_call_logs([LinphoneManager getLc]);
while(logs != NULL) {
LinphoneCallLog* log = (LinphoneCallLog *) logs->data;
if(missedFilter) {
if (linphone_call_log_get_status(log) == LinphoneCallMissed) {
if([LinphoneManager isLcReady]) {
const MSList * logs = linphone_core_get_call_logs([LinphoneManager getLc]);
while(logs != NULL) {
LinphoneCallLog* log = (LinphoneCallLog *) logs->data;
if(missedFilter) {
if (linphone_call_log_get_status(log) == LinphoneCallMissed) {
[callLogs addObject:[NSValue valueWithPointer: log]];
}
} else {
[callLogs addObject:[NSValue valueWithPointer: log]];
}
} else {
[callLogs addObject:[NSValue valueWithPointer: log]];
logs = ms_list_next(logs);
}
logs = ms_list_next(logs);
}
[[self tableView] reloadData];
}

View file

@ -238,12 +238,12 @@
}
logs = logs->next;
}
if(theLog != NULL) {
if(theLog != NULL && linphone_call_log_get_call_id(theLog) != NULL) {
// Go to HistoryDetails view
[[PhoneMainView instance] changeCurrentView:[HistoryViewController compositeViewDescription]];
HistoryDetailsViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[HistoryDetailsViewController compositeViewDescription] push:TRUE], HistoryDetailsViewController);
if(controller != nil) {
[controller setCallLog:theLog];
[controller setCallLogId:[NSString stringWithUTF8String:linphone_call_log_get_call_id(theLog)]];
}
}
}

View file

@ -68,11 +68,11 @@
#pragma mark - Action Functions
- (IBAction)onDetails:(id) event {
if(callLog != NULL) {
if(callLog != NULL && linphone_call_log_get_call_id(callLog) != NULL) {
// Go to History details view
HistoryDetailsViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[HistoryDetailsViewController compositeViewDescription] push:TRUE], HistoryDetailsViewController);
if(controller != nil) {
[controller setCallLog:callLog];
[controller setCallLogId: [NSString stringWithUTF8String:linphone_call_log_get_call_id(callLog)]];
}
}
}