Browse Source

quote cell ui

heavyrain2012 4 years ago
parent
commit
be2ee4dd33

+ 1 - 3
wfuikit/WFChatUIKit/MessageList/Cell/WFCUInformationCell.m

@@ -25,7 +25,7 @@
 @implementation WFCUInformationCell
 
 + (CGSize)sizeForCell:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
-    CGFloat height = [super hightForTimeLabel:msgModel];
+    CGFloat height = [super hightForHeaderArea:msgModel];
     NSString *infoText;
     if ([msgModel.message.content isKindOfClass:[WFCCNotificationMessageContent class]]) {
         WFCCNotificationMessageContent *content = (WFCCNotificationMessageContent *)msgModel.message.content;
@@ -37,8 +37,6 @@
     size.height += TEXT_LABEL_TOP_PADDING + TEXT_LABEL_BUTTOM_PADDING + TEXT_TOP_PADDING + TEXT_BUTTOM_PADDING;
     size.height += height;
     return CGSizeMake(width, size.height);
-    
-    return CGSizeZero;
 }
 
 - (void)setModel:(WFCUMessageModel *)model {

+ 1 - 0
wfuikit/WFChatUIKit/MessageList/Cell/WFCUMessageCell.h

@@ -15,5 +15,6 @@
 @property (nonatomic, strong)UILabel *nameLabel;
 @property (nonatomic, strong)UIImageView *bubbleView;
 @property (nonatomic, strong)UIView *contentArea;
+@property (nonatomic, strong)UILabel *quoteLabel;
 - (void)setMaskImage:(UIImage *)maskImage;
 @end

+ 52 - 8
wfuikit/WFChatUIKit/MessageList/Cell/WFCUMessageCell.m

@@ -29,6 +29,9 @@
 #define Bubble_Padding_Arraw 16
 #define Bubble_Padding_Another_Side 8
 
+#define MESSAGE_BASE_CELL_QUOTE_SIZE 14
+
+
 @interface WFCUMessageCell ()
 @property (nonatomic, strong)UIActivityIndicatorView *activityIndicatorView;
 @property (nonatomic, strong)UIImageView *failureView;
@@ -49,7 +52,7 @@
 }
 
 + (CGSize)sizeForCell:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
-  CGFloat height = [super hightForTimeLabel:msgModel];
+  CGFloat height = [super hightForHeaderArea:msgModel];
   CGFloat portraitSize = Portrait_Size;
   CGFloat nameLabelHeight = Name_Label_Height + Name_Client_Padding;
   CGFloat clientAreaWidth = [self clientAreaWidth];
@@ -69,6 +72,9 @@
     height += nameAndClientHeight;
   }
   height += Client_Arad_Buttom_Padding;   //buttom padding
+    
+  height += [self sizeForQuoteArea:msgModel withViewWidth:clientAreaWidth].height;
+    
   return CGSizeMake(width, height);
 }
 
@@ -76,6 +82,21 @@
   return CGSizeZero;
 }
 
++ (CGSize)sizeForQuoteArea:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
+    if ([msgModel.message.content isKindOfClass:[WFCCTextMessageContent class]]) {
+        WFCCTextMessageContent *txtContent = (WFCCTextMessageContent *)msgModel.message.content;
+        if (txtContent.quoteInfo) {
+            CGFloat quoteWidth = width - Portrait_Size - Portrait_Padding_Right - Portrait_Size - Portrait_Padding_Left;
+            NSString *quoteTxt = [NSString stringWithFormat:@"%@:%@", txtContent.quoteInfo.userDisplayName, txtContent.quoteInfo.messageDigest];
+            CGSize size = [WFCUUtilities getTextDrawingSize:quoteTxt font:[UIFont systemFontOfSize:MESSAGE_BASE_CELL_QUOTE_SIZE] constrainedSize:CGSizeMake(quoteWidth, 36)];
+            size.height += 4;
+            size.width = width;
+            return size;
+        }
+    }
+    return CGSizeZero;
+}
+
 - (void)updateStatus {
     if (self.model.message.direction == MessageDirection_Send) {
         if (self.model.message.status == Message_Status_Sending) {
@@ -158,11 +179,9 @@
   
   [super setModel:model];
 
-    
+  CGFloat selectViewOffset = model.selecting ? SelectView_Size + Portrait_Padding_Right : 0;
   if (model.message.direction == MessageDirection_Send) {
-      CGFloat selectViewOffset = model.selecting ? SelectView_Size + Portrait_Padding_Right : 0;
-      
-    CGFloat top = [WFCUMessageCellBase hightForTimeLabel:model];
+    CGFloat top = [WFCUMessageCellBase hightForHeaderArea:model];
     CGRect frame = self.frame;
     self.portraitView.frame = CGRectMake(frame.size.width - Portrait_Size - Portrait_Padding_Right - selectViewOffset, top, Portrait_Size, Portrait_Size);
     if (model.showNameLabel) {
@@ -241,7 +260,7 @@
           self.receiptView.frame = CGRectMake(self.bubbleView.frame.origin.x - 16, self.frame.size.height - 24 , 14, 14);
       }
   } else {
-    CGFloat top = [WFCUMessageCellBase hightForTimeLabel:model];
+    CGFloat top = [WFCUMessageCellBase hightForHeaderArea:model];
     self.portraitView.frame = CGRectMake(Portrait_Padding_Left, top, Portrait_Size, Portrait_Size);
     if (model.showNameLabel) {
       self.nameLabel.frame = CGRectMake(Portrait_Padding_Left + Portrait_Size + Name_Label_Padding, top, 200, Name_Label_Height);
@@ -288,7 +307,7 @@
         } else {
             self.selectView.image = [UIImage imageNamed:@"multi_unselected"];
         }
-        CGFloat top = [WFCUMessageCellBase hightForTimeLabel:model];
+        CGFloat top = [WFCUMessageCellBase hightForHeaderArea:model];
         CGRect frame = self.selectView.frame;
         frame.origin.y = top;
         self.selectView.frame = frame;
@@ -326,6 +345,31 @@
         });
         model.highlighted = NO;
     }
+    
+    self.quoteLabel.hidden = YES;
+    if ([model.message.content isKindOfClass:[WFCCTextMessageContent class]]) {
+        WFCCTextMessageContent *txtContent = (WFCCTextMessageContent *)model.message.content;
+        if (txtContent.quoteInfo) {
+            if (!self.quoteLabel) {
+                self.quoteLabel = [[UILabel alloc] initWithFrame:CGRectZero];
+                self.quoteLabel.backgroundColor = [UIColor grayColor];
+                self.quoteLabel.font = [UIFont systemFontOfSize:MESSAGE_BASE_CELL_QUOTE_SIZE];
+                self.quoteLabel.numberOfLines = 0;
+                self.quoteLabel.layer.cornerRadius = 3.f;
+                self.quoteLabel.layer.masksToBounds = YES;
+                [self.contentView addSubview:self.quoteLabel];
+            }
+            CGSize size = [self.class sizeForQuoteArea:model withViewWidth:[WFCUMessageCell clientAreaWidth]];
+            if (model.message.direction == MessageDirection_Send) {
+                self.quoteLabel.frame = CGRectMake(self.frame.size.width - Portrait_Size - Portrait_Padding_Right - Name_Label_Padding - size.width - Bubble_Padding_Another_Side - selectViewOffset, self.bubbleView.frame.origin.y + self.bubbleView.frame.size.height + 4, size.width, size.height-4);
+            } else {
+                self.quoteLabel.frame = CGRectMake(Portrait_Padding_Left + Portrait_Size + Name_Label_Padding + Bubble_Padding_Arraw, self.bubbleView.frame.origin.y + self.bubbleView.frame.size.height + 4, size.width, size.height-4);
+            }
+            
+            self.quoteLabel.hidden = NO;
+            self.quoteLabel.text = [NSString stringWithFormat:@"%@:%@", txtContent.quoteInfo.userDisplayName, txtContent.quoteInfo.messageDigest];
+        }
+    }
 }
 
 - (void)onTapReceiptView:(id)sender {
@@ -440,7 +484,7 @@
 
 - (UIImageView *)selectView {
     if(!_selectView) {
-        CGFloat top = [WFCUMessageCellBase hightForTimeLabel:self.model];
+        CGFloat top = [WFCUMessageCellBase hightForHeaderArea:self.model];
         CGRect frame = self.frame;
         frame = CGRectMake(frame.size.width - SelectView_Size - Portrait_Padding_Right, top, SelectView_Size, SelectView_Size);
         

+ 1 - 3
wfuikit/WFChatUIKit/MessageList/Cell/WFCUMessageCellBase.h

@@ -30,12 +30,10 @@
 @interface WFCUMessageCellBase : UICollectionViewCell
 @property (nonatomic, strong)UILabel *timeLabel;
 @property (nonatomic, strong)UIView *lastReadContainerView;
-@property (nonatomic, strong)UILabel *quoteLabel;
 @property (nonatomic, strong)WFCUMessageModel *model;
 @property (nonatomic, weak)id<WFCUMessageCellDelegate> delegate;
 + (CGSize)sizeForCell:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width;
-+ (CGFloat)hightForTimeLabel:(WFCUMessageModel *)msgModel;
-+ (CGFloat)hightForLastReadLabel:(WFCUMessageModel *)msgModel;
++ (CGFloat)hightForHeaderArea:(WFCUMessageModel *)msgModel;
 
 - (void)onTaped:(id)sender;
 - (void)onLongPressed:(id)sender;

+ 30 - 14
wfuikit/WFChatUIKit/MessageList/Cell/WFCUMessageCellBase.m

@@ -10,22 +10,27 @@
 #import "WFCUUtilities.h"
 #import "UIFont+YH.h"
 #import "UIColor+YH.h"
+#import "WFCUUtilities.h"
+
 @implementation WFCUMessageCellBase
 + (CGSize)sizeForCell:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
   return CGSizeMake(width, 80);
 }
-+ (CGFloat)hightForTimeLabel:(WFCUMessageModel *)msgModel {
-  if (msgModel.showTimeLabel) {
-    return 27;
-  }
-  return 5;
-}
-+ (CGFloat)hightForLastReadLabel:(WFCUMessageModel *)msgModel {
+
++ (CGFloat)hightForHeaderArea:(WFCUMessageModel *)msgModel {
+    CGFloat offset;
+    if (msgModel.showTimeLabel) {
+        offset = 27;
+    } else {
+        offset = 5;
+    }
+
     if (msgModel.lastReadMessage) {
-        return 30;
+        offset += 30;
     }
-    return 0;
+    return offset;
 }
+
 - (void)onTaped:(id)sender {
     [self.delegate didTapMessageCell:self withModel:self.model];
 }
@@ -52,20 +57,31 @@
     CGFloat offset = 5;
     if (model.lastReadMessage) {
         if (!self.lastReadContainerView) {
-            self.lastReadContainerView = [[UIView alloc] initWithFrame:CGRectMake(8, offset, screenWidth-16, 20)];
-            UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 10, screenWidth-16, 1)];
-            line.backgroundColor = [UIColor grayColor];
-            [self.lastReadContainerView addSubview:line];
+            self.lastReadContainerView = [[UIView alloc] initWithFrame:CGRectMake(16, offset, screenWidth-32, 20)];
             
             UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
             label.text = WFCString(@"last_read_here");
             label.font = [UIFont systemFontOfSize:16];
             label.textAlignment = NSTextAlignmentCenter;
             label.textColor = [UIColor grayColor];
+            label.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.f];
+            label.layer.cornerRadius = 5.f;
+            label.layer.masksToBounds = YES;
             CGSize size = [WFCUUtilities getTextDrawingSize:label.text font:label.font constrainedSize:CGSizeMake(screenWidth-16, 8000)];
             size.width += 16;
-            label.frame = CGRectMake((screenWidth - 16 - size.width)/2, offset, size.width, 20);
+            label.frame = CGRectMake((screenWidth - 32 - size.width)/2,  (20-size.height)/2, size.width, size.height);
             [self.lastReadContainerView addSubview:label];
+            
+            
+            UIView *leftline = [[UIView alloc] initWithFrame:CGRectMake(0, 10, (screenWidth-32-size.width)/2-8, 1)];
+            leftline.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.f];
+            [self.lastReadContainerView addSubview:leftline];
+            
+            UIView *rightline = [[UIView alloc] initWithFrame:CGRectMake((screenWidth-32 + size.width)/2 + 8, 10, (screenWidth-32-size.width)/2-8, 1)];
+            rightline.backgroundColor = leftline.backgroundColor;
+            [self.lastReadContainerView addSubview:rightline];
+            
+            [self.contentView addSubview:self.lastReadContainerView];
         }
         offset += 20;
     } else {

+ 1 - 1
wfuikit/WFChatUIKit/MessageList/Cell/WFCURecallCell.m

@@ -28,7 +28,7 @@
     return digest;
 }
 + (CGSize)sizeForCell:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
-    CGFloat height = [super hightForTimeLabel:msgModel];
+    CGFloat height = [super hightForHeaderArea:msgModel];
     NSString *infoText = [WFCURecallCell recallMsg:(WFCCRecallMessageContent *)msgModel.message.content];
     
     CGSize size = [WFCUUtilities getTextDrawingSize:infoText font:[UIFont systemFontOfSize:14] constrainedSize:CGSizeMake(width - TEXT_LABEL_LEFT_PADDING - TEXT_LABEL_RIGHT_PADDING - TEXT_LEFT_PADDING - TEXT_RIGHT_PADDING, 8000)];