1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
//
// TAPYourChatDeletedBubbleTableViewCell.m
// TapTalk
//
// Created by Dominic Vedericho on 29/05/19.
// Copyright © 2019 Moselo. All rights reserved.
//
#import "TAPYourChatDeletedBubbleTableViewCell.h"
@interface TAPYourChatDeletedBubbleTableViewCell ()
@property (strong, nonatomic) IBOutlet UIView *bubbleView;
@property (strong, nonatomic) IBOutlet UILabel *bubbleLabel;
@property (strong, nonatomic) IBOutlet UILabel *statusLabel;
@property (strong, nonatomic) IBOutlet UIButton *chatBubbleButton;
@property (strong, nonatomic) IBOutlet UIImageView *deletedIconImageView;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *statusLabelTopConstraint;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *statusLabelHeightConstraint;
@property (strong, nonatomic) IBOutlet UIView *senderInitialView;
@property (strong, nonatomic) IBOutlet UILabel *senderInitialLabel;
@property (strong, nonatomic) IBOutlet UIButton *senderProfileImageButton;
@property (strong, nonatomic) IBOutlet TAPImageView *senderImageView;
@property (strong, nonatomic) IBOutlet UILabel *senderNameLabel;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *senderImageViewWidthConstraint;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *senderImageViewTrailingConstraint;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *senderProfileImageButtonWidthConstraint;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *senderNameTopConstraint;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *senderNameHeightConstraint;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *deletedIconImageViewWidthConstraint;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *deletedIconImageViewTrailingConstraint;
- (IBAction)chatBubbleButtonDidTapped:(id)sender;
- (IBAction)senderProfileImageButtonDidTapped:(id)sender;
- (void)setBubbleCellStyle;
- (void)showSenderInfo:(BOOL)show;
@end
@implementation TAPYourChatDeletedBubbleTableViewCell
#pragma mark - Lifecycle
- (void)awakeFromNib {
[super awakeFromNib];
self.bubbleView.clipsToBounds = YES;
self.statusLabelTopConstraint.constant = 0.0f;
self.statusLabelHeightConstraint.constant = 0.0f;
[self.contentView layoutIfNeeded];
self.statusLabel.alpha = 0.0f;
self.bubbleView.clipsToBounds = YES;
self.bubbleView.layer.cornerRadius = 16.0f;
self.bubbleView.layer.maskedCorners = kCALayerMaxXMinYCorner | kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
self.senderImageView.clipsToBounds = YES;
self.senderImageView.layer.cornerRadius = CGRectGetHeight(self.senderImageView.frame)/2.0f;
[self setBubbleCellStyle];
[self showSenderInfo:NO];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)prepareForReuse {
[super prepareForReuse];
self.statusLabelTopConstraint.constant = 0.0f;
self.statusLabelHeightConstraint.constant = 0.0f;
self.statusLabel.alpha = 0.0f;
self.deletedIconImageViewWidthConstraint.constant = 0.0f;
self.deletedIconImageViewTrailingConstraint.constant = 0.0f;
self.bubbleLabel.text = @"";
[self setBubbleCellStyle];
[self showSenderInfo:NO];
[self.contentView layoutIfNeeded];
}
#pragma mark - Custom Method
- (void)setBubbleCellStyle {
self.contentView.backgroundColor = [UIColor clearColor];
self.bubbleView.backgroundColor = [[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorLeftBubbleBackground];
UIFont *bubbleLabelFont = [[TAPStyleManager sharedManager] getComponentFontForType:TAPComponentFontLeftBubbleDeletedMessageBody];
UIColor *bubbleLabelColor = [[TAPStyleManager sharedManager] getTextColorForType:TAPTextColorLeftBubbleDeletedMessageBody];
UIFont *statusLabelFont = [[TAPStyleManager sharedManager] getComponentFontForType:TAPComponentFontBubbleMessageStatus];
UIColor *statusLabelColor = [[TAPStyleManager sharedManager] getTextColorForType:TAPTextColorBubbleMessageStatus];
UIFont *initialNameLabelFont = [[TAPStyleManager sharedManager] getComponentFontForType:TAPComponentFontRoomAvatarSmallLabel];
UIColor *initialNameLabelColor = [[TAPStyleManager sharedManager] getTextColorForType:TAPTextColorRoomAvatarSmallLabel];
UIFont *senderNameLabelFont = [[TAPStyleManager sharedManager] getComponentFontForType:TAPComponentFontLeftBubbleSenderName];
UIColor *senderNameLabelColor = [[TAPStyleManager sharedManager] getTextColorForType:TAPTextColorLeftBubbleSenderName];
self.senderInitialLabel.textColor = initialNameLabelColor;
self.senderInitialLabel.font = initialNameLabelFont;
self.senderInitialView.layer.cornerRadius = CGRectGetWidth(self.senderInitialView.frame) / 2.0f;
self.senderInitialView.clipsToBounds = YES;
self.bubbleLabel.textColor = bubbleLabelColor;
self.bubbleLabel.font = bubbleLabelFont;
self.statusLabel.textColor = statusLabelColor;
self.statusLabel.font = statusLabelFont;
self.senderNameLabel.font = senderNameLabelFont;
self.senderNameLabel.textColor = senderNameLabelColor;
}
- (void)setMessage:(TAPMessageModel *)message {
if(message == nil) {
return;
}
_message = message;
if (self.type == TAPYourChatDeletedBubbleTableViewCellTypeDefault) {
UIImage *deletedImage = [UIImage imageNamed:@"TAPIconBlock" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
deletedImage = [deletedImage setImageTintColor:[[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorIconDeletedLeftMessageBubble]];
self.deletedIconImageView.image = deletedImage;
self.deletedIconImageViewWidthConstraint.constant = 16.0f;
self.deletedIconImageViewTrailingConstraint.constant = 4.0f;
self.bubbleLabel.text = NSLocalizedStringFromTableInBundle(@"This message was deleted.", nil, [TAPUtil currentBundle], @"");
}
else if (self.type == TAPYourChatDeletedBubbleTableViewCellTypeUnsupported) {
self.deletedIconImageView.image = nil;
self.deletedIconImageViewWidthConstraint.constant = 0.0f;
self.deletedIconImageViewTrailingConstraint.constant = 0.0f;
self.bubbleLabel.text = NSLocalizedStringFromTableInBundle(@"This message type is unsupported in the current app version.", nil, [TAPUtil currentBundle], @"");
}
else {
self.deletedIconImageView.image = nil;
self.deletedIconImageViewWidthConstraint.constant = 0.0f;
self.deletedIconImageViewTrailingConstraint.constant = 0.0f;
self.bubbleLabel.text = @"";
}
//CS NOTE - check chat room type, show sender info if group type
if (message.room.type == RoomTypeGroup || message.room.type == RoomTypeTransaction) {
[self showSenderInfo:YES];
NSString *thumbnailImageString = @"";
TAPUserModel *obtainedUser = [[TAPContactManager sharedManager] getUserWithUserID:message.user.userID];
if (obtainedUser != nil && ![obtainedUser.imageURL.thumbnail isEqualToString:@""]) {
thumbnailImageString = obtainedUser.imageURL.thumbnail;
thumbnailImageString = [TAPUtil nullToEmptyString:thumbnailImageString];
}
else {
thumbnailImageString = message.user.imageURL.thumbnail;
thumbnailImageString = [TAPUtil nullToEmptyString:thumbnailImageString];
}
NSString *fullNameString = @"";
if (obtainedUser != nil && ![obtainedUser.fullname isEqualToString:@""]) {
fullNameString = obtainedUser.fullname;
fullNameString = [TAPUtil nullToEmptyString:fullNameString];
}
else {
fullNameString = message.user.fullname;
fullNameString = [TAPUtil nullToEmptyString:fullNameString];
}
if ([thumbnailImageString isEqualToString:@""]) {
//No photo found, get the initial
self.senderInitialView.alpha = 1.0f;
self.senderImageView.alpha = 0.0f;
self.senderProfileImageButton.alpha = 0.0f;
self.senderInitialView.backgroundColor = [[TAPStyleManager sharedManager] getRandomDefaultAvatarBackgroundColorWithName:fullNameString];
self.senderInitialLabel.text = [[TAPStyleManager sharedManager] getInitialsWithName:fullNameString isGroup:NO];
}
else {
self.senderInitialView.alpha = 0.0f;
self.senderImageView.alpha = 1.0f;
[self.senderImageView setImageWithURLString:thumbnailImageString];
}
self.senderNameLabel.text = fullNameString;
}
else {
[self showSenderInfo:NO];
self.senderImageView.image = nil;
self.senderNameLabel.text = @"";
}
}
- (void)showStatusLabel:(BOOL)isShowed animated:(BOOL)animated {
self.chatBubbleButton.userInteractionEnabled = NO;
if (isShowed) {
NSTimeInterval lastMessageTimeInterval = [self.message.created doubleValue] / 1000.0f; //change to second from milisecond
NSDate *currentDate = [NSDate date];
NSTimeInterval currentTimeInterval = [currentDate timeIntervalSince1970];
NSTimeInterval timeGap = currentTimeInterval - lastMessageTimeInterval;
NSDateFormatter *midnightDateFormatter = [[NSDateFormatter alloc] init];
[midnightDateFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]]; // POSIX to avoid weird issues
midnightDateFormatter.dateFormat = @"dd-MMM-yyyy";
NSString *midnightFormattedCreatedDate = [midnightDateFormatter stringFromDate:currentDate];
NSDate *todayMidnightDate = [midnightDateFormatter dateFromString:midnightFormattedCreatedDate];
NSTimeInterval midnightTimeInterval = [todayMidnightDate timeIntervalSince1970];
NSTimeInterval midnightTimeGap = currentTimeInterval - midnightTimeInterval;
NSDate *lastMessageDate = [NSDate dateWithTimeIntervalSince1970:lastMessageTimeInterval];
NSString *lastMessageDateString = @"";
if (timeGap <= midnightTimeGap) {
//Today
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"HH:mm";
NSString *dateString = [dateFormatter stringFromDate:lastMessageDate];
NSString *appendedLastDateString = NSLocalizedStringFromTableInBundle(@"at ", nil, [TAPUtil currentBundle], @"");
lastMessageDateString = [NSString stringWithFormat:@"%@%@", appendedLastDateString, dateString];
}
else if (timeGap <= 86400.0f + midnightTimeGap) {
//Yesterday
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"HH:mm";
NSString *dateString = [dateFormatter stringFromDate:lastMessageDate];
NSString *appendedLastDateString = NSLocalizedStringFromTableInBundle(@"yesterday at ", nil, [TAPUtil currentBundle], @"");
lastMessageDateString = [NSString stringWithFormat:@"%@%@", appendedLastDateString, dateString];
}
else {
//Set date
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"dd/MM/yyyy HH:mm";
NSString *dateString = [dateFormatter stringFromDate:lastMessageDate];
NSString *appendedLastDateString = NSLocalizedStringFromTableInBundle(@"at ", nil, [TAPUtil currentBundle], @"");
lastMessageDateString = [NSString stringWithFormat:@"%@%@", appendedLastDateString, dateString];
}
NSString *appendedStatusString = NSLocalizedStringFromTableInBundle(@"Sent ", nil, [TAPUtil currentBundle], @"");
NSString *statusString = [NSString stringWithFormat:@"%@%@", appendedStatusString, lastMessageDateString];
self.statusLabel.text = statusString;
self.chatBubbleButton.alpha = 1.0f;
self.statusLabel.alpha = 1.0f;
self.chatBubbleButton.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.18f];
self.statusLabelTopConstraint.constant = 2.0f;
self.statusLabelHeightConstraint.constant = 13.0f;
[self.contentView layoutIfNeeded];
[self layoutIfNeeded];
self.chatBubbleButton.userInteractionEnabled = YES;
}
else {
self.chatBubbleButton.backgroundColor = [UIColor clearColor];
self.statusLabelTopConstraint.constant = 0.0f;
self.statusLabelHeightConstraint.constant = 0.0f;
[self.contentView layoutIfNeeded];
[self layoutIfNeeded];
self.chatBubbleButton.alpha = 0.0f;
self.chatBubbleButton.userInteractionEnabled = YES;
self.statusLabel.alpha = 0.0f;
}
}
- (IBAction)chatBubbleButtonDidTapped:(id)sender {
if ([self.delegate respondsToSelector:@selector(yourChatDeletedBubbleViewDidTapped:)]) {
[self.delegate yourChatDeletedBubbleViewDidTapped:self.message];
}
}
- (IBAction)senderProfileImageButtonDidTapped:(id)sender {
if ([self.delegate respondsToSelector:@selector(yourChatDeletedBubbleDidTappedProfilePictureWithMessage:)]) {
[self.delegate yourChatDeletedBubbleDidTappedProfilePictureWithMessage:self.message];
}
}
- (void)showSenderInfo:(BOOL)show {
if (show) {
self.senderImageViewWidthConstraint.constant = 30.0f;
self.senderImageViewTrailingConstraint.constant = 4.0f;
self.senderProfileImageButtonWidthConstraint.constant = 30.0f;
self.senderProfileImageButton.userInteractionEnabled = YES;
self.senderNameHeightConstraint.constant = 18.0f;
}
else {
self.senderImageViewWidthConstraint.constant = 0.0f;
self.senderImageViewTrailingConstraint.constant = 0.0f;
self.senderProfileImageButtonWidthConstraint.constant = 0.0f;
self.senderProfileImageButton.userInteractionEnabled = NO;
self.senderNameHeightConstraint.constant = 0.0f;
}
[self.contentView layoutIfNeeded];
}
@end