Improve avatar loading

This commit is contained in:
Yann Diorcet 2012-12-03 15:55:10 +01:00
parent f63bd03569
commit 650ff361ae
5 changed files with 20 additions and 14 deletions

View file

@ -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];

View file

@ -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;
}

View file

@ -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";

View file

@ -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];
});
});
}
}

View file

@ -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