uploadFileBottomView.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. //
  2. // uploadFileBottomView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/11/10.
  6. //
  7. #import "uploadFileBottomView.h"
  8. #import "TZAssetModel+imageData.h"
  9. #import "nasUploadFileManager.h"
  10. @interface uploadFileBottomView ()
  11. {
  12. BOOL isCanUpload;
  13. }
  14. @property(nonatomic,strong)UILabel *selectNumLabel;
  15. @property(nonatomic,strong)UILabel *uploadFileRoutelabel;
  16. @property(nonatomic,strong)UIButton *uploadButon;
  17. @end
  18. @implementation uploadFileBottomView
  19. - (id)initWithFrame:(CGRect)frame{
  20. self = [super initWithFrame:frame];
  21. [self setBackgroundColor:[UIColor whiteColor]];
  22. [self drawAnyView];
  23. return self;
  24. }
  25. - (void)drawAnyView{
  26. _selectNumLabel = [[UILabel alloc] init];
  27. _selectNumLabel.font = [UIFont boldSystemFontOfSize:16.0];
  28. _selectNumLabel.textColor = [UIColor blackColor];
  29. [self addSubview:_selectNumLabel];
  30. [_selectNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.left.mas_equalTo(15);
  32. make.top.mas_equalTo(10);
  33. make.right.mas_equalTo(-110);
  34. make.height.mas_equalTo(20);
  35. }];
  36. //设置即得标题
  37. self.indexPathsForSelectedItems = [NSMutableArray new];
  38. _uploadFileRoutelabel = [[UILabel alloc] init];
  39. //_uploadFileRoutelabel.font = [UIFont systemFontOfSize:14.0];
  40. //_uploadFileRoutelabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  41. _uploadFileRoutelabel.textColor =[UIColor hwColor:@"#01B7EA" alpha:1.0];
  42. [self addSubview:_uploadFileRoutelabel];
  43. _uploadFileRoutelabel.adjustsFontSizeToFitWidth = YES;
  44. [self setSavePathDataFun];
  45. [_uploadFileRoutelabel mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.mas_equalTo(15);
  47. make.top.mas_equalTo(_selectNumLabel.mas_bottom).offset(12);
  48. make.right.mas_equalTo(-110);
  49. make.height.mas_equalTo(15);
  50. }];
  51. UIView *tapView = [[UIView alloc] init];
  52. //tapView.backgroundColor = [UIColor redColor];
  53. [self addSubview:tapView];
  54. [tapView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.mas_equalTo(0);
  56. make.top.mas_equalTo(0);
  57. make.right.mas_equalTo(-110);
  58. make.bottom.mas_equalTo(10);
  59. }];
  60. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBottomViewFun)];
  61. [tapView addGestureRecognizer:tap];
  62. //图片上传
  63. NSString* curImgUploadStr = [[NSString alloc] initWithFormat:@"%@ %@",@"",NSLocalizedString(@"my_set_no_File_upload",nil)];
  64. // gradient
  65. CAGradientLayer *gl_But = [CAGradientLayer layer];
  66. gl_But.frame = CGRectMake(0,0,88.f,40.f);
  67. gl_But.startPoint = CGPointMake(0, 0.5);
  68. gl_But.endPoint = CGPointMake(1, 0.5);
  69. gl_But.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  70. gl_But.locations = @[@(0), @(1.0f)];
  71. gl_But.cornerRadius = 8;
  72. UIButton *imageUploadBut = [[UIButton alloc] init];
  73. [imageUploadBut setImage:[UIImage imageNamed:@"upload_file_white_100"] forState:UIControlStateNormal];
  74. [imageUploadBut setTitle:curImgUploadStr forState:UIControlStateNormal];
  75. [imageUploadBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  76. imageUploadBut.titleLabel.font = [UIFont boldSystemFontOfSize:13.0];
  77. imageUploadBut.tag = 2;
  78. [imageUploadBut addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  79. [self addSubview:imageUploadBut];
  80. [imageUploadBut.layer insertSublayer:gl_But atIndex:0];
  81. [imageUploadBut bringSubviewToFront:imageUploadBut.imageView];
  82. self.uploadButon = imageUploadBut;
  83. //imageUploadBut.backgroundColor = [UIColor redColor];
  84. //多国语言适配
  85. NSString *languageCode = [NSLocale preferredLanguages][0];
  86. if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
  87. {
  88. imageUploadBut.titleLabel.font = [UIFont systemFontOfSize:10.0];
  89. }
  90. [imageUploadBut mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.right.mas_equalTo(-10);
  92. make.top.mas_equalTo(10);
  93. make.width.mas_equalTo(98);
  94. make.height.mas_equalTo(40);
  95. }];
  96. imageUploadBut.enabled = NO;
  97. imageUploadBut.alpha = 0.5;
  98. }
  99. #pragma mark 数据处理
  100. - (void)setIndexPathsForSelectedItems:(NSMutableArray *)indexPathsForSelectedItems
  101. {
  102. isCanUpload = YES;
  103. _indexPathsForSelectedItems = indexPathsForSelectedItems;
  104. if(!_indexPathsForSelectedItems){
  105. _indexPathsForSelectedItems = [NSMutableArray new];
  106. }
  107. //TZAssetModel imageData (以字节为单位)
  108. NSUInteger allImageData = 0;
  109. for (TZAssetModel* model in _indexPathsForSelectedItems) {
  110. // if(model.type == TZAssetModelMediaTypeVideo){
  111. // allImageData += [model.videoData length];
  112. // }
  113. // else{
  114. // allImageData += [model.imageData length];
  115. // }
  116. allImageData += model.totalBytes;
  117. }
  118. if(self.available <= 0 || allImageData > self.available){
  119. isCanUpload = NO;
  120. }
  121. allImageData /= 1024;
  122. NSString *byteStr = nil;
  123. NSString *unitStr = @"KB";
  124. if(allImageData < 1024){
  125. byteStr = [[NSString alloc] initWithFormat:@"%ld",allImageData];
  126. }
  127. else if( allImageData >= 1024 && allImageData < 1024*1024){
  128. byteStr = [[NSString alloc] initWithFormat:@"%.2f",allImageData/1024.0];
  129. unitStr = @"MB";
  130. }
  131. else{
  132. byteStr = [[NSString alloc] initWithFormat:@"%.2f",allImageData/1024.0/1024.0];
  133. unitStr = @"G";
  134. }
  135. if(!_availableStorage){
  136. _availableStorage = @"--";
  137. }
  138. NSString *curStr1 = [NSString stringWithFormat:@"已选%ld项",_indexPathsForSelectedItems.count];
  139. NSString *curStr2 = [NSString stringWithFormat:@"(%@%@,%@)",byteStr,unitStr,_availableStorage];
  140. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@ %@",curStr1,curStr2];
  141. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  142. NSRange redRange = NSMakeRange([totalStr rangeOfString:curStr2].location, [totalStr rangeOfString:curStr2].length);
  143. UIColor *noteColor =[UIColor hwColor:@"#959799" alpha:1.0];
  144. if(!isCanUpload){
  145. noteColor = [UIColor redColor];
  146. }
  147. [noteStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
  148. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:redRange];
  149. // 设置行间距
  150. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  151. [paragraphStyle setLineSpacing:5]; //设置行间距
  152. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  153. _selectNumLabel.attributedText = noteStr;
  154. if(_isExtraFileAndNotFindPathType){
  155. isCanUpload = YES;
  156. }
  157. if(_indexPathsForSelectedItems.count > 0 && isCanUpload){
  158. // self.uploadButon.enabled = YES;
  159. // self.uploadButon.alpha = 1;
  160. }
  161. else
  162. {
  163. self.uploadButon.enabled = NO;
  164. self.uploadButon.alpha = 0.5;
  165. }
  166. }
  167. //上传按钮是否可以交互
  168. - (void)setUploadButtonCanClickFunBy:(BOOL)canClick
  169. {
  170. //if(canClick && _isExtraFileAndNotFindPathType)
  171. if(canClick && isCanUpload)
  172. {
  173. self.uploadButon.enabled = YES;
  174. self.uploadButon.alpha = 1;
  175. }
  176. else
  177. {
  178. self.uploadButon.enabled = NO;
  179. self.uploadButon.alpha = 0.5;
  180. }
  181. }
  182. - (void)setSavePathDataFun
  183. {
  184. NSString *savePath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)];
  185. if(!savePath||savePath.length == 0){
  186. savePath = Const_default_upload_path;
  187. }
  188. NSString *uploadDefaultPath = savePath;
  189. uploadDefaultPath = [iTools changePathToShowPathBy:uploadDefaultPath];
  190. _uploadFileRoutelabel.text = [[NSString alloc] initWithFormat:@"%@: %@",NSLocalizedString(@"File_upload_path_tip",nil),uploadDefaultPath];
  191. }
  192. #pragma mark 按钮点击
  193. - (void)didClickButFun:(UIButton*)but
  194. {
  195. //1.4.3 新需求 有传输任务超过200个时 不给上传
  196. if([nasUploadFileManager shareInstance].uploadingArr.count >= 200){
  197. [[iToast makeText:NSLocalizedString(@"upload_task_not_done_tip",nil)] show];
  198. return;
  199. }
  200. if(_isExtraFileAndNotFindPathType){
  201. [[iToast makeText:NSLocalizedString(@"upload_file_and_not_path_tip",nil)] show];
  202. return;
  203. }
  204. if(_didClickUploadFile)
  205. {
  206. _didClickUploadFile();
  207. }
  208. }
  209. - (void)tapBottomViewFun
  210. {
  211. if(_didClickbottomFun)
  212. {
  213. _didClickbottomFun();
  214. }
  215. }
  216. @end