From 59d81cd2ef37c74d7ab4323eaa49793571dc7c10 Mon Sep 17 00:00:00 2001 From: David Idmansour Date: Wed, 27 Jun 2018 17:06:46 +0200 Subject: [PATCH] aligned chat bubbles & width and height of bubbles depend on message length --- Classes/LinphoneManager.m | 3 +++ .../Base.lproj/MainInterface.storyboard | 16 ++++++++-------- richNotifications/NotificationTableViewCell.h | 3 +++ richNotifications/NotificationTableViewCell.m | 16 ++++++++++++++++ richNotifications/NotificationViewController.m | 18 +++++++++++++----- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 51be144cf..871fae6f4 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1256,6 +1256,9 @@ static void linphone_iphone_popup_password_request(LinphoneCore *lc, LinphoneAut const char *filename = linphone_content_get_name(file); [msgData setObject:[NSString stringWithUTF8String:filename] forKey:@"msg"]; } else { + CGSize msgSize = [UIChatBubbleTextCell ViewSizeForMessage:msg withWidth:375]; + [msgData setObject:[NSNumber numberWithFloat:msgSize.width] forKey:@"width"]; + [msgData setObject:[NSNumber numberWithFloat:msgSize.height] forKey:@"height"]; [msgData setObject:[UIChatBubbleTextCell TextMessageForChat:msg] forKey:@"msg"]; } [msgData setObject:[NSNumber numberWithBool:isOutgoing] forKey:@"isOutgoing"]; diff --git a/richNotifications/Base.lproj/MainInterface.storyboard b/richNotifications/Base.lproj/MainInterface.storyboard index 75085b067..de6f3da83 100644 --- a/richNotifications/Base.lproj/MainInterface.storyboard +++ b/richNotifications/Base.lproj/MainInterface.storyboard @@ -26,25 +26,25 @@ - + - - + + @@ -87,8 +87,8 @@ - - + + diff --git a/richNotifications/NotificationTableViewCell.h b/richNotifications/NotificationTableViewCell.h index 063836e34..534c10f0c 100644 --- a/richNotifications/NotificationTableViewCell.h +++ b/richNotifications/NotificationTableViewCell.h @@ -14,5 +14,8 @@ @property (weak, nonatomic) IBOutlet UILabel *imdm; @property (weak, nonatomic) IBOutlet UIImageView *background; @property (weak, nonatomic) IBOutlet UIImageView *bottomBarColor; +@property BOOL isOutgoing; +@property float width; +@property float height; @end diff --git a/richNotifications/NotificationTableViewCell.m b/richNotifications/NotificationTableViewCell.m index 36e80404f..79b64f1b1 100644 --- a/richNotifications/NotificationTableViewCell.m +++ b/richNotifications/NotificationTableViewCell.m @@ -23,4 +23,20 @@ // Configure the view for the selected state } +- (void)layoutSubviews { + [super layoutSubviews]; + CGRect bubbleFrame = self.contentView.frame; + int origin_x; + + bubbleFrame.size = CGSizeMake(_width, _height); + + origin_x = (_isOutgoing ? self.frame.size.width - bubbleFrame.size.width - 5 : 5); + + bubbleFrame.origin.x = origin_x; + self.contentView.frame = bubbleFrame; + + _msgText.textContainerInset = UIEdgeInsetsZero; + _msgText.textContainer.lineFragmentPadding = 0; +} + @end diff --git a/richNotifications/NotificationViewController.m b/richNotifications/NotificationViewController.m index 49d4a333b..9ba2fa616 100644 --- a/richNotifications/NotificationViewController.m +++ b/richNotifications/NotificationViewController.m @@ -37,7 +37,6 @@ animated:YES]; NSLog(@"Content length : %f", self.tableView.contentSize.height); NSLog(@"Number of rows : %d", (unsigned int)[self tableView:self.tableView numberOfRowsInSection:0]); - [self.view.superview bringSubviewToFront:self.tableView]; } #pragma mark - UITableViewDataSource Functions @@ -65,21 +64,30 @@ cell.contactImage.image = [UIImage imageWithData:imageData]; cell.nameDate.text = display; cell.msgText.text = msgText; + cell.isOutgoing = isOutgoing; + cell.width = ((NSNumber *)[msgs[indexPath.row] objectForKey:@"width"]).floatValue; + cell.height = ((NSNumber *)[msgs[indexPath.row] objectForKey:@"height"]).floatValue; + cell.nameDate.textColor = [UIColor colorWithPatternImage:cell.background.image]; + cell.msgText.textColor = [UIColor darkGrayColor]; if (!isOutgoing) cell.imdm.hidden = YES; - if ([imdm isEqualToString:@"LinphoneChatMessageStateDelivered"]) + if ([imdm isEqualToString:@"LinphoneChatMessageStateDelivered"]) { cell.imdm.text = NSLocalizedString(@"Delivered", nil); - else if ([imdm isEqualToString:@"LinphoneChatMessageStateDisplayed"]) + cell.imdm.textColor = [UIColor grayColor]; + } else if ([imdm isEqualToString:@"LinphoneChatMessageStateDisplayed"]) { cell.imdm.text = NSLocalizedString(@"Read", nil); - else + cell.imdm.textColor = [UIColor colorWithRed:(24 / 255.0) green:(167 / 255.0) blue:(175 / 255.0) alpha:1.0]; + } else cell.imdm.text = imdm; + printf("Taille label : %f\n", cell.nameDate.font.pointSize); + printf("Taille field : %f\n", cell.msgText.font.pointSize); return cell; } #pragma mark - UITableViewDelegate Functions - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - return 100; + return ((NSNumber *)[msgs[indexPath.row] objectForKey:@"height"]).floatValue + 5; } @end