forked from mirrors/linphone-iphone
display as file if can not load image
This commit is contained in:
parent
947ec611de
commit
46fefb6988
2 changed files with 34 additions and 17 deletions
|
|
@ -114,7 +114,9 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
}];
|
||||
}
|
||||
|
||||
- (void) loadFileAsset {
|
||||
- (void) loadFileAsset:(NSString *)name {
|
||||
NSString *text = [NSString stringWithFormat:@"📎 %@",name];
|
||||
_fileName.text = text;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
_fileName.hidden = _fileView.hidden = _fileButton.hidden = NO;
|
||||
_imageGestureRecognizer.enabled = NO;
|
||||
|
|
@ -170,14 +172,24 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
if (_messageImageView.image == nil) {
|
||||
NSData* data = [NSData dataWithContentsOfFile:filePath];
|
||||
UIImage *image = [[UIImage alloc] initWithData:data];
|
||||
[self loadImageAsset:nil image:image];
|
||||
_imageGestureRecognizer.enabled = YES;
|
||||
if (image) {
|
||||
[self loadImageAsset:nil image:image];
|
||||
_imageGestureRecognizer.enabled = YES;
|
||||
} else {
|
||||
// compability with other platforms
|
||||
[self loadFileAsset:fileName];
|
||||
}
|
||||
}
|
||||
} else if ([key isEqualToString:@"localvideo"]) {
|
||||
if (_messageImageView.image == nil) {
|
||||
UIImage* image = [UIChatBubbleTextCell getImageFromVideoUrl:[ChatConversationView getCacheFileUrl:fileName]];
|
||||
[self loadImageAsset:nil image:image];
|
||||
_imageGestureRecognizer.enabled = NO;
|
||||
if (image) {
|
||||
[self loadImageAsset:nil image:image];
|
||||
_imageGestureRecognizer.enabled = NO;
|
||||
} else {
|
||||
// compability with other platforms
|
||||
[self loadFileAsset:fileName];
|
||||
}
|
||||
}
|
||||
} else if ([key isEqualToString:@"localfile"]) {
|
||||
if ([fileType isEqualToString:@"video"]) {
|
||||
|
|
@ -190,9 +202,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
[self loadImageAsset:nil image:image];
|
||||
_imageGestureRecognizer.enabled = YES;
|
||||
} else {
|
||||
NSString *text = [NSString stringWithFormat:@"📎 %@",fileName];
|
||||
_fileName.text = text;
|
||||
[self loadFileAsset];
|
||||
[self loadFileAsset:fileName];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -279,9 +289,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
[self loadImageAsset:nil image:image];
|
||||
_imageGestureRecognizer.enabled = YES;
|
||||
} else {
|
||||
NSString *text = [NSString stringWithFormat:@"📎 %@",localFile];
|
||||
_fileName.text = text;
|
||||
[self loadFileAsset];
|
||||
[self loadFileAsset:fileName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -363,6 +363,14 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
return [self ViewHeightForMessageText:chat withWidth:width textForImdn:nil];
|
||||
}
|
||||
|
||||
+ (CGSize)ViewHeightForFile:(int)width {
|
||||
CGSize fileSize = CGSizeMake(230, 50);
|
||||
CGSize size = [self getMediaMessageSizefromOriginalSize:fileSize withWidth:width];
|
||||
size.width = MAX(size.width + CELL_MESSAGE_X_MARGIN, CELL_MIN_WIDTH);
|
||||
size.height = MAX(size.height + CELL_MESSAGE_Y_MARGIN, CELL_MIN_HEIGHT);
|
||||
return size;
|
||||
}
|
||||
|
||||
+ (CGSize)ViewHeightForMessageText:(LinphoneChatMessage *)chat withWidth:(int)width textForImdn:(NSString *)imdnText{
|
||||
NSString *messageText = [UIChatBubbleTextCell TextMessageForChat:chat];
|
||||
static UIFont *messageFont = nil;
|
||||
|
|
@ -423,12 +431,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
image = [[UIImage alloc] initWithData:data];
|
||||
}
|
||||
} else {
|
||||
// other files // todo for text
|
||||
CGSize fileSize = CGSizeMake(230, 50);
|
||||
size = [self getMediaMessageSizefromOriginalSize:fileSize withWidth:width];
|
||||
size.width = MAX(size.width + CELL_MESSAGE_X_MARGIN, CELL_MIN_WIDTH);
|
||||
size.height = MAX(size.height + CELL_MESSAGE_Y_MARGIN, CELL_MIN_HEIGHT);
|
||||
return size;
|
||||
return [self ViewHeightForFile:width];
|
||||
}
|
||||
|
||||
originalImageSize = image.size;
|
||||
|
|
@ -441,9 +444,15 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
|
|||
if (localImage && [[NSFileManager defaultManager] fileExistsAtPath:[[LinphoneManager cacheDirectory] stringByAppendingPathComponent:localImage]]) {
|
||||
NSData* data = [ChatConversationView getCacheFileData:localImage];
|
||||
UIImage *image = [[UIImage alloc] initWithData:data];
|
||||
if (!image) {
|
||||
return [self ViewHeightForFile:width];
|
||||
}
|
||||
originalImageSize = image.size;
|
||||
} else if (localVideo && [[NSFileManager defaultManager] fileExistsAtPath:[[LinphoneManager cacheDirectory] stringByAppendingPathComponent:localVideo]]) {
|
||||
UIImage *image = [UIChatBubbleTextCell getImageFromVideoUrl:[ChatConversationView getCacheFileUrl:localVideo]];
|
||||
if (!image) {
|
||||
return [self ViewHeightForFile:width];
|
||||
}
|
||||
originalImageSize = image.size;
|
||||
} else {
|
||||
// support previous versions
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue