forked from mirrors/linphone-iphone
Fix display of file attachment icons in reply bubbles
This commit is contained in:
parent
7c3e20cd54
commit
ce97c85cc8
7 changed files with 32 additions and 29 deletions
|
|
@ -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];
|
||||
}];
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue