From cf6b974161da3d47598b5600185a35917fcec4ee Mon Sep 17 00:00:00 2001 From: David Idmansour Date: Thu, 14 Jun 2018 17:04:03 +0200 Subject: [PATCH] get contact pictures from sip address & update user defaults when app launch and after each call --- Classes/HistoryListTableView.h | 1 + Classes/HistoryListTableView.m | 48 +- Classes/LinphoneManager.m | 6 +- .../Base.lproj/MainInterface.storyboard | 4633 ----------------- latestCallsWidget/TodayViewController.h | 1 - latestCallsWidget/TodayViewController.m | 57 +- 6 files changed, 55 insertions(+), 4691 deletions(-) diff --git a/Classes/HistoryListTableView.h b/Classes/HistoryListTableView.h index 1285997be..c6a49334c 100644 --- a/Classes/HistoryListTableView.h +++ b/Classes/HistoryListTableView.h @@ -29,4 +29,5 @@ @property(strong, nonatomic) NSMutableDictionary *sections; @property(strong, nonatomic) NSMutableArray *sortedDays; ++ (void) saveDataToUserDefaults; @end diff --git a/Classes/HistoryListTableView.m b/Classes/HistoryListTableView.m index 5c72fc1ef..fc0ddbda5 100644 --- a/Classes/HistoryListTableView.m +++ b/Classes/HistoryListTableView.m @@ -127,7 +127,6 @@ const bctbx_list_t *logs = linphone_core_get_call_logs(LC); self.sections = [NSMutableDictionary dictionary]; - NSUserDefaults *mySharedDefaults = [[NSUserDefaults alloc] initWithSuiteName: @"group.belledonne-communications.linphone.widget"]; while (logs != NULL) { LinphoneCallLog *log = (LinphoneCallLog *)logs->data; if (!missedFilter || linphone_call_log_get_status(log) == LinphoneCallMissed) { @@ -160,26 +159,6 @@ [super loadData]; - NSMutableDictionary *dictShare = [NSMutableDictionary dictionary]; - for (id day in self.sections.allKeys) { - for (id log in self.sections[day]) { - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; -// [dict setObject:[NSDate dateWithTimeIntervalSince1970:linphone_call_log_get_start_date([log pointerValue])] -// forKey:@"date"]; - [dict setObject:[NSString stringWithUTF8String:linphone_call_log_get_call_id([log pointerValue])] - forKey:@"id"]; - [dict setObject:[NSString stringWithUTF8String:linphone_address_as_string(linphone_call_log_get_remote_address([log pointerValue]))] - forKey:@"address"]; - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; - - NSString *stringFromDate = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:linphone_call_log_get_start_date([log pointerValue])]]; - [dictShare setObject:dict - forKey:stringFromDate]; - } - } - [mySharedDefaults setObject:dictShare forKey:@"logs"]; - if (IPAD) { if (![self selectFirstRow]) { HistoryDetailsView *view = VIEW(HistoryDetailsView); @@ -188,6 +167,33 @@ } } ++ (void) saveDataToUserDefaults { + const bctbx_list_t *logs = linphone_core_get_call_logs(LC); + NSUserDefaults *mySharedDefaults = [[NSUserDefaults alloc] initWithSuiteName: @"group.belledonne-communications.linphone.widget"]; + NSMutableDictionary *dictShare = [NSMutableDictionary dictionary]; + while (logs != NULL) { + LinphoneCallLog *log = (LinphoneCallLog *)logs->data; + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + if (!linphone_call_log_get_call_id(log)) { + logs = bctbx_list_next(logs); + continue; + } + [dict setObject:[NSString stringWithUTF8String:linphone_call_log_get_call_id(log)] + forKey:@"id"]; + [dict setObject:[NSString stringWithUTF8String:linphone_address_as_string(linphone_call_log_get_remote_address(log))] + forKey:@"address"]; + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; + + NSString *stringFromDate = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:linphone_call_log_get_start_date(log)]]; + [dictShare setObject:dict + forKey:stringFromDate]; + + logs = bctbx_list_next(logs); + } + [mySharedDefaults setObject:dictShare forKey:@"logs"]; +} + - (void)computeSections { NSArray *unsortedDays = [self.sections allKeys]; _sortedDays = [[NSMutableArray alloc] diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index a8d97a7b8..5d43ea304 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -718,6 +718,7 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char // Disable speaker when no more call if ((state == LinphoneCallEnd || state == LinphoneCallError)) { + [HistoryListTableView saveDataToUserDefaults]; [[UIDevice currentDevice] setProximityMonitoringEnabled:FALSE]; speaker_already_enabled = FALSE; if (linphone_core_get_calls_nb(theLinphoneCore) == 0) { @@ -1801,7 +1802,10 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach [self enableProxyPublish:([UIApplication sharedApplication].applicationState == UIApplicationStateActive)]; - LOGI(@"Linphone [%s] started on [%s]", linphone_core_get_version(), [[UIDevice currentDevice].model UTF8String]); + //update UserDefaults for widgets + [HistoryListTableView saveDataToUserDefaults]; + + LOGI(@"Linphone [%s] started on [%s]", linphone_core_get_version(), [[UIDevice currentDevice].model UTF8String]); // Post event NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSValue valueWithPointer:theLinphoneCore] forKey:@"core"]; diff --git a/latestCallsWidget/Base.lproj/MainInterface.storyboard b/latestCallsWidget/Base.lproj/MainInterface.storyboard index 2ad09841d..437d2feaa 100644 --- a/latestCallsWidget/Base.lproj/MainInterface.storyboard +++ b/latestCallsWidget/Base.lproj/MainInterface.storyboard @@ -25,13 +25,6 @@ -