Commit efc665dc authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Adrien Béraud

UI: messages view

Enable gif animation

Change-Id: I28371de138e5b9e05303bb1c0cf7f2b63f2c68a3
parent 4f82dbcd
......@@ -351,15 +351,15 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
paragraphStyle,NSParagraphStyleAttributeName, nil];
NSAttributedString* alternativeString = [[NSAttributedString alloc] initWithString:fileName attributes:alternativeNametAttr];
result.transferedFileName.attributedAlternateTitle = alternativeString;
NSImage* image = [self getImageForFilePath:name size:MAX_TRANSFERED_IMAGE_SIZE];
NSImage* image = [self getImageForFilePath:name];
if (([name rangeOfString:@"/"].location == NSNotFound)) {
image = [self getImageForFilePath:[self getDataTransferPath:interactionID] size:MAX_TRANSFERED_IMAGE_SIZE];
image = [self getImageForFilePath:[self getDataTransferPath:interactionID]];
}
if(image != nil) {
result.transferedImage.image = [image roundCorners:14];
[result updateImageConstraint:image.size.width andHeight:image.size.height];
[result.transferedImage setAction:@selector(imagePreview:)];
[result.transferedImage setTarget:self];
result.transferedImage.image = image;
[result updateImageConstraintWithMax: MAX_TRANSFERED_IMAGE_SIZE];
[result.openImagebutton setAction:@selector(imagePreview:)];
[result.openImagebutton setTarget:self];
}
}
[result setupForInteraction:interactionID];
......@@ -525,12 +525,21 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
if( interaction.status == lrc::api::interaction::Status::TRANSFER_FINISHED) {
NSString* name = @(interaction.body.c_str());
NSImage* image = [self getImageForFilePath:name size:MAX_TRANSFERED_IMAGE_SIZE];
NSImage* image = [self getImageForFilePath:name];
if (([name rangeOfString:@"/"].location == NSNotFound)) {
image = [self getImageForFilePath:[self getDataTransferPath:it->first] size:MAX_TRANSFERED_IMAGE_SIZE];
image = [self getImageForFilePath:[self getDataTransferPath:it->first]];
}
if (image != nil) {
return image.size.height + TIME_BOX_HEIGHT;
CGFloat widthScaleFactor = MAX_TRANSFERED_IMAGE_SIZE / image.size.width;
CGFloat heightScaleFactor = MAX_TRANSFERED_IMAGE_SIZE / image.size.height;
CGFloat heigt = 0;
if((widthScaleFactor >= 1) && (heightScaleFactor >= 1)) {
heigt = image.size.height;
} else {
CGFloat scale = MIN(widthScaleFactor, heightScaleFactor);
heigt = image.size.height * scale;
}
return heigt + TIME_BOX_HEIGHT;
}
}
return BUBBLE_HEIGHT_FOR_TRANSFERED_FILE + TIME_BOX_HEIGHT;
......@@ -573,14 +582,11 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
return @(info.path.c_str());
}
-(NSImage*) getImageForFilePath: (NSString *) path size:(CGFloat)size {
-(NSImage*) getImageForFilePath: (NSString *) path {
if (path.length <= 0) {return nil;}
if (![[NSFileManager defaultManager] fileExistsAtPath: path]) {return nil;}
NSImage* transferedImage = [[NSImage alloc] initWithContentsOfFile: path];
if(transferedImage != nil) {
return [transferedImage imageResizeInsideMax: size];
}
return nil;
return transferedImage;
}
-(CGSize) sizeFor:(NSString *) message maxWidth:(CGFloat) width {
......
......@@ -33,10 +33,11 @@
@property (nonatomic, strong) IBOutlet NSBox* timeBox;
@property (nonatomic, strong) IBOutlet NSTextField* timeLabel;
@property (nonatomic, strong) IBOutlet NSButton* transferedFileName;
@property (nonatomic, strong) IBOutlet NSButton* transferedImage;
@property (nonatomic, strong) IBOutlet NSImageView* transferedImage;
@property (nonatomic, strong) IBOutlet NSProgressIndicator* sendingMessageIndicator;
@property (nonatomic, strong) IBOutlet NSImageView* messageFailed;
@property (nonatomic, strong) IBOutlet NSView* messageStatus;
@property (nonatomic, strong) IBOutlet NSButton* openImagebutton;
- (uint64_t) interaction;
......@@ -44,6 +45,7 @@
- (void) setupForInteraction:(uint64_t)inter;
- (void) updateMessageConstraint:(CGFloat) width andHeight: (CGFloat) height timeIsVisible: (bool) visible isTopPadding: (bool) padding;
- (void) updateImageConstraint: (CGFloat) width andHeight: (CGFloat) height;
- (void) updateImageConstraintWithMax: (CGFloat) maxDimension;
- (void) invalidateImageConstraints;
@end
......@@ -21,6 +21,7 @@
#import "IMTableCellView.h"
#import "NSColor+RingTheme.h"
@implementation IMTableCellView {
uint64_t interaction;
}
......@@ -34,6 +35,7 @@ NSString* const TIME_BOX_HEIGHT = @"34";
@synthesize declineButton;
@synthesize progressIndicator;
@synthesize statusLabel;
@synthesize openImagebutton;
- (void) setupDirection
{
......@@ -57,8 +59,6 @@ NSString* const TIME_BOX_HEIGHT = @"34";
[self.msgView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.msgBackground setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.msgView setEditable:NO];
[(NSButtonCell*)transferedImage.cell setShowsStateBy:NSNoCellMask];
[(NSButtonCell*)transferedImage.cell setHighlightsBy:NSNoCellMask];
acceptButton.image = [NSColor image: [NSImage imageNamed:@"ic_file_upload.png"] tintedWithColor:[NSColor greenSuccessColor]];
declineButton.image = [NSColor image: [NSImage imageNamed:@"ic_action_cancel.png"] tintedWithColor:[NSColor redColor]];
}
......@@ -130,6 +130,22 @@ NSString* const TIME_BOX_HEIGHT = @"34";
[NSLayoutConstraint activateConstraints:constraintsHorizontal];
}
- (void) updateImageConstraintWithMax: (CGFloat) maxDimension {
if(!self.transferedImage) {return;}
CGFloat widthScaleFactor = maxDimension / transferedImage.image.size.width;
CGFloat heightScaleFactor = maxDimension / transferedImage.image.size.height;
NSSize size = NSZeroSize;
if((widthScaleFactor >= 1) && (heightScaleFactor >= 1)) {
size.width = transferedImage.image.size.width;
size.height = transferedImage.image.size.height;
} else {
CGFloat scale = MIN(widthScaleFactor, heightScaleFactor);
size.width = transferedImage.image.size.width * scale;
size.height = transferedImage.image.size.height * scale;
}
[self updateImageConstraint:size.width andHeight: size.height];
}
- (void) invalidateImageConstraints {
[NSLayoutConstraint deactivateConstraints:[self.transferedImage constraints]];
}
......
......@@ -76,5 +76,12 @@
@property (nonatomic, strong) NSColor* buttonDisableColor;
/*
* Color of the button corners. Draw circle with cornerRadius filled with bgColor
* and fill corner with cornerColor
*/
@property (nonatomic, strong) NSColor* cornerColor;
@end
......@@ -123,6 +123,62 @@
NSBezierPath* ovalPath = [NSBezierPath bezierPathWithRoundedRect:dirtyRect
xRadius:[self.cornerRadius floatValue]
yRadius:[self.cornerRadius floatValue]];
if(self.cornerColor) {
NSRect frame = [self frame];
[backgroundColor setFill];
[ovalPath fill];
[NSGraphicsContext saveGraphicsState];
CGPoint top = CGPointMake(frame.size.width * 0.5, 0);
CGPoint right = CGPointMake(frame.size.width, frame.size.height * 0.5);
CGPoint bottom = CGPointMake(frame.size.width * 0.5, frame.size.height);
CGPoint left = CGPointMake(0, frame.size.height * 0.5);
CGPoint topLeft = CGPointMake(0, 0);
CGPoint topRight = CGPointMake(frame.size.width, 0);
CGPoint bottomLeft = CGPointMake(0, frame.size.height);
CGPoint bottomRight = CGPointMake(frame.size.width, frame.size.height);
NSBezierPath* topLeftPath = [[NSBezierPath alloc] init];
NSPoint pointArrayLeft[3];
pointArrayLeft[0] = left;
pointArrayLeft[1] = topLeft;
pointArrayLeft[2] = top;
[topLeftPath appendBezierPathWithPoints:pointArrayLeft count:3];
[topLeftPath appendBezierPathWithArcFromPoint: topLeft toPoint: left radius: 20.0f];
[self.cornerColor setFill];
[topLeftPath fill];
NSBezierPath* topRightPath = [[NSBezierPath alloc] init];
NSPoint pointArrayTop[3];
pointArrayTop[0] = top;
pointArrayTop[1] = topRight;
pointArrayTop[2] = right;
[topRightPath appendBezierPathWithPoints:pointArrayTop count:3];
[topRightPath appendBezierPathWithArcFromPoint: topRight toPoint: top radius: 20.0f];
[topRightPath fill];
NSBezierPath* bottomLeftPath = [[NSBezierPath alloc] init];
NSPoint pointArrayRight[3];
pointArrayRight[0] = right;
pointArrayRight[1] = bottomRight;
pointArrayRight[2] = bottom;
[bottomLeftPath appendBezierPathWithPoints:pointArrayRight count:3];
[bottomLeftPath appendBezierPathWithArcFromPoint: bottomRight toPoint: right radius: 20.0f];
[bottomLeftPath fill];
NSBezierPath* bottomRightPath = [[NSBezierPath alloc] init];
NSPoint pointArrayBottom[3];
pointArrayBottom[0] = bottom;
pointArrayBottom[1] = bottomLeft;
pointArrayBottom[2] = left;
[bottomRightPath appendBezierPathWithPoints:pointArrayBottom count:3];
[bottomRightPath appendBezierPathWithArcFromPoint: bottomLeft toPoint: bottom radius: 20.0f];
[bottomRightPath fill];
[NSGraphicsContext saveGraphicsState];
return;
}
[backgroundColor setFill];
[ovalPath fill];
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment