// // NASMySpaceTableViewCell.m // 双子星云手机 // // Created by xd h on 2024/6/21. // #import "NASMySpaceTableViewCell.h" @interface NASMySpaceTableViewCell () @property(nonatomic,strong) UIImageView *typeImageView; @property(nonatomic,strong) UILabel *diskNameLabel; @property(nonatomic,strong) UIView *progressBgView; @property(nonatomic,strong) UIView *progressSelectView; @property(nonatomic,strong) CAGradientLayer *glayer; @property(nonatomic,strong) UILabel *totalLabel; @property(nonatomic,strong) UILabel *usedlabel; //@property(nonatomic,strong) UILabel *unuselabel; @end @implementation NASMySpaceTableViewCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self drawView]; } return self; } - (void)drawView { UIView *whiteBgView = [UIView new]; whiteBgView.backgroundColor = [UIColor whiteColor]; whiteBgView.layer.cornerRadius = 8; whiteBgView.layer.masksToBounds = YES; [self.contentView addSubview:whiteBgView]; [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.height.mas_equalTo(110); make.bottom.mas_equalTo(0); }]; _typeImageView = [[UIImageView alloc] init]; //_typeImageView.backgroundColor = [UIColor greenColor]; [whiteBgView addSubview:_typeImageView]; [_typeImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.top.mas_equalTo(15); make.width.mas_equalTo(32); make.height.mas_equalTo(32); }]; _diskNameLabel = [[UILabel alloc] init]; _diskNameLabel.font = [UIFont systemFontOfSize:14.0]; _diskNameLabel.textColor = [UIColor blackColor]; //_fileNamelabel.backgroundColor = [UIColor greenColor]; [whiteBgView addSubview:_diskNameLabel]; [_diskNameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(_typeImageView.mas_right).offset(8); make.right.mas_equalTo(-18); make.centerY.equalTo(_typeImageView.mas_centerY).offset(0); //make.height.mas_equalTo(20); }]; _progressBgView = [[UIView alloc] init]; _progressBgView.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0]; _progressBgView.layer.cornerRadius = 3; _progressBgView.layer.masksToBounds = YES; [whiteBgView addSubview:_progressBgView]; [_progressBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(16); make.right.mas_equalTo(-18); make.height.mas_equalTo(6); make.top.equalTo(_typeImageView.mas_bottom).offset(10); }]; _progressSelectView = [[UIView alloc] init]; //_progressSelectView.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0]; _progressSelectView.layer.cornerRadius = 3; _progressSelectView.layer.masksToBounds = YES; [_progressBgView addSubview:_progressSelectView]; // gradient _glayer = [CAGradientLayer layer]; _glayer.startPoint = CGPointMake(0, 0.5); _glayer.endPoint = CGPointMake(1, 0.5); _glayer.colors = @[(__bridge id)[UIColor hwColor:@"#0BDDFD" alpha:1.0].CGColor, (__bridge id)[UIColor hwColor:@"#048CFB" alpha:1.0].CGColor]; _glayer.locations = @[@(0), @(1.0f)]; [_progressSelectView.layer addSublayer:_glayer]; CGFloat butWidth = (SCREEN_W - 16*2 - 16*2)/2.0; _totalLabel = [[UILabel alloc] init]; _totalLabel.font = [UIFont systemFontOfSize:12.0]; _totalLabel.textColor = [UIColor hwColor:@"#818CA2"]; //_fileNamelabel.backgroundColor = [UIColor greenColor]; _totalLabel.textAlignment = NSTextAlignmentRight; [whiteBgView addSubview:_totalLabel]; [_totalLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-16); make.width.mas_equalTo(butWidth); make.top.mas_equalTo(_progressBgView.mas_bottom).offset(10); }]; _usedlabel = [[UILabel alloc] init]; _usedlabel.font = [UIFont systemFontOfSize:12.0]; _usedlabel.textColor = [UIColor hwColor:@"#818CA2"]; //_usedlabel.textAlignment = NSTextAlignmentCenter; //_usedlabel.backgroundColor = [UIColor greenColor]; [whiteBgView addSubview:_usedlabel]; [_usedlabel mas_makeConstraints:^(MASConstraintMaker *make) { //make.left.mas_equalTo(_totalLabel.mas_right); make.left.mas_equalTo(16); make.width.mas_equalTo(butWidth); make.top.mas_equalTo(_progressBgView.mas_bottom).offset(10); }]; // _unuselabel = [[UILabel alloc] init]; // _unuselabel.font = [UIFont systemFontOfSize:12.0]; // _unuselabel.textColor = [UIColor hwColor:@"#818CA2"]; // _unuselabel.textAlignment = NSTextAlignmentRight; // //_unuselabel.backgroundColor = [UIColor greenColor]; // [whiteBgView addSubview:_unuselabel]; // // [_unuselabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.right.mas_equalTo(-13); // make.width.mas_equalTo(butWidth); // make.top.mas_equalTo(_progressBgView.mas_bottom).offset(10); // }]; } - (void)setExtraFileModel:(cloudPhoneExtraFileModel *)extraFileModel { _extraFileModel = extraFileModel; KWeakSelf dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf delayedSetDataFun]; }); } - (void)delayedSetDataFun { if([_extraFileModel.extraPath containsString:@"/sdcard/"]){ _typeImageView.image = [UIImage imageNamed:@"nas_disk_phone"]; _diskNameLabel.text = NSLocalizedString(@"NAS_cloudPhone_Space",nil); } else{ _typeImageView.image = [UIImage imageNamed:@"nas_disk_u"]; _diskNameLabel.text = _extraFileModel.name; } long allExtraAvableSize = _extraFileModel.extraAvableSize; long allExtraTotalSize = _extraFileModel.extraTotalSize; if(allExtraTotalSize == 0){ return; } CGFloat rate = (allExtraTotalSize-allExtraAvableSize) /(allExtraTotalSize*1.0); CGRect frame = _progressBgView.bounds; frame.size.width = frame.size.width * rate; if (!isnan(frame.size.width)) { _progressSelectView.frame = frame; _glayer.frame = frame; } // 计算 大小 //CGFloat extraAvableSizeF = allExtraAvableSize / 1024.0 /1024.0/1024.0; CGFloat extraTotalSizeF = allExtraTotalSize / 1024.0 /1024.0/1024.0; CGFloat extraUsedSizeF = (allExtraTotalSize-allExtraAvableSize) / 1024.0 /1024.0/1024.0; NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%.2fGB",NSLocalizedString(@"NAS_disk_Total_title",nil),extraTotalSizeF]; if(extraTotalSizeF > 1024){ extraTotalSizeF = extraTotalSizeF/1024.0; totalStr = [[NSString alloc] initWithFormat:@"%@%.2fTB",NSLocalizedString(@"NAS_disk_Total_title",nil),extraTotalSizeF]; } _totalLabel.text = totalStr; NSString *usedStr = [[NSString alloc] initWithFormat:@"%@%.2fGB",NSLocalizedString(@"NAS_disk_used_Space",nil),extraUsedSizeF]; if(extraTotalSizeF > 1024){ extraUsedSizeF = extraUsedSizeF/1024.0; usedStr = [[NSString alloc] initWithFormat:@"%@%.2fTB",NSLocalizedString(@"NAS_disk_used_Space",nil),extraUsedSizeF]; } _usedlabel.text = usedStr; // NSString *unusedStr = [[NSString alloc] initWithFormat:@"%@%.2fGB",NSLocalizedString(@"NAS_disk_unuse_Space",nil),extraAvableSizeF]; // if(extraAvableSizeF > 1024){ // extraAvableSizeF = extraAvableSizeF/1024.0; // unusedStr = [[NSString alloc] initWithFormat:@"%@%.2fTB",NSLocalizedString(@"NAS_disk_unuse_Space",nil),extraAvableSizeF]; // } // _unuselabel.text = unusedStr; } @end