FavoritesAudioCell.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // FavoritesAudioCell.m
  3. // AIIM
  4. //
  5. // Created by qitewei on 2025/4/30.
  6. //
  7. #import "FavoritesAudioCell.h"
  8. #import "Masonry.h"
  9. #import "config.h"
  10. @interface FavoritesAudioCell()
  11. @property (nonatomic, strong) UILabel * contentLbl;
  12. @property (nonatomic, strong) UILabel * timeLbl;
  13. @property (nonatomic, strong) UIImageView * typeImageView;
  14. @end
  15. @implementation FavoritesAudioCell
  16. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  17. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  18. [self configUI];
  19. }
  20. return self;
  21. }
  22. - (void)configUI{
  23. self.contentView.backgroundColor = globalColor(GCTypeDark6);
  24. [self.contentView addSubview:self.typeImageView];
  25. [self.typeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.size.mas_equalTo(CGSizeMake(60, 60));
  27. make.right.mas_equalTo(-20);
  28. make.top.mas_equalTo(16);
  29. make.bottom.mas_equalTo(-16);
  30. }];
  31. [self.contentView addSubview:self.timeLbl];
  32. [self.timeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.height.mas_equalTo(12);
  34. make.left.mas_equalTo(20);
  35. make.bottom.mas_equalTo(-24);
  36. }];
  37. [self.contentView addSubview:self.contentLbl];
  38. [self.contentLbl mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.height.mas_equalTo(14);
  40. make.left.mas_equalTo(20);
  41. make.right.mas_equalTo(self.typeImageView.mas_left).offset(-12);
  42. make.bottom.mas_equalTo(self.timeLbl.mas_top).offset(-12);
  43. }];
  44. }
  45. - (void)setMsg:(NSDictionary *)msg{
  46. _msg = msg;
  47. NSString *extend = msg[@"extend"];
  48. NSData *data = [extend dataUsingEncoding:NSUTF8StringEncoding];
  49. NSError *error;
  50. NSDictionary *extendDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  51. if ([msg[@"messageType"] isEqualToString:@"3"]) {
  52. self.typeImageView.image = kImageMake(@"audio_icon");
  53. if ([extendDict jk_hasKey:@"time"]) {
  54. self.contentLbl.text = [NSString stringWithFormat:@"%@''",extendDict[@"time"]];
  55. }
  56. }else{
  57. self.contentLbl.text = extendDict[@"fileName"]?:@"";
  58. self.typeImageView.image = kImageMake(@"file_icon");
  59. }
  60. self.timeLbl.text = msg[@"createTime"];
  61. }
  62. #pragma mark lazy
  63. - (UILabel *)contentLbl{
  64. if (!_contentLbl) {
  65. _contentLbl = [[UILabel alloc] init];
  66. _contentLbl.textColor = UIColor.whiteColor;
  67. _contentLbl.font = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
  68. }
  69. return _contentLbl;
  70. }
  71. - (UILabel *)timeLbl{
  72. if (!_timeLbl) {
  73. _timeLbl = [[UILabel alloc] init];
  74. _timeLbl.textColor = globalColor(GCTypeDark7);
  75. _timeLbl.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
  76. }
  77. return _timeLbl;
  78. }
  79. - (UIImageView *)typeImageView{
  80. if (!_typeImageView) {
  81. _typeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"audio_icon"]];
  82. }
  83. return _typeImageView;
  84. }
  85. @end