Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 1 | /* |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 2 | * Copyright (C) 2016-2018 Savoir-faire Linux Inc. |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 4 | * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com> |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 5 | * |
| 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 Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 22 | #import "NSColor+RingTheme.h" |
| 23 | |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 24 | @implementation IMTableCellView { |
| 25 | uint64_t interaction; |
| 26 | } |
| 27 | |
Kateryna Kostiuk | ae660fd | 2018-04-24 14:10:41 -0400 | [diff] [blame^] | 28 | NSString* const MESSAGE_MARGIN = @"10"; |
| 29 | NSString* const TIME_BOX_HEIGHT = @"34"; |
| 30 | |
| 31 | @synthesize msgView, msgBackground, timeBox, transferedImage; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 32 | @synthesize photoView; |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 33 | @synthesize acceptButton; |
| 34 | @synthesize declineButton; |
| 35 | @synthesize progressIndicator; |
| 36 | @synthesize statusLabel; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 37 | |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 38 | - (void) setupDirection |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 39 | { |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 40 | if ([self.identifier containsString:@"Right"]) { |
Kateryna Kostiuk | 58276bc | 2017-06-07 08:50:48 -0400 | [diff] [blame] | 41 | self.msgBackground.pointerDirection = RIGHT; |
Kateryna Kostiuk | 3308987 | 2017-07-14 16:43:59 -0400 | [diff] [blame] | 42 | self.msgBackground.bgColor = [NSColor ringLightBlue]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 43 | } |
Kateryna Kostiuk | 58276bc | 2017-06-07 08:50:48 -0400 | [diff] [blame] | 44 | else { |
| 45 | self.msgBackground.pointerDirection = LEFT; |
| 46 | self.msgBackground.bgColor = [NSColor whiteColor]; |
| 47 | } |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | - (void) setupForInteraction:(uint64_t)inter |
| 51 | { |
| 52 | interaction = inter; |
| 53 | [self setupDirection]; |
Kateryna Kostiuk | 58276bc | 2017-06-07 08:50:48 -0400 | [diff] [blame] | 54 | [self.msgView setBackgroundColor:[NSColor clearColor]]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 55 | [self.msgView setString:@""]; |
Kateryna Kostiuk | ae660fd | 2018-04-24 14:10:41 -0400 | [diff] [blame^] | 56 | [self.msgView setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 57 | [self.msgBackground setTranslatesAutoresizingMaskIntoConstraints:NO]; |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 58 | [self.msgView setEnabledTextCheckingTypes:NSTextCheckingTypeLink]; |
| 59 | [self.msgView setAutomaticLinkDetectionEnabled:YES]; |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 60 | [self.msgView setEditable:NO]; |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 61 | } |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 62 | |
Kateryna Kostiuk | ae660fd | 2018-04-24 14:10:41 -0400 | [diff] [blame^] | 63 | - (void) updateMessageConstraint:(CGFloat) width andHeight: (CGFloat) height timeIsVisible: (bool) visible |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 64 | { |
Kateryna Kostiuk | ae660fd | 2018-04-24 14:10:41 -0400 | [diff] [blame^] | 65 | [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 Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 72 | |
Kateryna Kostiuk | ae660fd | 2018-04-24 14:10:41 -0400 | [diff] [blame^] | 73 | 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 Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 124 | } |
| 125 | |
Anthony Léonard | e7d62ed | 2018-01-25 10:51:47 -0500 | [diff] [blame] | 126 | - (uint64_t)interaction |
| 127 | { |
| 128 | return interaction; |
| 129 | } |
| 130 | |
Alexandre Lision | 0f66bd3 | 2016-01-18 11:30:45 -0500 | [diff] [blame] | 131 | @end |