blob: 365837d625f90eb0f343a2485b36ac330e2f1f2f [file] [log] [blame]
Alexandre Lision0f66bd32016-01-18 11:30:45 -05001/*
Anthony Léonarde7d62ed2018-01-25 10:51:47 -05002 * Copyright (C) 2016-2018 Savoir-faire Linux Inc.
Alexandre Lision0f66bd32016-01-18 11:30:45 -05003 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Anthony Léonarde7d62ed2018-01-25 10:51:47 -05004 * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
Alexandre Lision0f66bd32016-01-18 11:30:45 -05005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#import "IMTableCellView.h"
Alexandre Lision0f66bd32016-01-18 11:30:45 -050022#import "NSColor+RingTheme.h"
23
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050024@implementation IMTableCellView {
25 uint64_t interaction;
26}
27
Kateryna Kostiukae660fd2018-04-24 14:10:41 -040028NSString* const MESSAGE_MARGIN = @"10";
29NSString* const TIME_BOX_HEIGHT = @"34";
30
31@synthesize msgView, msgBackground, timeBox, transferedImage;
Alexandre Lision0f66bd32016-01-18 11:30:45 -050032@synthesize photoView;
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050033@synthesize acceptButton;
34@synthesize declineButton;
35@synthesize progressIndicator;
36@synthesize statusLabel;
Alexandre Lision0f66bd32016-01-18 11:30:45 -050037
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050038- (void) setupDirection
Alexandre Lision0f66bd32016-01-18 11:30:45 -050039{
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050040 if ([self.identifier containsString:@"Right"]) {
Kateryna Kostiuk58276bc2017-06-07 08:50:48 -040041 self.msgBackground.pointerDirection = RIGHT;
Kateryna Kostiuk33089872017-07-14 16:43:59 -040042 self.msgBackground.bgColor = [NSColor ringLightBlue];
Alexandre Lision0f66bd32016-01-18 11:30:45 -050043 }
Kateryna Kostiuk58276bc2017-06-07 08:50:48 -040044 else {
45 self.msgBackground.pointerDirection = LEFT;
46 self.msgBackground.bgColor = [NSColor whiteColor];
47 }
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050048}
49
50- (void) setupForInteraction:(uint64_t)inter
51{
52 interaction = inter;
53 [self setupDirection];
Kateryna Kostiuk58276bc2017-06-07 08:50:48 -040054 [self.msgView setBackgroundColor:[NSColor clearColor]];
Alexandre Lision0f66bd32016-01-18 11:30:45 -050055 [self.msgView setString:@""];
Kateryna Kostiukae660fd2018-04-24 14:10:41 -040056 [self.msgView setTranslatesAutoresizingMaskIntoConstraints:NO];
57 [self.msgBackground setTranslatesAutoresizingMaskIntoConstraints:NO];
Alexandre Lision0f66bd32016-01-18 11:30:45 -050058 [self.msgView setEnabledTextCheckingTypes:NSTextCheckingTypeLink];
59 [self.msgView setAutomaticLinkDetectionEnabled:YES];
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050060 [self.msgView setEditable:NO];
Anthony Léonarde7d62ed2018-01-25 10:51:47 -050061}
Alexandre Lision0f66bd32016-01-18 11:30:45 -050062
Kateryna Kostiukae660fd2018-04-24 14:10:41 -040063- (void) updateMessageConstraint:(CGFloat) width andHeight: (CGFloat) height timeIsVisible: (bool) visible
Alexandre Lision0f66bd32016-01-18 11:30:45 -050064{
Kateryna Kostiukae660fd2018-04-24 14:10:41 -040065 [NSLayoutConstraint deactivateConstraints:[self.msgView constraints]];
66 [NSLayoutConstraint deactivateConstraints:[self.timeBox constraints]];
67 NSString* formatWidth = [NSString stringWithFormat:@"H:|-%@-[msgView(==%@)]-%@-|",
68 MESSAGE_MARGIN,[NSString stringWithFormat:@"%f", width],
69 MESSAGE_MARGIN];
70 NSString* formatHeight = [NSString stringWithFormat:@"V:[msgView(==%@)]",
71 [NSString stringWithFormat:@"%f", height]];
Alexandre Lision0f66bd32016-01-18 11:30:45 -050072
Kateryna Kostiukae660fd2018-04-24 14:10:41 -040073 NSArray* constraintsMessageHorizontal = [NSLayoutConstraint
74 constraintsWithVisualFormat:formatWidth
75 options:NSLayoutFormatAlignAllCenterY
76 metrics:nil views:NSDictionaryOfVariableBindings(msgView)];
77 NSArray* constraintsMessageVertical = [NSLayoutConstraint
78 constraintsWithVisualFormat:formatHeight
79 options:0
80 metrics:nil views:NSDictionaryOfVariableBindings(msgView)];
81
82 NSLayoutConstraint* centerMessageConstraint =[NSLayoutConstraint constraintWithItem:msgView
83 attribute:NSLayoutAttributeCenterY
84 relatedBy:NSLayoutRelationEqual
85 toItem:msgView.superview
86 attribute:NSLayoutAttributeCenterY
87 multiplier:1.f constant:0.f];
88
89 NSString* formatTime = [NSString stringWithFormat:@"V:[timeBox(%@)]", TIME_BOX_HEIGHT];
90 [self.timeBox setHidden:NO];
91 if (!visible) {
92 formatTime = [NSString stringWithFormat:@"V:[timeBox(1)]"];
93 [self.timeBox setHidden:YES];
94 }
95 NSArray* constraintsVerticalTimeBox = [NSLayoutConstraint
96 constraintsWithVisualFormat:formatTime
97 options:0
98 metrics:nil views:NSDictionaryOfVariableBindings(timeBox)];
99 NSArray* constraints = [[[constraintsMessageHorizontal arrayByAddingObjectsFromArray:constraintsMessageVertical]
100 arrayByAddingObject:centerMessageConstraint] arrayByAddingObjectsFromArray:constraintsVerticalTimeBox];
101 [NSLayoutConstraint activateConstraints:constraints];
102}
103
104- (void) updateImageConstraint: (CGFloat) width andHeight: (CGFloat) height {
105 [NSLayoutConstraint deactivateConstraints:[self.transferedImage constraints]];
106 [self.msgBackground setHidden:YES];
107 NSString* formatHeight = [NSString stringWithFormat:@"V:[transferedImage(==%@)]",[NSString stringWithFormat:@"%f", height]];
108 NSString* formatWidth = [NSString stringWithFormat:
109 @"H:[transferedImage(==%@)]",[NSString stringWithFormat:@"%f", width]];
110 NSArray* constraintsHorizontal = [NSLayoutConstraint
111 constraintsWithVisualFormat:formatWidth
112 options:0
113 metrics:nil views:NSDictionaryOfVariableBindings(transferedImage)];
114 NSArray* constraintsVertical = [NSLayoutConstraint
115 constraintsWithVisualFormat:formatHeight
116 options:0
117 metrics:nil views:NSDictionaryOfVariableBindings(transferedImage)];
118 NSArray* constraints =[constraintsHorizontal arrayByAddingObjectsFromArray:constraintsVertical] ;
119 [NSLayoutConstraint activateConstraints:constraintsHorizontal];
120}
121
122- (void) invalidateImageConstraints {
123[NSLayoutConstraint deactivateConstraints:[self.transferedImage constraints]];
Alexandre Lision0f66bd32016-01-18 11:30:45 -0500124}
125
Anthony Léonarde7d62ed2018-01-25 10:51:47 -0500126- (uint64_t)interaction
127{
128 return interaction;
129}
130
Alexandre Lision0f66bd32016-01-18 11:30:45 -0500131@end