2
0

WFCURecallCell.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. }
  32. - (void)setModel:(WFCUMessageModel *)model {
  33. [super setModel:model];
  34. WFCCRecallMessageContent *content = (WFCCRecallMessageContent *)model.message.content;
  35. NSString *infoText = [WFCURecallCell recallMsg:(WFCCRecallMessageContent *)model.message.content];
  36. CGFloat width = self.contentView.bounds.size.width;
  37. CGFloat reeditBtnWidth = 0;
  38. if (content.originalContentType == MESSAGE_CONTENT_TYPE_TEXT && [content.originalSender isEqualToString:[WFCCNetworkService sharedInstance].userId] && content.originalSearchableContent.length > 0 && [content.operatorId isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  39. 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)];
  40. reeditBtnWidth = btnsize.width + 4;
  41. }
  42. 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)];
  43. self.infoLabel.text = infoText;
  44. self.infoLabel.layoutMargins = UIEdgeInsetsMake(TEXT_TOP_PADDING, TEXT_LEFT_PADDING, TEXT_BUTTOM_PADDING, TEXT_RIGHT_PADDING);
  45. CGFloat timeLableEnd = 0;
  46. if (!self.timeLabel.hidden) {
  47. timeLableEnd = self.timeLabel.frame.size.height + self.timeLabel.frame.origin.y;
  48. }
  49. 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);
  50. self.infoLabel.frame = CGRectMake(8, TEXT_BUTTOM_PADDING, size.width, size.height);
  51. if (reeditBtnWidth) {
  52. self.reeditButton.frame = CGRectMake(size.width + 8, TEXT_BUTTOM_PADDING, reeditBtnWidth, size.height);
  53. self.reeditButton.hidden = NO;
  54. } else {
  55. self.reeditButton.hidden = YES;
  56. }
  57. }
  58. - (void)onReeditBtn:(id)sender {
  59. [self.delegate reeditRecalledMessage:self withModel:self.model];
  60. }
  61. - (UILabel *)infoLabel {
  62. if (!_infoLabel) {
  63. _infoLabel = [[UILabel alloc] init];
  64. _infoLabel.numberOfLines = 0;
  65. _infoLabel.font = [UIFont systemFontOfSize:14];
  66. _infoLabel.textColor = [UIColor whiteColor];
  67. _infoLabel.numberOfLines = 0;
  68. _infoLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  69. _infoLabel.textAlignment = NSTextAlignmentCenter;
  70. _infoLabel.font = [UIFont systemFontOfSize:14.f];
  71. _infoLabel.textAlignment = NSTextAlignmentCenter;
  72. _infoLabel.backgroundColor = [UIColor clearColor];
  73. [self.recallContainer addSubview:_infoLabel];
  74. }
  75. return _infoLabel;
  76. }
  77. - (UIButton *)reeditButton {
  78. if (!_reeditButton) {
  79. _reeditButton = [[UIButton alloc] init];
  80. [_reeditButton setTitle:WFCString(@"重新编辑") forState:UIControlStateNormal];
  81. [_reeditButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
  82. [_reeditButton setTitleColor:[UIColor grayColor] forState:UIControlStateSelected];
  83. [_reeditButton addTarget:self action:@selector(onReeditBtn:) forControlEvents:UIControlEventTouchDown];
  84. [_reeditButton setBackgroundColor:[UIColor clearColor]];
  85. _reeditButton.titleLabel.font = [UIFont systemFontOfSize:14];
  86. [self.recallContainer addSubview:_reeditButton];
  87. }
  88. return _reeditButton;
  89. }
  90. - (UIView *)recallContainer {
  91. if (!_recallContainer) {
  92. _recallContainer = [[UIView alloc] init];
  93. _recallContainer.backgroundColor = [UIColor colorWithRed:201/255.f green:201/255.f blue:201/255.f alpha:1.f];
  94. _recallContainer.layer.masksToBounds = YES;
  95. _recallContainer.layer.cornerRadius = 5.f;
  96. [self.contentView addSubview:_recallContainer];
  97. }
  98. return _recallContainer;
  99. }
  100. @end