mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-24 22:58:13 +00:00
get contact pictures from sip address & update user defaults when app launch and after each call
This commit is contained in:
parent
e82cfa3211
commit
cf6b974161
6 changed files with 55 additions and 4691 deletions
|
|
@ -29,4 +29,5 @@
|
|||
@property(strong, nonatomic) NSMutableDictionary *sections;
|
||||
@property(strong, nonatomic) NSMutableArray *sortedDays;
|
||||
|
||||
+ (void) saveDataToUserDefaults;
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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"];
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -14,7 +14,6 @@
|
|||
@property (strong, nonatomic) NSMutableDictionary *imgs;
|
||||
@property (strong, nonatomic) NSMutableArray *sortedDates;
|
||||
@property (strong, nonatomic) NSMutableArray *logIds;
|
||||
@property (strong, nonatomic) NSNumber *nbImgs;
|
||||
@property (strong) dispatch_semaphore_t sem;
|
||||
|
||||
- (IBAction)firstButtonTapped;
|
||||
|
|
|
|||
|
|
@ -18,13 +18,7 @@
|
|||
|
||||
@implementation TodayViewController
|
||||
|
||||
- (instancetype) init {
|
||||
printf("BONJOUR\n");
|
||||
return [super init];
|
||||
}
|
||||
|
||||
- (void)loadData {
|
||||
_contactsToDisplay = [NSMutableArray array];
|
||||
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
||||
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
|
||||
|
||||
|
|
@ -57,9 +51,8 @@
|
|||
CNContactStore* store = [[CNContactStore alloc] init];
|
||||
[store containersMatchingPredicate:[CNContainer predicateForContainersWithIdentifiers:@[ store.defaultContainerIdentifier]] error:&contactError];
|
||||
NSArray *keysToFetch = @[
|
||||
CNContactEmailAddressesKey, CNContactPhoneNumbersKey, CNContactImageDataAvailableKey,
|
||||
CNContactFamilyNameKey, CNContactGivenNameKey, CNContactNicknameKey,
|
||||
CNContactInstantMessageAddressesKey, CNContactIdentifierKey, CNContactImageDataKey
|
||||
CNContactImageDataAvailableKey, CNContactInstantMessageAddressesKey,
|
||||
CNContactIdentifierKey, CNContactImageDataKey
|
||||
];
|
||||
CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:keysToFetch];
|
||||
|
||||
|
|
@ -69,11 +62,16 @@
|
|||
contactError);
|
||||
} else {
|
||||
if (contact.imageDataAvailable) {
|
||||
[self.imgs setObject:contact.imageData
|
||||
forKey:[contact.givenName stringByAppendingFormat:
|
||||
([contact.familyName isEqualToString:@""])?@"":@" %@", contact.familyName]];
|
||||
printf("Ajout de l'image de %s\n", [contact.givenName stringByAppendingFormat:
|
||||
([contact.familyName isEqualToString:@""])?@"":@" %@", contact.familyName].UTF8String);
|
||||
NSArray *addresses = contact.instantMessageAddresses;
|
||||
NSString *address = @"";
|
||||
for (CNLabeledValue *v in addresses) {
|
||||
CNInstantMessageAddress *addressValue = v.value;
|
||||
if ([addressValue.service isEqualToString:@"SIP"]) {
|
||||
address = addressValue.username;
|
||||
[self.imgs setObject:contact.imageData
|
||||
forKey:address];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
|
@ -88,29 +86,26 @@
|
|||
_logIds = [NSMutableArray array];
|
||||
int i = 0, j = 0;
|
||||
dispatch_semaphore_wait(_sem, DISPATCH_TIME_FOREVER);
|
||||
_nbImgs = [NSNumber numberWithInteger:_imgs.count];
|
||||
while (i < _stackViews.count && j < _sortedDates.count) {
|
||||
NSDate *date = _sortedDates[j++];
|
||||
NSString *address = [[_logs objectForKey:date] objectForKey:@"address"];
|
||||
LinphoneAddress *adr = linphone_address_new([address UTF8String]);
|
||||
NSString *logId = [[_logs objectForKey:date] objectForKey:@"id"];
|
||||
if ([_contactsToDisplay containsObject:[NSString stringWithUTF8String:linphone_address_as_string_uri_only(adr)]])
|
||||
address = [[NSString stringWithUTF8String:linphone_address_as_string_uri_only(adr)] substringFromIndex:4];
|
||||
if ([_contactsToDisplay containsObject:address])
|
||||
continue;
|
||||
[_contactsToDisplay addObject:[NSString stringWithUTF8String:linphone_address_as_string_uri_only(adr)]];
|
||||
[_contactsToDisplay addObject:address];
|
||||
[_logIds addObject:logId];
|
||||
NSString *displayName = [NSString stringWithUTF8String:linphone_address_get_display_name(adr)];
|
||||
UIStackView *stack = _stackViews[i];
|
||||
UIButton *button = stack.subviews[1];
|
||||
UIButton *button = stack.subviews[0];
|
||||
// making rounded image
|
||||
UIImageView *imageView = button.imageView;
|
||||
imageView.layer.cornerRadius = imageView.frame.size.height / 2;
|
||||
imageView.clipsToBounds = YES;
|
||||
UILabel *name = stack.subviews[2];
|
||||
if ([self.imgs.allKeys containsObject:displayName]) {
|
||||
[button setImage:[UIImage imageWithData:[_imgs objectForKey:displayName]] forState:UIControlStateNormal];
|
||||
printf("Affichage de l'image de %s\n", displayName.UTF8String);
|
||||
}
|
||||
printf("Fin de l'affichage pour %s\n", displayName.UTF8String);
|
||||
UILabel *name = stack.subviews[1];
|
||||
if ([self.imgs.allKeys containsObject:address])
|
||||
[button setImage:[UIImage imageWithData:[_imgs objectForKey:address]] forState:UIControlStateNormal];
|
||||
[stack setAlpha:1];
|
||||
button.enabled = YES;
|
||||
[name setText:displayName];
|
||||
|
|
@ -128,9 +123,7 @@
|
|||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view from its nib.
|
||||
NSLog(@"------ LA VUE A CHARGE ------");
|
||||
_sem = dispatch_semaphore_create(0);
|
||||
_nbImgs = [NSNumber numberWithInt:0];
|
||||
[self fetchContactsInBackGroundThread];
|
||||
[self loadData];
|
||||
[self draw];
|
||||
|
|
@ -147,15 +140,9 @@
|
|||
// If an error is encountered, use NCUpdateResultFailed
|
||||
// If there's no update required, use NCUpdateResultNoData
|
||||
// If there's an update, use NCUpdateResultNewData
|
||||
NSLog(@"valeurs dans dict contacts : %i", (int)_imgs.count);
|
||||
NSLog(@"valeurs de nbImgs : %i", (int)_nbImgs.integerValue);
|
||||
/*if (_nbImgs.integerValue != _imgs.count) {
|
||||
[self draw];
|
||||
completionHandler(NCUpdateResultNoData);
|
||||
} else {
|
||||
[self draw];
|
||||
completionHandler(NCUpdateResultNoData);
|
||||
}*/
|
||||
[self fetchContactsInBackGroundThread];
|
||||
[self loadData];
|
||||
[self draw];
|
||||
completionHandler(NCUpdateResultNewData);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue