From ce97c85cc8bc7aab4ee904c65f775a72ddfd8914 Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Tue, 5 Oct 2021 07:15:35 +0200 Subject: [PATCH] Fix display of file attachment icons in reply bubbles --- Classes/ChatConversationView.m | 2 +- Classes/LinphoneUI/UIChatBubblePhotoCell.m | 2 +- Classes/LinphoneUI/UIChatBubbleTextCell.h | 5 +-- Classes/LinphoneUI/UIChatBubbleTextCell.m | 10 +++--- Classes/LinphoneUI/UIChatContentView.m | 4 +-- Classes/LinphoneUI/UIChatReplyBubbleView.m | 2 +- Classes/SwiftUtil.swift | 36 ++++++++++++---------- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 0761a3c08..40e86856f 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -1592,7 +1592,7 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog NSFileCoordinator *co =[[NSFileCoordinator alloc] init]; NSError *error = nil; [co coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL * _Nonnull newURL) { - UIImage *image = [UIChatBubbleTextCell getImageFromFileName:[newURL lastPathComponent]]; + UIImage *image = [UIChatBubbleTextCell getImageFromFileName:[newURL lastPathComponent] forReplyBubble:false]; [_fileContext addObject:[NSData dataWithContentsOfURL:newURL] name:[newURL lastPathComponent] type:@"file" image:image]; [self refreshImageDrawer]; }]; diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m index f94ea00d7..ccf47d7aa 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m @@ -140,7 +140,7 @@ } - (void) loadFileAsset:(NSString *)name { - UIImage *image = [UIChatBubbleTextCell getImageFromFileName:name]; + UIImage *image = [UIChatBubbleTextCell getImageFromFileName:name forReplyBubble:false]; [self loadImageAsset:nil image:image]; _imageGestureRecognizer.enabled = YES; _finalImage.tag = FILE_ICON_TAG; diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.h b/Classes/LinphoneUI/UIChatBubbleTextCell.h index fe729b670..6b583ecac 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.h +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.h @@ -76,8 +76,9 @@ + (CGSize)ViewHeightForMessageText:(LinphoneChatMessage *)chat withWidth:(int)width textForImdn:(NSString *)imdnText; + (CGSize)getMediaMessageSizefromOriginalSize:(CGSize)originalSize withWidth:(int)width; + (UIImage *)getImageFromVideoUrl:(NSURL *)url; -+ (UIImage *)getImageFromContent:(LinphoneContent *)content filePath:(NSString *)filePath; -+ (UIImage *)getImageFromFileName:(NSString *)fileName; ++ (UIImage *)getImageFromContent:(LinphoneContent *)content filePath:(NSString *)filePath forReplyBubble:(BOOL)forReplyBubble; ++ (UIImage *)getImageFromFileName:(NSString *)fileName forReplyBubble:(BOOL)forReplyBubbble; + - (void)setEvent:(LinphoneEventLog *)event; - (void)setChatMessageForCbs:(LinphoneChatMessage *)message; diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 500479018..4038ac799 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -396,7 +396,7 @@ static const CGFloat REPLY_OR_FORWARD_TAG_HEIGHT = 18; utilityPlayer = nil; } -+ (UIImage *)getImageFromFileName:(NSString *)fileName { ++ (UIImage *)getImageFromFileName:(NSString *)fileName forReplyBubble:(BOOL)forReplyBubbble { NSString *extension = [[fileName.lowercaseString componentsSeparatedByString:@"."] lastObject]; UIImage *image; NSString * text = fileName; @@ -416,10 +416,10 @@ static const CGFloat REPLY_OR_FORWARD_TAG_HEIGHT = 18; image = [UIImage imageNamed:@"file_default"]; } - return [SwiftUtil textToImageWithDrawText:text inImage:image]; + return [SwiftUtil textToImageWithDrawText:text inImage:image forReplyBubble:forReplyBubbble]; } -+ (UIImage *)getImageFromContent:(LinphoneContent *)content filePath:(NSString *)filePath; { ++ (UIImage *)getImageFromContent:(LinphoneContent *)content filePath:(NSString *)filePath forReplyBubble:(BOOL)forReplyBubble { NSString *type = [NSString stringWithUTF8String:linphone_content_get_type(content)]; NSString *name = [NSString stringWithUTF8String:linphone_content_get_name(content)]; if (!filePath) { @@ -434,7 +434,7 @@ static const CGFloat REPLY_OR_FORWARD_TAG_HEIGHT = 18; image = [[UIImage alloc] initWithData:data]; } if (image) return image; - else return [self getImageFromFileName:name]; + else return [self getImageFromFileName:name forReplyBubble:forReplyBubble]; } +(LinphoneContent *) voiceContent:(LinphoneChatMessage *)message { @@ -536,7 +536,7 @@ static const CGFloat REPLY_OR_FORWARD_TAG_HEIGHT = 18; filePath = [LinphoneManager validFilePath:name]; } - image = [UIChatBubbleTextCell getImageFromContent:content filePath:filePath]; + image = [UIChatBubbleTextCell getImageFromContent:content filePath:filePath forReplyBubble:false]; } if (image) { CGSize sSize = [self getMediaMessageSizefromOriginalSize:image.size withWidth:IMAGE_DEFAULT_WIDTH]; diff --git a/Classes/LinphoneUI/UIChatContentView.m b/Classes/LinphoneUI/UIChatContentView.m index 3b5713e94..f43467ccc 100644 --- a/Classes/LinphoneUI/UIChatContentView.m +++ b/Classes/LinphoneUI/UIChatContentView.m @@ -32,7 +32,7 @@ if(!linphone_chat_message_is_outgoing(_message) && linphone_content_is_file_transfer(_content)) { // has not yet downloaded NSString *name = [NSString stringWithUTF8String:linphone_content_get_name(content)] ; - UIImage *image = [UIChatBubbleTextCell getImageFromFileName:name]; + UIImage *image = [UIChatBubbleTextCell getImageFromFileName:name forReplyBubble:false]; [self setImage:image]; _downloadButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_downloadButton addTarget:self @@ -51,7 +51,7 @@ NSString *name = [NSString stringWithUTF8String:linphone_content_get_name(content)]; _filePath = [LinphoneManager validFilePath:name]; } - UIImage *image = [UIChatBubbleTextCell getImageFromContent:content filePath:_filePath]; + UIImage *image = [UIChatBubbleTextCell getImageFromContent:content filePath:_filePath forReplyBubble:false]; [self setImage:image]; UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onMultiPartClick:)]; tapGestureRecognizer.numberOfTapsRequired = 1; diff --git a/Classes/LinphoneUI/UIChatReplyBubbleView.m b/Classes/LinphoneUI/UIChatReplyBubbleView.m index e6e523561..a63a7dc47 100644 --- a/Classes/LinphoneUI/UIChatReplyBubbleView.m +++ b/Classes/LinphoneUI/UIChatReplyBubbleView.m @@ -124,7 +124,7 @@ if (filePath == NULL) { filePath = [LinphoneManager validFilePath:name]; } - [result addObject:[UIChatBubbleTextCell getImageFromContent:content filePath:filePath]]; + [result addObject:[UIChatBubbleTextCell getImageFromContent:content filePath:filePath forReplyBubble:true]]; } return result; } diff --git a/Classes/SwiftUtil.swift b/Classes/SwiftUtil.swift index ff9278263..12fd20012 100644 --- a/Classes/SwiftUtil.swift +++ b/Classes/SwiftUtil.swift @@ -21,10 +21,10 @@ import UIKit @objc class SwiftUtil: NSObject { - @objc static func textToImage(drawText text: String, inImage image: UIImage) -> UIImage { + @objc static func textToImage(drawText text: String, inImage image: UIImage, forReplyBubble:Bool) -> UIImage { let textColor = UIColor.black - let fontMax = UIFont.systemFont(ofSize: 30) - let backgroundColor = UIColor.white + let fontMax = UIFont.systemFont(ofSize: 12) + let backgroundColor = forReplyBubble ? UIColor(red: 246/255.0, green: 246/255.0, blue: 246/255.0, alpha: 1.0) : UIColor.white let size = CGSize(width: 120, height: 120) @@ -34,22 +34,24 @@ import UIKit backgroundColor.setFill() context!.fill(CGRect(x: 0, y: 0, width: size.width, height: size.height)) - image.draw(in: CGRect(origin: CGPoint(x: size.width/2 - (image.size.width)/2,y: 5), size: image.size)) + let imageSize:CGSize = forReplyBubble ? CGSize(width: 80, height:80*(image.size.height / image.size.width)): image.size - let label = UILabel(frame: CGRect(x: 0,y: 0,width: size.width,height: 50)) - label.numberOfLines = 0 - label.font = fontMax - label.adjustsFontSizeToFitWidth = true - label.text = text - label.textColor = textColor - label.textAlignment = .center - label.allowsDefaultTighteningForTruncation = true - label.lineBreakMode = .byTruncatingTail - imageWithLabel(label: label).draw(in: CGRect(origin: CGPoint(x:0,y: 60), size: CGSize(width: size.width,height: 50))) - let view = UIView(frame: CGRect(x: 0,y: 0,width: size.width,height: 50)) - view.addSubview(label) - label.sizeToFit() + image.draw(in: CGRect(origin: CGPoint(x: size.width/2 - (imageSize.width)/2,y: (forReplyBubble ? size.height/2 : 90/2) - (imageSize.height)/2), size: imageSize)) + if (!forReplyBubble) { + let label = UILabel(frame: CGRect(x: 0,y: 0,width: size.width,height: 30)) + label.numberOfLines = 1 + label.font = fontMax + label.adjustsFontSizeToFitWidth = false + label.text = text + label.textColor = textColor + label.textAlignment = .center + label.allowsDefaultTighteningForTruncation = true + label.lineBreakMode = .byTruncatingMiddle + imageWithLabel(label: label).draw(in: CGRect(origin: CGPoint(x:5,y: 70), size: CGSize(width: size.width-10,height: 30))) + let view = UIView(frame: CGRect(x: 0,y: 0,width: size.width,height: 30)) + view.addSubview(label) + } let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext()