WFCURecallCell.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // InformationCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/1.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCURecallCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "WFCUUtilities.h"
  11. #define TEXT_TOP_PADDING 6
  12. #define TEXT_BUTTOM_PADDING 6
  13. #define TEXT_LEFT_PADDING 8
  14. #define TEXT_RIGHT_PADDING 8
  15. #define TEXT_LABEL_TOP_PADDING TEXT_TOP_PADDING + 4
  16. #define TEXT_LABEL_BUTTOM_PADDING TEXT_BUTTOM_PADDING + 4
  17. #define TEXT_LABEL_LEFT_PADDING 30
  18. #define TEXT_LABEL_RIGHT_PADDING 30
  19. @implementation WFCURecallCell
  20. + (NSString *)recallMsg:(WFCCRecallMessageContent *)content {
  21. NSString *digest = [content digest:nil];
  22. return digest;
  23. }
  24. + (CGSize)sizeForCell:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
  25. CGFloat height = [super hightForHeaderArea:msgModel];
  26. NSString *infoText = [WFCURecallCell recallMsg:(WFCCRecallMessageContent *)msgModel.message.content];
  27. 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)];
  28. size.height += TEXT_LABEL_TOP_PADDING + TEXT_LABEL_BUTTOM_PADDING + TEXT_TOP_PADDING + TEXT_BUTTOM_PADDING;
  29. size.height += height;
  30. return CGSizeMake(width, size.height);
  31. return CGSizeZero;
  32. }
  33. - (void)setModel:(WFCUMessageModel *)model {
  34. [super setModel:model];
  35. WFCCRecallMessageContent *content = (WFCCRecallMessageContent *)model.message.content;
  36. NSString *infoText = [WFCURecallCell recallMsg:(WFCCRecallMessageContent *)model.message.content];
  37. CGFloat width = self.contentView.bounds.size.width;
  38. CGFloat reeditBtnWidth = 0;
  39. if (content.originalContentType == MESSAGE_CONTENT_TYPE_TEXT && [content.originalSender isEqualToString:[WFCCNetworkService sharedInstance].userId] && content.originalSearchableContent.length > 0) {
  40. CGSize btnsize = [WFCUUtilities getTextDrawingSize:self.reeditButton.titleLabel.text font:[UIFont systemFontOfSize:14] constrainedSize:CGSizeMake(width - TEXT_LABEL_LEFT_PADDING - TEXT_LABEL_RIGHT_PADDING - TEXT_LEFT_PADDING - TEXT_RIGHT_PADDING, 8000)];
  41. reeditBtnWidth = btnsize.width + 4;
  42. }
  43. 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)];
  44. self.infoLabel.text = infoText;
  45. self.infoLabel.layoutMargins = UIEdgeInsetsMake(TEXT_TOP_PADDING, TEXT_LEFT_PADDING, TEXT_BUTTOM_PADDING, TEXT_RIGHT_PADDING);
  46. CGFloat timeLableEnd = 0;
  47. if (!self.timeLabel.hidden) {
  48. timeLableEnd = self.timeLabel.frame.size.height + self.timeLabel.frame.origin.y;
  49. }
  50. self.recallContainer.frame = CGRectMake((width - size.width - reeditBtnWidth)/2 - 8, timeLableEnd + TEXT_LABEL_TOP_PADDING, size.width + reeditBtnWidth + 16, size.height + TEXT_TOP_PADDING + TEXT_BUTTOM_PADDING);
  51. self.infoLabel.frame = CGRectMake(8, TEXT_BUTTOM_PADDING, size.width, size.height);
  52. if (reeditBtnWidth) {
  53. self.reeditButton.frame = CGRectMake(size.width + 8, TEXT_BUTTOM_PADDING, reeditBtnWidth, size.height);
  54. }
  55. }
  56. - (void)onReeditBtn:(id)sender {
  57. [self.delegate reeditRecalledMessage:self withModel:self.model];
  58. }
  59. - (UILabel *)infoLabel {
  60. if (!_infoLabel) {
  61. _infoLabel = [[UILabel alloc] init];
  62. _infoLabel.numberOfLines = 0;
  63. _infoLabel.font = [UIFont systemFontOfSize:14];
  64. _infoLabel.textColor = [UIColor whiteColor];
  65. _infoLabel.numberOfLines = 0;
  66. _infoLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  67. _infoLabel.textAlignment = NSTextAlignmentCenter;
  68. _infoLabel.font = [UIFont systemFontOfSize:14.f];
  69. _infoLabel.textAlignment = NSTextAlignmentCenter;
  70. _infoLabel.backgroundColor = [UIColor clearColor];
  71. [self.recallContainer addSubview:_infoLabel];
  72. }
  73. return _infoLabel;
  74. }
  75. - (UIButton *)reeditButton {
  76. if (!_reeditButton) {
  77. _reeditButton = [[UIButton alloc] init];
  78. [_reeditButton setTitle:@"重新编辑" forState:UIControlStateNormal];
  79. [_reeditButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
  80. [_reeditButton setTitleColor:[UIColor grayColor] forState:UIControlStateSelected];
  81. [_reeditButton addTarget:self action:@selector(onReeditBtn:) forControlEvents:UIControlEventTouchDown];
  82. [_reeditButton setBackgroundColor:[UIColor clearColor]];
  83. _reeditButton.titleLabel.font = [UIFont systemFontOfSize:14];
  84. [self.recallContainer addSubview:_reeditButton];
  85. }
  86. return _reeditButton;
  87. }
  88. - (UIView *)recallContainer {
  89. if (!_recallContainer) {
  90. _recallContainer = [[UIView alloc] init];
  91. _recallContainer.backgroundColor = [UIColor colorWithRed:201/255.f green:201/255.f blue:201/255.f alpha:1.f];
  92. _recallContainer.layer.masksToBounds = YES;
  93. _recallContainer.layer.cornerRadius = 5.f;
  94. [self.contentView addSubview:_recallContainer];
  95. }
  96. return _recallContainer;
  97. }
  98. @end