CalldetailsCell.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // CalldetailsCell.m
  3. // ABtong
  4. //
  5. // Created by qin on 2025/7/31.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "CalldetailsCell.h"
  9. #import <SDWebImage/UIImageView+WebCache.h>
  10. #import "config.h"
  11. @interface CalldetailsCell()
  12. @property (strong, nonatomic) UILabel *name;
  13. @property (strong, nonatomic) UILabel *time;
  14. @property (strong, nonatomic) UILabel *countText;
  15. @property (strong, nonatomic) UIImageView *rightAr;
  16. @property (strong, nonatomic) UILabel *lineLb;
  17. @end
  18. @implementation CalldetailsCell
  19. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  20. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  21. if (self) {
  22. [self initAlllSubviews];
  23. self.selectionStyle = UITableViewCellSelectionStyleNone;
  24. self.backgroundColor = [UIColor clearColor];
  25. }
  26. return self;
  27. }
  28. -(void)initAlllSubviews{
  29. _rightAr = [UIImageView new];
  30. _rightAr.contentMode = UIViewContentModeScaleAspectFill;
  31. [_rightAr setImage:[UIImage imageNamed:@"arrow-right"]];
  32. [self.contentView addSubview:_rightAr];
  33. // 名字
  34. _name = [UILabel new];
  35. _name.font = SYSFONT(18);
  36. _name.textColor = [UIColor whiteColor];
  37. [self.contentView addSubview:_name];
  38. // 时间
  39. _time = [UILabel new];
  40. _time.font = SYSFONT(14);
  41. _time.textColor = UIColor.whiteColor;
  42. [self.contentView addSubview:_time];
  43. // 时间
  44. _countText = [UILabel new];
  45. _countText.font = SYSFONT(16);
  46. _countText.textColor = UIColor.whiteColor;
  47. [self.contentView addSubview:_countText];
  48. _lineLb = [UILabel new];
  49. _lineLb.text = @"";
  50. _lineLb.backgroundColor = UIColor.lightGrayColor;
  51. [self.contentView addSubview:_lineLb];
  52. _lineLb.alpha = 0;
  53. [_rightAr mas_remakeConstraints:^(MASConstraintMaker *make) {
  54. make.right.equalTo(self.contentView.mas_right).offset(-30);
  55. make.top.mas_equalTo(self.contentView.mas_top).offset(20);
  56. make.width.mas_equalTo(20);
  57. make.height.mas_equalTo(20);
  58. }];
  59. [_name mas_remakeConstraints:^(MASConstraintMaker *make) {
  60. make.left.equalTo(self.contentView.mas_left).offset(18);
  61. make.top.mas_equalTo(self.contentView.mas_top).offset(12);
  62. }];
  63. [_time mas_remakeConstraints:^(MASConstraintMaker *make) {
  64. make.left.equalTo(self.contentView.mas_left).offset(18);
  65. make.top.mas_equalTo(_name.mas_bottom).offset(6);
  66. }];
  67. [_countText mas_remakeConstraints:^(MASConstraintMaker *make) {
  68. make.left.equalTo(_time.mas_right).offset(4);
  69. make.top.mas_equalTo(_name.mas_bottom).offset(6);
  70. }];
  71. [_lineLb mas_remakeConstraints:^(MASConstraintMaker *make) {
  72. make.top.mas_equalTo(self.contentView.mas_bottom).offset(-3);
  73. make.width.mas_equalTo(self.contentView.mas_width).offset(12);
  74. make.height.mas_equalTo(0.5);
  75. }];
  76. }
  77. - (void)fillWithData:( NSDictionary*)data {
  78. // NSLog(@"fillWithData:%@",data);
  79. //NSLog(@"lastTime:%@",data[@"lastTime"]);
  80. NSString *timestr =data[@"timestamp"];
  81. if([timestr isKindOfClass:[NSNumber class]]){
  82. self.name.text=[self timeF:timestr.longLongValue];
  83. }
  84. else if([timestr isKindOfClass:[NSString class]]){
  85. self.name.text=[self timeF:timestr.longLongValue];
  86. }
  87. else{
  88. self.name.text=@"";
  89. }
  90. NSString *chatId =data[@"chatId"]?:@"";
  91. NSString *fromId =data[@"fromId"]?:@"";
  92. if([chatId isEqualToString:fromId]){
  93. _time.text = @"呼入:";
  94. }
  95. else{
  96. _time.text = @"呼出:";
  97. }
  98. NSString *video =data[@"video"];
  99. if (video.intValue==0) {
  100. [_rightAr setImage:[UIImage imageNamed:@"callhuixiao"]];
  101. }
  102. else{
  103. [_rightAr setImage:[UIImage imageNamed:@"shipinth"]];
  104. }
  105. NSString *result =data[@"result"];
  106. NSString *duration = data[@"duration"];
  107. if(result.intValue == 1){
  108. _countText.text = [NSString stringWithFormat:@" %@",[self formatTimeWithMilliseconds:duration.intValue]];
  109. _countText.textColor = [UIColor whiteColor];
  110. }
  111. else{
  112. _countText.text = @"未接通";
  113. _countText.textColor = [UIColor redColor];
  114. }
  115. // tell constraints they need updating
  116. [self setNeedsUpdateConstraints];
  117. // update constraints now so we can animate the change
  118. [self updateConstraintsIfNeeded];
  119. [self layoutIfNeeded];
  120. }
  121. -(NSString *)timeF:(NSInteger)time{
  122. //NSLog(@"time:%ld",(long)time);
  123. // 创建日期格式器
  124. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  125. [formatter setDateFormat:@"dd"]; // 设置你想要的日期格式
  126. long long timestamp =(long)time/1000; // 例如:2021-10-01 00:00:00 UTC
  127. // 转换为NSDate
  128. NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp];
  129. NSString *dateString = [formatter stringFromDate:date];
  130. NSDate *now = [NSDate date];
  131. NSTimeInterval trt = [now timeIntervalSince1970];
  132. date = [NSDate dateWithTimeIntervalSince1970:trt];
  133. NSString *tdateString = [formatter stringFromDate:date];
  134. NSInteger shijiancha = trt-timestamp;
  135. if(shijiancha<60){
  136. return NSLocalizedString(@"1分钟内", @"");
  137. }
  138. if(shijiancha>24*3600||dateString.intValue!=tdateString.intValue){
  139. // 假设这是你的时间戳(以秒为单位)
  140. long long timestamp =(long)time/1000; // 例如:2021-10-01 00:00:00 UTC
  141. // 转换为NSDate
  142. NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp];
  143. // 创建日期格式器
  144. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  145. [formatter setDateFormat:@"yyyy-MM-dd HH:mm"]; // 设置你想要的日期格式
  146. // 转换为字符串
  147. NSString *dateString = [formatter stringFromDate:date];
  148. return dateString;
  149. }
  150. else{
  151. NSInteger xiaoshi = shijiancha/3600;
  152. NSInteger fenzhong = shijiancha/60;
  153. if(xiaoshi>0){
  154. // 假设这是你的时间戳(以秒为单位)
  155. long long timestamp =(long)time/1000; // 例如:2021-10-01 00:00:00 UTC
  156. // 转换为NSDate
  157. NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp];
  158. // 创建日期格式器
  159. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  160. [formatter setDateFormat:@"HH:mm"]; // 设置你想要的日期格式
  161. // 转换为字符串
  162. NSString *dateString = [formatter stringFromDate:date];
  163. return dateString;
  164. }
  165. else{
  166. return [NSString stringWithFormat:@"%ld%@",(long)fenzhong,NSLocalizedString(@"分钟前", @"")];
  167. }
  168. }
  169. return @"";
  170. }
  171. - (NSString *)formatTimeWithMilliseconds:(NSInteger)milliseconds{
  172. NSInteger seconds = milliseconds / 1000.0;
  173. if (seconds >= 60) {
  174. // 大于等于60秒时显示为分钟,保留一位小数
  175. NSInteger minutes = seconds / 60.0;
  176. NSInteger sc = seconds%60;
  177. return [NSString stringWithFormat:@"%ld分%ld秒", (long)minutes,(long)sc];
  178. } else {
  179. // 小于60秒时显示为秒,保留整数
  180. return [NSString stringWithFormat:@"%ld秒", seconds];
  181. }
  182. }
  183. @end