| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- //
- // CalldetailsCell.m
- // ABtong
- //
- // Created by qin on 2025/7/31.
- //
- #import <Foundation/Foundation.h>
- #import "CalldetailsCell.h"
- #import <SDWebImage/UIImageView+WebCache.h>
- #import "config.h"
- @interface CalldetailsCell()
- @property (strong, nonatomic) UILabel *name;
- @property (strong, nonatomic) UILabel *time;
- @property (strong, nonatomic) UILabel *countText;
- @property (strong, nonatomic) UIImageView *rightAr;
- @property (strong, nonatomic) UILabel *lineLb;
- @end
- @implementation CalldetailsCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self initAlllSubviews];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
- }
- return self;
- }
- -(void)initAlllSubviews{
-
- _rightAr = [UIImageView new];
- _rightAr.contentMode = UIViewContentModeScaleAspectFill;
- [_rightAr setImage:[UIImage imageNamed:@"arrow-right"]];
- [self.contentView addSubview:_rightAr];
-
-
- // 名字
- _name = [UILabel new];
- _name.font = SYSFONT(18);
- _name.textColor = [UIColor whiteColor];
- [self.contentView addSubview:_name];
-
- // 时间
- _time = [UILabel new];
- _time.font = SYSFONT(14);
- _time.textColor = UIColor.whiteColor;
- [self.contentView addSubview:_time];
-
- // 时间
- _countText = [UILabel new];
- _countText.font = SYSFONT(16);
- _countText.textColor = UIColor.whiteColor;
- [self.contentView addSubview:_countText];
-
- _lineLb = [UILabel new];
- _lineLb.text = @"";
- _lineLb.backgroundColor = UIColor.lightGrayColor;
- [self.contentView addSubview:_lineLb];
- _lineLb.alpha = 0;
-
-
- [_rightAr mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView.mas_right).offset(-30);
- make.top.mas_equalTo(self.contentView.mas_top).offset(20);
- make.width.mas_equalTo(20);
- make.height.mas_equalTo(20);
- }];
-
- [_name mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView.mas_left).offset(18);
- make.top.mas_equalTo(self.contentView.mas_top).offset(12);
- }];
-
- [_time mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView.mas_left).offset(18);
- make.top.mas_equalTo(_name.mas_bottom).offset(6);
- }];
-
- [_countText mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(_time.mas_right).offset(4);
- make.top.mas_equalTo(_name.mas_bottom).offset(6);
- }];
-
- [_lineLb mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.contentView.mas_bottom).offset(-3);
- make.width.mas_equalTo(self.contentView.mas_width).offset(12);
- make.height.mas_equalTo(0.5);
- }];
-
-
- }
- - (void)fillWithData:( NSDictionary*)data {
-
- // NSLog(@"fillWithData:%@",data);
-
- //NSLog(@"lastTime:%@",data[@"lastTime"]);
- NSString *timestr =data[@"timestamp"];
-
- if([timestr isKindOfClass:[NSNumber class]]){
- self.name.text=[self timeF:timestr.longLongValue];
- }
- else if([timestr isKindOfClass:[NSString class]]){
- self.name.text=[self timeF:timestr.longLongValue];
- }
- else{
- self.name.text=@"";
- }
-
- NSString *chatId =data[@"chatId"]?:@"";
- NSString *fromId =data[@"fromId"]?:@"";
- if([chatId isEqualToString:fromId]){
- _time.text = @"呼入:";
- }
- else{
- _time.text = @"呼出:";
- }
-
- NSString *video =data[@"video"];
- if (video.intValue==0) {
- [_rightAr setImage:[UIImage imageNamed:@"callhuixiao"]];
- }
- else{
- [_rightAr setImage:[UIImage imageNamed:@"shipinth"]];
- }
-
-
-
-
-
- NSString *result =data[@"result"];
- NSString *duration = data[@"duration"];
- if(result.intValue == 1){
- _countText.text = [NSString stringWithFormat:@" %@",[self formatTimeWithMilliseconds:duration.intValue]];
- _countText.textColor = [UIColor whiteColor];
- }
- else{
- _countText.text = @"未接通";
- _countText.textColor = [UIColor redColor];
- }
- // tell constraints they need updating
- [self setNeedsUpdateConstraints];
- // update constraints now so we can animate the change
- [self updateConstraintsIfNeeded];
- [self layoutIfNeeded];
- }
- -(NSString *)timeF:(NSInteger)time{
- //NSLog(@"time:%ld",(long)time);
- // 创建日期格式器
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- [formatter setDateFormat:@"dd"]; // 设置你想要的日期格式
-
-
- long long timestamp =(long)time/1000; // 例如:2021-10-01 00:00:00 UTC
- // 转换为NSDate
- NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp];
- NSString *dateString = [formatter stringFromDate:date];
-
-
- NSDate *now = [NSDate date];
- NSTimeInterval trt = [now timeIntervalSince1970];
- date = [NSDate dateWithTimeIntervalSince1970:trt];
- NSString *tdateString = [formatter stringFromDate:date];
-
-
- NSInteger shijiancha = trt-timestamp;
-
- if(shijiancha<60){
- return NSLocalizedString(@"1分钟内", @"");
- }
- if(shijiancha>24*3600||dateString.intValue!=tdateString.intValue){
- // 假设这是你的时间戳(以秒为单位)
- long long timestamp =(long)time/1000; // 例如:2021-10-01 00:00:00 UTC
- // 转换为NSDate
- NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp];
- // 创建日期格式器
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- [formatter setDateFormat:@"yyyy-MM-dd HH:mm"]; // 设置你想要的日期格式
- // 转换为字符串
- NSString *dateString = [formatter stringFromDate:date];
- return dateString;
- }
- else{
- NSInteger xiaoshi = shijiancha/3600;
- NSInteger fenzhong = shijiancha/60;
- if(xiaoshi>0){
- // 假设这是你的时间戳(以秒为单位)
- long long timestamp =(long)time/1000; // 例如:2021-10-01 00:00:00 UTC
- // 转换为NSDate
- NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp];
- // 创建日期格式器
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- [formatter setDateFormat:@"HH:mm"]; // 设置你想要的日期格式
- // 转换为字符串
- NSString *dateString = [formatter stringFromDate:date];
- return dateString;
- }
- else{
- return [NSString stringWithFormat:@"%ld%@",(long)fenzhong,NSLocalizedString(@"分钟前", @"")];
- }
- }
-
- return @"";
- }
- - (NSString *)formatTimeWithMilliseconds:(NSInteger)milliseconds{
- NSInteger seconds = milliseconds / 1000.0;
-
- if (seconds >= 60) {
- // 大于等于60秒时显示为分钟,保留一位小数
- NSInteger minutes = seconds / 60.0;
- NSInteger sc = seconds%60;
- return [NSString stringWithFormat:@"%ld分%ld秒", (long)minutes,(long)sc];
- } else {
- // 小于60秒时显示为秒,保留整数
- return [NSString stringWithFormat:@"%ld秒", seconds];
- }
- }
- @end
|