123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- //
- // uploadFileBottomView.m
- // 隐私保护
- //
- // Created by xd h on 2023/11/10.
- //
- #import "uploadFileBottomView.h"
- #import "TZAssetModel+imageData.h"
- #import "nasUploadFileManager.h"
- @interface uploadFileBottomView ()
- {
- BOOL isCanUpload;
- }
- @property(nonatomic,strong)UILabel *selectNumLabel;
- @property(nonatomic,strong)UILabel *uploadFileRoutelabel;
- @property(nonatomic,strong)UIButton *uploadButon;
- @end
- @implementation uploadFileBottomView
- - (id)initWithFrame:(CGRect)frame{
- self = [super initWithFrame:frame];
- [self setBackgroundColor:[UIColor whiteColor]];
- [self drawAnyView];
-
- return self;
- }
- - (void)drawAnyView{
- _selectNumLabel = [[UILabel alloc] init];
- _selectNumLabel.font = [UIFont boldSystemFontOfSize:16.0];
- _selectNumLabel.textColor = [UIColor blackColor];
- [self addSubview:_selectNumLabel];
-
- [_selectNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(15);
- make.top.mas_equalTo(10);
- make.right.mas_equalTo(-110);
- make.height.mas_equalTo(20);
- }];
-
- //设置即得标题
- self.indexPathsForSelectedItems = [NSMutableArray new];
-
- _uploadFileRoutelabel = [[UILabel alloc] init];
- //_uploadFileRoutelabel.font = [UIFont systemFontOfSize:14.0];
- //_uploadFileRoutelabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
- _uploadFileRoutelabel.textColor =[UIColor hwColor:@"#01B7EA" alpha:1.0];
- [self addSubview:_uploadFileRoutelabel];
- _uploadFileRoutelabel.adjustsFontSizeToFitWidth = YES;
-
- [self setSavePathDataFun];
-
- [_uploadFileRoutelabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(15);
- make.top.mas_equalTo(_selectNumLabel.mas_bottom).offset(12);
- make.right.mas_equalTo(-110);
- make.height.mas_equalTo(15);
- }];
-
- UIView *tapView = [[UIView alloc] init];
- //tapView.backgroundColor = [UIColor redColor];
- [self addSubview:tapView];
-
- [tapView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.top.mas_equalTo(0);
- make.right.mas_equalTo(-110);
- make.bottom.mas_equalTo(10);
- }];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBottomViewFun)];
- [tapView addGestureRecognizer:tap];
-
- //图片上传
- NSString* curImgUploadStr = [[NSString alloc] initWithFormat:@"%@ %@",@"",NSLocalizedString(@"my_set_no_File_upload",nil)];
-
-
- // gradient
- CAGradientLayer *gl_But = [CAGradientLayer layer];
- gl_But.frame = CGRectMake(0,0,88.f,40.f);
- gl_But.startPoint = CGPointMake(0, 0.5);
- gl_But.endPoint = CGPointMake(1, 0.5);
- gl_But.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
- gl_But.locations = @[@(0), @(1.0f)];
- gl_But.cornerRadius = 8;
-
-
- UIButton *imageUploadBut = [[UIButton alloc] init];
-
-
- [imageUploadBut setImage:[UIImage imageNamed:@"upload_file_white_100"] forState:UIControlStateNormal];
- [imageUploadBut setTitle:curImgUploadStr forState:UIControlStateNormal];
-
- [imageUploadBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- imageUploadBut.titleLabel.font = [UIFont boldSystemFontOfSize:13.0];
- imageUploadBut.tag = 2;
- [imageUploadBut addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:imageUploadBut];
- [imageUploadBut.layer insertSublayer:gl_But atIndex:0];
- [imageUploadBut bringSubviewToFront:imageUploadBut.imageView];
-
- self.uploadButon = imageUploadBut;
-
- //imageUploadBut.backgroundColor = [UIColor redColor];
- //多国语言适配
- NSString *languageCode = [NSLocale preferredLanguages][0];
- if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
- {
- imageUploadBut.titleLabel.font = [UIFont systemFontOfSize:10.0];
- }
-
- [imageUploadBut mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(-10);
- make.top.mas_equalTo(10);
- make.width.mas_equalTo(98);
- make.height.mas_equalTo(40);
- }];
-
- imageUploadBut.enabled = NO;
- imageUploadBut.alpha = 0.5;
- }
- #pragma mark 数据处理
- - (void)setIndexPathsForSelectedItems:(NSMutableArray *)indexPathsForSelectedItems
- {
- isCanUpload = YES;
-
- _indexPathsForSelectedItems = indexPathsForSelectedItems;
- if(!_indexPathsForSelectedItems){
- _indexPathsForSelectedItems = [NSMutableArray new];
- }
-
- //TZAssetModel imageData (以字节为单位)
- NSUInteger allImageData = 0;
-
- for (TZAssetModel* model in _indexPathsForSelectedItems) {
-
- // if(model.type == TZAssetModelMediaTypeVideo){
- // allImageData += [model.videoData length];
- // }
- // else{
- // allImageData += [model.imageData length];
- // }
-
- allImageData += model.totalBytes;
-
- }
-
- if(self.available <= 0 || allImageData > self.available){
- isCanUpload = NO;
- }
-
- allImageData /= 1024;
-
- NSString *byteStr = nil;
- NSString *unitStr = @"KB";
-
- if(allImageData < 1024){
- byteStr = [[NSString alloc] initWithFormat:@"%ld",allImageData];
- }
- else if( allImageData >= 1024 && allImageData < 1024*1024){
- byteStr = [[NSString alloc] initWithFormat:@"%.2f",allImageData/1024.0];
- unitStr = @"MB";
- }
- else{
- byteStr = [[NSString alloc] initWithFormat:@"%.2f",allImageData/1024.0/1024.0];
- unitStr = @"G";
- }
-
- if(!_availableStorage){
- _availableStorage = @"--";
- }
-
- NSString *curStr1 = [NSString stringWithFormat:@"已选%ld项",_indexPathsForSelectedItems.count];
- NSString *curStr2 = [NSString stringWithFormat:@"(%@%@,%@)",byteStr,unitStr,_availableStorage];
- NSString *totalStr = [[NSString alloc] initWithFormat:@"%@ %@",curStr1,curStr2];
-
- NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
-
- NSRange redRange = NSMakeRange([totalStr rangeOfString:curStr2].location, [totalStr rangeOfString:curStr2].length);
-
- UIColor *noteColor =[UIColor hwColor:@"#959799" alpha:1.0];
- if(!isCanUpload){
- noteColor = [UIColor redColor];
- }
-
- [noteStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
- [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:redRange];
- // 设置行间距
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:5]; //设置行间距
-
- [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
- _selectNumLabel.attributedText = noteStr;
-
- if(_isExtraFileAndNotFindPathType){
- isCanUpload = YES;
- }
-
- if(_indexPathsForSelectedItems.count > 0 && isCanUpload){
- // self.uploadButon.enabled = YES;
- // self.uploadButon.alpha = 1;
- }
- else
- {
- self.uploadButon.enabled = NO;
- self.uploadButon.alpha = 0.5;
- }
- }
- //上传按钮是否可以交互
- - (void)setUploadButtonCanClickFunBy:(BOOL)canClick
- {
- //if(canClick && _isExtraFileAndNotFindPathType)
- if(canClick && isCanUpload)
- {
- self.uploadButon.enabled = YES;
- self.uploadButon.alpha = 1;
- }
- else
- {
- self.uploadButon.enabled = NO;
- self.uploadButon.alpha = 0.5;
- }
- }
- - (void)setSavePathDataFun
- {
- NSString *savePath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)];
- if(!savePath||savePath.length == 0){
- savePath = Const_default_upload_path;
- }
-
- NSString *uploadDefaultPath = savePath;
-
- uploadDefaultPath = [iTools changePathToShowPathBy:uploadDefaultPath];
-
- _uploadFileRoutelabel.text = [[NSString alloc] initWithFormat:@"%@: %@",NSLocalizedString(@"File_upload_path_tip",nil),uploadDefaultPath];
- }
- #pragma mark 按钮点击
- - (void)didClickButFun:(UIButton*)but
- {
-
- //1.4.3 新需求 有传输任务超过200个时 不给上传
- if([nasUploadFileManager shareInstance].uploadingArr.count >= 200){
- [[iToast makeText:NSLocalizedString(@"upload_task_not_done_tip",nil)] show];
- return;
- }
-
- if(_isExtraFileAndNotFindPathType){
- [[iToast makeText:NSLocalizedString(@"upload_file_and_not_path_tip",nil)] show];
- return;
- }
-
- if(_didClickUploadFile)
- {
- _didClickUploadFile();
- }
- }
- - (void)tapBottomViewFun
- {
- if(_didClickbottomFun)
- {
- _didClickbottomFun();
- }
-
- }
- @end
|