Commit a0f16868 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

UI/UX: messages

- remove timelines
- change failed messages ui
- remove empty lines in the messages
- support urls

Change-Id: I100665ec7839261fda07f70ad9bac121af3d7083
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 252a94ab
......@@ -21,6 +21,7 @@
#import "ChatVC.h"
#import "MessagesVC.h"
#import "NSString+Extensions.h"
@interface ChatVC ()
{
......@@ -62,6 +63,10 @@
[self.view.window makeFirstResponder:self.messageField];
}
- (void)setMessage:(NSString *)newValue {
_message = [newValue removeEmptyLinesAtBorders];
}
- (IBAction)sendMessage:(id)sender {
/* make sure there is text to send */
NSString* text = self.message;
......
......@@ -41,6 +41,7 @@
#import "MessagesVC.h"
#import "utils.h"
#import "RingWindowController.h"
#import "NSString+Extensions.h"
#import <QuartzCore/QuartzCore.h>
......@@ -88,6 +89,10 @@
return self;
}
- (void)setMessage:(NSString *)newValue {
_message = [newValue removeEmptyLinesAtBorders];
}
-(void) clearData {
cachedConv_ = nil;
convUid_ = "";
......
......@@ -35,6 +35,7 @@
#import "delegates/ImageManipulationDelegate.h"
#import "utils.h"
#import "views/NSColor+RingTheme.h"
#import "NSString+Extensions.h"
@interface MessagesVC () <NSTableViewDelegate, NSTableViewDataSource> {
......@@ -314,7 +315,7 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
switch (status) {
[result.statusLabel setTextColor:[NSColor textColor]];
case lrc::api::interaction::Status::TRANSFER_FINISHED:
[result.statusLabel setTextColor:[NSColor greenColor]];
[result.statusLabel setTextColor:[NSColor greenSuccessColor]];
[result.statusLabel setStringValue:NSLocalizedString(@"Success", @"File transfer successful label")];
break;
case lrc::api::interaction::Status::TRANSFER_CANCELED:
......@@ -322,7 +323,7 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
[result.statusLabel setStringValue:NSLocalizedString(@"Canceled", @"File transfer canceled label")];
break;
case lrc::api::interaction::Status::TRANSFER_ERROR:
[result.statusLabel setTextColor:[NSColor redColor]];
[result.statusLabel setTextColor:[NSColor errorTransferColor]];
[result.statusLabel setStringValue:NSLocalizedString(@"Failed", @"File transfer failed label")];
break;
case lrc::api::interaction::Status::TRANSFER_UNJOINABLE_PEER:
......@@ -427,23 +428,56 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
type = LAST;
}
result.msgBackground.type = type;
[result setupForInteraction:it->first];
bool sendingFail = false;
[result.messageStatus setHidden:YES];
if (interaction.type == lrc::api::interaction::Type::TEXT && isOutgoing) {
if (interaction.status == lrc::api::interaction::Status::SENDING) {
[result.messageStatus setHidden:NO];
[result.sendingMessageIndicator startAnimation:nil];
[result.messageFailed setHidden:YES];
} else if (interaction.status == lrc::api::interaction::Status::FAILED) {
[result.messageStatus setHidden:NO];
[result.sendingMessageIndicator setHidden:YES];
[result.messageFailed setHidden:NO];
sendingFail = true;
}
}
[result setupForInteraction:it->first isFailed: sendingFail];
bool shouldDisplayTime = (sequence == FIRST_WITH_TIME || sequence == SINGLE_WITH_TIME) ? YES : NO;
bool shouldApplyPadding = (sequence == FIRST_WITHOUT_TIME || sequence == SINGLE_WITHOUT_TIME) ? YES : NO;
[result.msgBackground setNeedsDisplay:YES];
[result setNeedsDisplay:YES];
[result.timeBox setNeedsDisplay:YES];
NSString *text = @(interaction.body.c_str());
text = [text removeEmptyLinesAtBorders];
NSMutableAttributedString* msgAttString =
[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",@(interaction.body.c_str())]
[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:text]
attributes:[self messageAttributes]];
CGSize messageSize = [self sizeFor: @(interaction.body.c_str()) maxWidth:tableView.frame.size.width * 0.7];
CGSize messageSize = [self sizeFor: text maxWidth:tableView.frame.size.width * 0.7];
[result updateMessageConstraint:messageSize.width andHeight:messageSize.height timeIsVisible:shouldDisplayTime isTopPadding: shouldApplyPadding];
[[result.msgView textStorage] appendAttributedString:msgAttString];
[result.msgView checkTextInDocument:nil];
NSDataDetector *linkDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [linkDetector matchesInString:result.msgView.string options:0 range:NSMakeRange(0, result.msgView.string.length)];
[result.msgView.textStorage beginEditing];
for (NSTextCheckingResult *match in matches) {
if (!match.URL) continue;
NSDictionary *linkAttributes = @{
NSLinkAttributeName: match.URL,
};
[result.msgView.textStorage addAttributes:linkAttributes range:match.range];
}
[result.msgView.textStorage endEditing];
if (shouldDisplayTime) {
NSDate* msgTime = [NSDate dateWithTimeIntervalSince1970:interaction.timestamp];
NSString* timeString = [self timeForMessage: msgTime];
......@@ -457,18 +491,6 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
auto& imageManip = reinterpret_cast<Interfaces::ImageManipulationDelegate&>(GlobalInstances::pixmapManipulator());
[result.photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(imageManip.conversationPhoto(*conv, convModel_->owner)))];
}
[result.messageStatus setHidden:YES];
if (interaction.type == lrc::api::interaction::Type::TEXT && isOutgoing) {
if (interaction.status == lrc::api::interaction::Status::SENDING) {
[result.messageStatus setHidden:NO];
[result.sendingMessageIndicator startAnimation:nil];
[result.messageFailed setHidden:YES];
} else if (interaction.status == lrc::api::interaction::Status::FAILED) {
[result.messageStatus setHidden:NO];
[result.sendingMessageIndicator setHidden:YES];
[result.messageFailed setHidden:NO];
}
}
return result;
}
......@@ -515,7 +537,10 @@ typedef NS_ENUM(NSInteger, MessageSequencing) {
return 0;
}
CGSize messageSize = [self sizeFor: @(interaction.body.c_str()) maxWidth:tableView.frame.size.width * 0.7];
NSString *text = @(interaction.body.c_str());
text = [text removeEmptyLinesAtBorders];
CGSize messageSize = [self sizeFor: text maxWidth:tableView.frame.size.width * 0.7];
CGFloat singleLignMessageHeight = 15;
bool shouldApplyPadding = (sequence == FIRST_WITHOUT_TIME || sequence == SINGLE_WITHOUT_TIME) ? YES : NO;
......
......@@ -35,11 +35,12 @@
@property (nonatomic, strong) IBOutlet NSTextField* transferedFileName;
@property (nonatomic, strong) IBOutlet NSImageView* transferedImage;
@property (nonatomic, strong) IBOutlet NSProgressIndicator* sendingMessageIndicator;
@property (nonatomic, strong) IBOutlet NSTextField* messageFailed;
@property (nonatomic, strong) IBOutlet NSImageView* messageFailed;
@property (nonatomic, strong) IBOutlet NSView* messageStatus;
- (uint64_t) interaction;
- (void) setupForInteraction:(uint64_t)inter isFailed:(bool) failed;
- (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;
......
......@@ -40,6 +40,7 @@ NSString* const TIME_BOX_HEIGHT = @"34";
if ([self.identifier containsString:@"Right"]) {
self.msgBackground.pointerDirection = RIGHT;
self.msgBackground.bgColor = [NSColor ringLightBlue];
self.messageFailed.image = [NSColor image: [NSImage imageNamed:@"ic_action_cancel.png"] tintedWithColor:[[NSColor errorColor] lightenColorByValue:0.05]];
}
else {
self.msgBackground.pointerDirection = LEFT;
......@@ -55,11 +56,19 @@ NSString* const TIME_BOX_HEIGHT = @"34";
[self.msgView setString:@""];
[self.msgView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.msgBackground setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.msgView setEnabledTextCheckingTypes:NSTextCheckingTypeLink];
[self.msgView setAutomaticLinkDetectionEnabled:YES];
[self.msgView setEditable:NO];
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]];
}
- (void) setupForInteraction:(uint64_t)inter isFailed:(bool) failed {
[self setupForInteraction:inter];
if (failed) {
self.msgBackground.bgColor = [[NSColor errorColor] lightenColorByValue:0.2];
}
}
- (void) updateMessageConstraint:(CGFloat) width andHeight: (CGFloat) height timeIsVisible: (bool) visible isTopPadding: (bool) padding
{
[NSLayoutConstraint deactivateConstraints:[self.msgView constraints]];
......
......@@ -30,6 +30,9 @@
+ (NSColor*) ringGreyHighlight;
+ (NSColor*) ringGreyLight;
+ (NSColor*) ringDarkGrey;
+ (NSColor*) errorColor;
+ (NSColor*) greenSuccessColor;
+ (NSColor*) errorTransferColor;
- (NSColor *)lightenColorByValue:(float)value;
- (NSColor *)darkenColorByValue:(float)value;
......
......@@ -56,6 +56,21 @@
return [NSColor colorWithCalibratedRed:59/255.0 green:193/255.0 blue:211/255.0 alpha:0.3];
}
+ (NSColor*) errorColor
{
return [NSColor colorWithCalibratedRed:255/255.0 green:102/255.0 blue:102/255.0 alpha:1];
}
+ (NSColor*) errorTransferColor
{
return [NSColor colorWithCalibratedRed:204/255.0 green:51/255.0 blue:51/255.0 alpha:1];
}
+ (NSColor*) greenSuccessColor
{
return [NSColor colorWithCalibratedRed:0/255.0 green:178/255.0 blue:11/255.0 alpha:1];
}
- (NSColor *)lightenColorByValue:(float)value {
float red = [self redComponent];
red += value;
......
This diff is collapsed.
This diff is collapsed.
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