JXTalkCell.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // JXTalkCell.m
  3. // shiku_im
  4. //
  5. // Created by p on 2019/6/18.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXTalkCell.h"
  9. @interface JXTalkCell()
  10. @property (nonatomic, strong) UIImageView *headImage;
  11. @property (nonatomic, strong) UILabel *userName;
  12. @property (nonatomic, strong) UILabel *lastTime;
  13. @property (nonatomic, strong) UILabel *talkTime;
  14. @property (nonatomic, strong) NSTimer *timer;
  15. @end
  16. @implementation JXTalkCell
  17. - (void)awakeFromNib {
  18. [super awakeFromNib];
  19. // Initialization code
  20. }
  21. - (instancetype)initWithFrame:(CGRect)frame {
  22. if ([super initWithFrame:frame]) {
  23. [self customView];
  24. [g_notify addObserver:self selector:@selector(talkAction:) name:@"TalkActionNotfi" object:nil];
  25. }
  26. return self;
  27. }
  28. //- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  29. //{
  30. // self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  31. //
  32. // if (self) {
  33. //
  34. // [self customView];
  35. // [g_notify addObserver:self selector:@selector(talkAction:) name:@"TalkActionNotfi" object:nil];
  36. // }
  37. // return self;
  38. //
  39. //}
  40. - (void)dealloc {
  41. [g_notify removeObserver:self];
  42. }
  43. - (void)talkAction:(NSNotification *)notif {
  44. NSDictionary *dict = notif.object;
  45. if ([[dict objectForKey:@"userId"] isEqualToString:_talkModel.userId]) {
  46. if ([[dict objectForKey:@"type"] isEqualToString:@"1"]) {
  47. // _headImage.layer.borderWidth = 2;
  48. _talkModel.talkTime = 1;
  49. _talkModel.lastTime = [[NSDate date] timeIntervalSince1970];
  50. _talkTime.text = [TimeUtil getTimeShort1:_talkModel.talkTime];
  51. _lastTime.text = [TimeUtil formatDate:[NSDate dateWithTimeIntervalSince1970:_talkModel.lastTime] format:@"HH:mm:ss"];
  52. _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
  53. }else {
  54. [_timer invalidate];
  55. _timer = nil;
  56. _headImage.layer.borderWidth = 0;
  57. }
  58. }
  59. }
  60. - (void)timerAction:(NSTimer *)timer {
  61. _talkModel.talkTime ++;
  62. _talkTime.text = [TimeUtil getTimeShort1:_talkModel.talkTime];
  63. }
  64. - (void)customView {
  65. _headImage = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, 52, 52)];
  66. _headImage.layer.cornerRadius = _headImage.frame.size.width / 2;
  67. _headImage.layer.masksToBounds = YES;
  68. _headImage.layer.borderColor = [UIColor redColor].CGColor;
  69. [self addSubview:_headImage];
  70. _userName = [[UILabel alloc] initWithFrame:CGRectMake(12, CGRectGetMaxY(_headImage.frame) + 14, 92 - 24, 13)];
  71. _userName.textAlignment = NSTextAlignmentCenter;
  72. _userName.textColor = HEXCOLOR(0x999999);
  73. _userName.font = [UIFont systemFontOfSize:13.0];
  74. [self addSubview:_userName];
  75. // _lastTime = [[UILabel alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 100, 10, 100, 20)];
  76. // _lastTime.textColor = [UIColor lightGrayColor];
  77. // _lastTime.font = [UIFont systemFontOfSize:15.0];
  78. // [self addSubview:_lastTime];
  79. //
  80. // UILabel *lastTip = [[UILabel alloc] initWithFrame:CGRectMake(_lastTime.frame.origin.x - 100, 10, 100, 20)];
  81. // lastTip.textColor = [UIColor lightGrayColor];
  82. // lastTip.font = [UIFont systemFontOfSize:15.0];
  83. // lastTip.text = Localized(@"JX_LastGrabWheat:");
  84. // lastTip.textAlignment = NSTextAlignmentRight;
  85. // [self addSubview:lastTip];
  86. //
  87. // _talkTime = [[UILabel alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 100, CGRectGetMaxY(_lastTime.frame), 100, 20)];
  88. // _talkTime.textColor = [UIColor lightGrayColor];
  89. // _talkTime.font = [UIFont systemFontOfSize:15.0];
  90. // [self addSubview:_talkTime];
  91. //
  92. // UILabel *talkTip = [[UILabel alloc] initWithFrame:CGRectMake(_talkTime.frame.origin.x - 100, CGRectGetMaxY(lastTip.frame), 100, 20)];
  93. // talkTip.textColor = [UIColor lightGrayColor];
  94. // talkTip.font = [UIFont systemFontOfSize:15.0];
  95. // talkTip.text = Localized(@"JX_SpeechTime:");
  96. // talkTip.textAlignment = NSTextAlignmentRight;
  97. // [self addSubview:talkTip];
  98. //
  99. // UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 60 - .5, JX_SCREEN_WIDTH, .5)];
  100. // line.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1];
  101. // [self addSubview:line];
  102. }
  103. - (void)setTalkModel:(JXTalkModel *)talkModel {
  104. _talkModel = talkModel;
  105. [g_server getHeadImageSmall:talkModel.userId userName:talkModel.userName imageView:_headImage];
  106. _userName.text = talkModel.userName;
  107. // if (talkModel.lastTime > 0) {
  108. // _lastTime.text = [TimeUtil formatDate:[NSDate dateWithTimeIntervalSince1970:talkModel.lastTime] format:@"HH:mm:ss"];
  109. // }else {
  110. // _lastTime.text = nil;
  111. // }
  112. //
  113. // if (talkModel.talkTime > 0) {
  114. // _talkTime.text = [TimeUtil getTimeShort1:talkModel.talkTime];
  115. // }else {
  116. // _talkTime.text = nil;
  117. // }
  118. }
  119. @end