WFCUFileRecordTableViewCell.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // FileRecordTableViewCell.m
  3. // WFChatUIKit
  4. //
  5. // Created by dali on 2020/10/29.
  6. // Copyright © 2020 Wildfirechat. All rights reserved.
  7. //
  8. #import "WFCUFileRecordTableViewCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "WFCUUtilities.h"
  11. @interface WFCUFileRecordTableViewCell ()
  12. @property(nonatomic, strong)UIImageView *iconView;
  13. @property(nonatomic, strong)UILabel *nameLabel;
  14. @property(nonatomic, strong)UILabel *infoLabel;
  15. @end
  16. @implementation WFCUFileRecordTableViewCell
  17. + (CGFloat)sizeOfRecord:(WFCCFileRecord *)record withCellWidth:(CGFloat)width {
  18. CGSize size1 = [WFCUUtilities getTextDrawingSize:record.name font:[UIFont systemFontOfSize:18] constrainedSize:CGSizeMake(width - 74, 48)];
  19. NSString *info = [NSString stringWithFormat:@"%@ 来自%@ %@", [WFCUUtilities formatTimeLabel:record.timestamp], [[WFCCIMService sharedWFCIMService] getUserInfo:record.userId inGroup:record.conversation.type == Group_Type ? record.conversation.target : nil refresh:NO].displayName, [WFCUUtilities formatSizeLable:record.size]];
  20. CGSize size2 = [WFCUUtilities getTextDrawingSize:info font:[UIFont systemFontOfSize:14] constrainedSize:CGSizeMake(width - 74, 40)];
  21. return 8 + size1.height + 8 + size2.height + 8;
  22. }
  23. - (void)awakeFromNib {
  24. [super awakeFromNib];
  25. // Initialization code
  26. for (UIView *view in self.subviews) {
  27. [view removeFromSuperview];
  28. }
  29. }
  30. - (void)setFileIcon:(NSString *)fileName {
  31. NSString *ext = [[fileName pathExtension] lowercaseString];
  32. self.iconView.image = [WFCUUtilities imageForExt:ext];
  33. }
  34. - (void)setFileRecord:(WFCCFileRecord *)fileRecord {
  35. _fileRecord = fileRecord;
  36. [self setFileIcon:fileRecord.name];
  37. self.nameLabel.text = self.fileRecord.name;
  38. CGSize size = [WFCUUtilities getTextDrawingSize:self.fileRecord.name font:[UIFont systemFontOfSize:18] constrainedSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 74, 48)];
  39. self.nameLabel.frame = CGRectMake(66, 8, size.width, size.height);
  40. NSString *sender = [[WFCCIMService sharedWFCIMService] getUserInfo:fileRecord.userId inGroup:fileRecord.conversation.type == Group_Type ? fileRecord.conversation.target : nil refresh:NO].displayName;
  41. if(!sender.length) {
  42. sender = fileRecord.userId;
  43. }
  44. NSString *info = [NSString stringWithFormat:@"%@ 来自", [WFCUUtilities formatTimeLabel:fileRecord.timestamp]];
  45. NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:info];
  46. [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:sender attributes:@{NSForegroundColorAttributeName : [UIColor blueColor]}]];
  47. [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@", [WFCUUtilities formatSizeLable:fileRecord.size]]]];
  48. self.infoLabel.attributedText = attStr;
  49. size = [WFCUUtilities getTextDrawingSize:attStr.string font:[UIFont systemFontOfSize:14] constrainedSize:CGSizeMake(self.bounds.size.width - 74, 40)];
  50. self.infoLabel.frame = CGRectMake(66, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height + 8, size.width, size.height);
  51. }
  52. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  53. [super setSelected:selected animated:animated];
  54. // Configure the view for the selected state
  55. }
  56. - (UIImageView *)iconView {
  57. if (!_iconView) {
  58. _iconView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, 50, 50)];
  59. [self.contentView addSubview:_iconView];
  60. }
  61. return _iconView;;
  62. }
  63. - (UILabel *)nameLabel {
  64. if (!_nameLabel) {
  65. _nameLabel = [[UILabel alloc] init];
  66. _nameLabel.font = [UIFont systemFontOfSize:18];
  67. _nameLabel.numberOfLines = 0;
  68. [self.contentView addSubview:_nameLabel];
  69. }
  70. return _nameLabel;
  71. }
  72. - (UILabel *)infoLabel {
  73. if (!_infoLabel) {
  74. _infoLabel = [[UILabel alloc] init];
  75. _infoLabel.font = [UIFont systemFontOfSize:14];
  76. _infoLabel.numberOfLines = 0;
  77. _infoLabel.textColor = [UIColor grayColor];
  78. [self.contentView addSubview:_infoLabel];
  79. }
  80. return _infoLabel;
  81. }
  82. @end