downloadFileBottomView.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // downloadFileBottomView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/8.
  6. //
  7. #import "downloadFileBottomView.h"
  8. #import <sys/mount.h>
  9. #include <sys/param.h>
  10. @interface downloadFileBottomView ()
  11. @property(nonatomic,strong)UILabel *selectNumLabel;
  12. @property(nonatomic,strong)UILabel *uploadFileRoutelabel;
  13. @property(nonatomic,strong)UIButton *uploadButon;
  14. @end
  15. @implementation downloadFileBottomView
  16. - (id)initWithFrame:(CGRect)frame{
  17. self = [super initWithFrame:frame];
  18. [self setBackgroundColor:[UIColor whiteColor]];
  19. [self drawAnyView];
  20. _availableStorage = [self freeDiskSpaceInBytes];
  21. return self;
  22. }
  23. - (NSString *)freeDiskSpaceInBytes{
  24. struct statfs buf;
  25. unsigned long long freeSpace = -1;
  26. if (statfs("/var", &buf) >= 0) {
  27. freeSpace = (unsigned long long)(buf.f_bsize * buf.f_bavail);
  28. }
  29. NSString *str = [NSString stringWithFormat:@"%0.2f GB",freeSpace/1024.0/1024.0/1024.0];
  30. return str;
  31. }
  32. - (void)drawAnyView{
  33. _selectNumLabel = [[UILabel alloc] init];
  34. _selectNumLabel.font = [UIFont boldSystemFontOfSize:16.0];
  35. [self addSubview:_selectNumLabel];
  36. [_selectNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.mas_equalTo(15);
  38. make.top.mas_equalTo(10);
  39. make.right.mas_equalTo(-110);
  40. make.height.mas_equalTo(20);
  41. }];
  42. //设置即得标题
  43. self.indexPathsForSelectedItems = [NSMutableArray new];
  44. _uploadFileRoutelabel = [[UILabel alloc] init];
  45. _uploadFileRoutelabel.font = [UIFont systemFontOfSize:14.0];
  46. _uploadFileRoutelabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  47. _uploadFileRoutelabel.text = NSLocalizedString(@"File_download_Path_default",nil);
  48. [self addSubview:_uploadFileRoutelabel];
  49. [_uploadFileRoutelabel mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.left.mas_equalTo(15);
  51. make.top.mas_equalTo(_selectNumLabel.mas_bottom).offset(10);
  52. make.right.mas_equalTo(-110);
  53. make.height.mas_equalTo(20);
  54. }];
  55. //图片上传
  56. NSString* curImgUploadStr = [[NSString alloc] initWithFormat:@"%@ %@",@" ",NSLocalizedString(@"my_set_no_File_download",nil)];
  57. // gradient
  58. CAGradientLayer *gl_But = [CAGradientLayer layer];
  59. gl_But.frame = CGRectMake(0,0,88.f,40.f);
  60. gl_But.startPoint = CGPointMake(0, 0.5);
  61. gl_But.endPoint = CGPointMake(1, 0.5);
  62. gl_But.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  63. gl_But.locations = @[@(0), @(1.0f)];
  64. gl_But.cornerRadius = 8;
  65. UIButton *imageUploadBut = [[UIButton alloc] init];
  66. [imageUploadBut setImage:[UIImage imageNamed:@"donwload_file_white_100"] forState:UIControlStateNormal];
  67. [imageUploadBut setTitle:curImgUploadStr forState:UIControlStateNormal];
  68. [imageUploadBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  69. imageUploadBut.titleLabel.font = [UIFont boldSystemFontOfSize:13.0];
  70. imageUploadBut.tag = 2;
  71. [imageUploadBut addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  72. [self addSubview:imageUploadBut];
  73. [imageUploadBut.layer insertSublayer:gl_But atIndex:0];
  74. [imageUploadBut bringSubviewToFront:imageUploadBut.imageView];
  75. self.uploadButon = imageUploadBut;
  76. //imageUploadBut.backgroundColor = [UIColor redColor];
  77. [imageUploadBut mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.right.mas_equalTo(-15);
  79. make.top.mas_equalTo(10);
  80. make.width.mas_equalTo(88);
  81. make.height.mas_equalTo(40);
  82. }];
  83. imageUploadBut.enabled = NO;
  84. imageUploadBut.alpha = 0.5;
  85. }
  86. #pragma mark 数据处理
  87. - (void)setIndexPathsForSelectedItems:(NSMutableArray *)indexPathsForSelectedItems
  88. {
  89. _indexPathsForSelectedItems = indexPathsForSelectedItems;
  90. if(!_indexPathsForSelectedItems){
  91. _indexPathsForSelectedItems = [NSMutableArray new];
  92. }
  93. //TZAssetModel imageData (以字节为单位)
  94. NSUInteger allImageData = 0;
  95. for (couldPhoneFileModel* model in _indexPathsForSelectedItems) {
  96. allImageData += model.length;
  97. }
  98. allImageData /= 1024;
  99. NSString *byteStr = nil;
  100. NSString *unitStr = @"KB";
  101. if(allImageData < 1024){
  102. byteStr = [[NSString alloc] initWithFormat:@"%ld",allImageData];
  103. }
  104. else if( allImageData >= 1024 && allImageData < 1024*1024){
  105. byteStr = [[NSString alloc] initWithFormat:@"%.1f",allImageData/1024.0];
  106. unitStr = @"MB";
  107. }
  108. else{
  109. byteStr = [[NSString alloc] initWithFormat:@"%.2f",allImageData/1024.0/1024.0];
  110. unitStr = @"G";
  111. }
  112. if(!_availableStorage){
  113. _availableStorage = @"--";
  114. }
  115. NSString *curStr1 = [NSString stringWithFormat:@"已选%ld项",_indexPathsForSelectedItems.count];
  116. NSString *curStr2 = [NSString stringWithFormat:@"(%@%@,%@)",byteStr,unitStr,_availableStorage];
  117. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@ %@",curStr1,curStr2];
  118. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  119. NSRange redRange = NSMakeRange([totalStr rangeOfString:curStr2].location, [totalStr rangeOfString:curStr2].length);
  120. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#959799" alpha:1.0] range:redRange];
  121. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:redRange];
  122. // 设置行间距
  123. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  124. [paragraphStyle setLineSpacing:5]; //设置行间距
  125. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  126. _selectNumLabel.attributedText = noteStr;
  127. if(_indexPathsForSelectedItems.count > 0){
  128. self.uploadButon.enabled = YES;
  129. self.uploadButon.alpha = 1;
  130. }
  131. else
  132. {
  133. self.uploadButon.enabled = NO;
  134. self.uploadButon.alpha = 0.5;
  135. }
  136. }
  137. #pragma mark 按钮点击
  138. - (void)didClickButFun:(UIButton*)but
  139. {
  140. if(_didClickDownloadFile)
  141. {
  142. _didClickDownloadFile();
  143. }
  144. }
  145. @end