uploadFileBottomView.m 8.3 KB

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