From 650ff361aec4344187899b613d6ee9d1d723435a Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Mon, 3 Dec 2012 15:55:10 +0100 Subject: [PATCH] Improve avatar loading --- Classes/ChatRoomViewController.m | 4 ++-- Classes/HistoryDetailsViewController.m | 2 +- Classes/IncomingCallViewController.m | 20 ++++++++++++-------- Classes/LinphoneUI/UICallCell.m | 6 ++++-- Classes/LinphoneUI/UIChatRoomCell.m | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Classes/ChatRoomViewController.m b/Classes/ChatRoomViewController.m index 0915a4abe..a776b2622 100644 --- a/Classes/ChatRoomViewController.m +++ b/Classes/ChatRoomViewController.m @@ -348,7 +348,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta - (void)saveAndSend:(UIImage*)image url:(NSURL*)url { if(url == nil) { [waitView setHidden:FALSE]; - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [[LinphoneManager instance].photoLibrary writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){ @@ -381,7 +381,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta [waitView setHidden:FALSE]; DTActionSheet *sheet = [[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Choose the image size", nil)]; - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //UIImage *image = [original_image normalizedImage]; for(NSString *key in [imageQualities allKeys]) { NSNumber *number = [imageQualities objectForKey:key]; diff --git a/Classes/HistoryDetailsViewController.m b/Classes/HistoryDetailsViewController.m index 58b480b51..553f8e38c 100644 --- a/Classes/HistoryDetailsViewController.m +++ b/Classes/HistoryDetailsViewController.m @@ -183,7 +183,7 @@ static UICompositeViewDescription *compositeDescription = nil; NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:lAddress]]; contact = [[[LinphoneManager instance] fastAddressBook] getContact:normalizedSipAddress]; if(contact) { - image = [FastAddressBook getContactImage:contact thumbnail:false]; + image = [FastAddressBook getContactImage:contact thumbnail:true]; address = [FastAddressBook getContactDisplayName:contact]; useLinphoneAddress = false; } diff --git a/Classes/IncomingCallViewController.m b/Classes/IncomingCallViewController.m index c3f3d6d72..e008d5c09 100644 --- a/Classes/IncomingCallViewController.m +++ b/Classes/IncomingCallViewController.m @@ -21,6 +21,7 @@ #import "LinphoneManager.h" #import "FastAddressBook.h" #import "PhoneMainView.h" +#import "UILinphone.h" @implementation IncomingCallViewController @@ -113,7 +114,8 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)update { [self view]; //Force view load - UIImage *image = nil; + [avatarImage setImage:[UIImage imageNamed:@"avatar_unknown.png"]]; + NSString* address = nil; const LinphoneAddress* addr = linphone_call_get_remote_address(call); if (addr != NULL) { @@ -124,7 +126,15 @@ static UICompositeViewDescription *compositeDescription = nil; NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:lAddress]]; ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:normalizedSipAddress]; if(contact) { - image = [FastAddressBook getContactImage:contact thumbnail:false]; + UIImage *tmpImage = [FastAddressBook getContactImage:contact thumbnail:false]; + if(tmpImage != nil) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { + UIImage *tmpImage2 = [UIImage decodedImageWithImage:tmpImage]; + dispatch_async(dispatch_get_main_queue(), ^{ + avatarImage.image = tmpImage2; + }); + }); + } address = [FastAddressBook getContactDisplayName:contact]; useLinphoneAddress = false; } @@ -140,12 +150,6 @@ static UICompositeViewDescription *compositeDescription = nil; } } - // Set Image - if(image == nil) { - image = [UIImage imageNamed:@"avatar_unknown.png"]; - } - [avatarImage setImage:image]; - // Set Address if(address == nil) { address = @"Unknown"; diff --git a/Classes/LinphoneUI/UICallCell.m b/Classes/LinphoneUI/UICallCell.m index 69e4e9ee6..8d69976d7 100644 --- a/Classes/LinphoneUI/UICallCell.m +++ b/Classes/LinphoneUI/UICallCell.m @@ -61,9 +61,11 @@ self.address = [FastAddressBook getContactDisplayName:contact]; UIImage *tmpImage = [FastAddressBook getContactImage:contact thumbnail:false]; if(tmpImage != nil) { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, (unsigned long)NULL), ^(void) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { UIImage *tmpImage2 = [UIImage decodedImageWithImage:tmpImage]; - self.image = tmpImage2; + dispatch_async(dispatch_get_main_queue(), ^{ + [self setImage: tmpImage2]; + }); }); } } diff --git a/Classes/LinphoneUI/UIChatRoomCell.m b/Classes/LinphoneUI/UIChatRoomCell.m index d23d732ed..067cd5c78 100644 --- a/Classes/LinphoneUI/UIChatRoomCell.m +++ b/Classes/LinphoneUI/UIChatRoomCell.m @@ -127,7 +127,7 @@ static UIFont *CELL_FONT = nil; [messageImageView startLoading]; ChatModel *achat = chat; [[LinphoneManager instance].photoLibrary assetForURL:[NSURL URLWithString:[chat message]] resultBlock:^(ALAsset *asset) { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, (unsigned long)NULL), ^(void) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { ALAssetRepresentation* representation = [asset defaultRepresentation]; UIImage *image = [UIImage imageWithCGImage:[representation fullResolutionImage] scale:representation.scale