uploadFileRecordViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. //
  2. // uoloadFileRecordViewController.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/11/13.
  6. //
  7. #import "uploadFileRecordViewController.h"
  8. #import "uploadFileManager.h"
  9. #import "uploadFileDataModel.h"
  10. #import "uploadFileRecordheadView.h"
  11. #import "uploadFileRecordBodyView.h"
  12. #import "uploadFileRecordEditBottomView.h"
  13. @interface uploadFileRecordViewController ()
  14. //选中的项
  15. @property (nonatomic, strong) NSMutableArray *indexPathsForSelectedItems;
  16. @property (nonatomic, strong) uploadFileRecordheadView *uploadFileRecordheadV;
  17. @property (nonatomic, strong) uploadFileRecordBodyView *uploadFileRecordBodyV;
  18. @property (nonatomic, strong) NSMutableArray *allDataArr;
  19. @property (nonatomic, strong) UIButton *leftButton;
  20. @property (nonatomic, strong) UIButton *rightButton;
  21. @property (nonatomic, strong) uploadFileRecordEditBottomView *uploadFileRecordEditBottomV;
  22. @property (nonatomic,assign) BOOL isEditType;
  23. @end
  24. @implementation uploadFileRecordViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. // Do any additional setup after loading the view.
  28. //[self.view setBackgroundColor:HWF5F7FAColor];
  29. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileRefreshFun:) name:uploadFileRefreshNotification object:nil];
  30. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileDeteleFun:) name:uploadFileDeteleNotification object:nil];
  31. [self.view setBackgroundColor:[UIColor whiteColor]];
  32. self.titleLabel.text = NSLocalizedString(@"my_set_no_File_upload_record",nil) ;
  33. [self.toolBar setHidden:YES];
  34. [self.navigationBar setHidden:YES];
  35. [self.navBarBGView setHidden:NO];
  36. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  37. [self initbaseUIFun];
  38. [self getDataInDatabaseFun];
  39. }
  40. #pragma mark UI
  41. - (void)initbaseUIFun
  42. {
  43. _uploadFileRecordheadV = [[uploadFileRecordheadView alloc] init];
  44. [self.view addSubview:_uploadFileRecordheadV];
  45. [_uploadFileRecordheadV mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.mas_equalTo(15);
  47. make.right.mas_equalTo(-15);
  48. make.top.mas_equalTo(self.navBarBGView.mas_bottom).offset(15.0);
  49. make.height.mas_equalTo(50);
  50. }];
  51. KWeakSelf
  52. #pragma mark 头部点击事件
  53. _uploadFileRecordheadV.didClickButFun = ^(NSInteger index) {
  54. [weakSelf didClickHeadFun: index];
  55. };
  56. _uploadFileRecordBodyV = [[uploadFileRecordBodyView alloc] init];
  57. _uploadFileRecordBodyV.curVC = self;
  58. [self.view addSubview:_uploadFileRecordBodyV];
  59. [_uploadFileRecordBodyV mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.mas_equalTo(0);
  61. make.right.mas_equalTo(0);
  62. make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
  63. make.bottom.mas_equalTo(0);
  64. }];
  65. _uploadFileRecordBodyV.didScrollFun = ^(NSInteger index) {
  66. [weakSelf didScorllBodyFun:index];
  67. };
  68. _uploadFileRecordBodyV.didLongPressClick = ^{
  69. weakSelf.isEditType = YES;
  70. };
  71. _leftButton = [[UIButton alloc] init];
  72. [_leftButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  73. _leftButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
  74. _leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  75. [_leftButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  76. _leftButton.tag = 1;
  77. [_leftButton setTitle:NSLocalizedString(@"other_cancel",nil) forState:UIControlStateNormal];
  78. _leftButton.hidden = YES;
  79. [self.navBarBGView addSubview:_leftButton];
  80. [_leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.width.mas_equalTo(80);
  82. make.left.mas_equalTo(15);
  83. make.height.mas_equalTo(self.backBtn.mas_height);
  84. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  85. }];
  86. _rightButton = [[UIButton alloc] init];
  87. [_rightButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  88. _rightButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
  89. _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  90. [_rightButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  91. _rightButton.tag = 2;
  92. [_rightButton setTitle:NSLocalizedString(@"File_upload_Record_select_all",nil) forState:UIControlStateNormal];
  93. _rightButton.hidden = YES;
  94. [self.navBarBGView addSubview:_rightButton];
  95. [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.width.mas_equalTo(80);
  97. make.right.mas_equalTo(-15);
  98. make.height.mas_equalTo(self.backBtn.mas_height);
  99. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  100. }];
  101. _uploadFileRecordEditBottomV = [[uploadFileRecordEditBottomView alloc] init];
  102. _uploadFileRecordEditBottomV.hidden = YES;
  103. [self.view addSubview:_uploadFileRecordEditBottomV];
  104. [_uploadFileRecordEditBottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.left.mas_equalTo(0);
  106. make.right.mas_equalTo(0);
  107. make.height.mas_equalTo(60 + safeArea);
  108. make.bottom.mas_equalTo(0);
  109. }];
  110. _uploadFileRecordEditBottomV.didClickButFun = ^{
  111. [weakSelf.uploadFileRecordBodyV deleteModelOneByOneFun];
  112. };
  113. }
  114. #pragma mark 头部点击 背景滚动
  115. - (void)didClickHeadFun:(NSInteger)index
  116. {
  117. _uploadFileRecordBodyV.selectIndex = index;
  118. }
  119. - (void)didScorllBodyFun:(NSInteger)index
  120. {
  121. _uploadFileRecordheadV.selectIndex = index;
  122. }
  123. -(void)gotoUploadFile:(NSMutableArray*)indexPathsForSelectedItems
  124. {
  125. _indexPathsForSelectedItems = [[uploadFileManager shareInstance] handlTZAssetModelToUploadFileDataFunBy:indexPathsForSelectedItems];
  126. HLog(@"11");
  127. }
  128. #pragma mark 读取数据库数据
  129. - (void)getDataInDatabaseFun
  130. {
  131. _allDataArr = [NSMutableArray new];
  132. KWeakSelf
  133. [uploadFileDataModel bg_findAllAsync:upLoadFile_image_tableName complete:^(NSArray * _Nullable array) {
  134. NSMutableArray *failArr = [NSMutableArray new];
  135. NSMutableArray *doneArr = [NSMutableArray new];
  136. NSMutableArray *otherArr = [NSMutableArray new];
  137. for (uploadFileDataModel * curModel in array) {
  138. if(curModel.curUploadStateType == uploadStateFail){
  139. [failArr addObject:curModel];
  140. }
  141. else if(curModel.curUploadStateType == uploadStateDone){
  142. [doneArr addObject:curModel];
  143. }
  144. else{
  145. [otherArr addObject:curModel];
  146. }
  147. }
  148. [self->_allDataArr addObject:otherArr];
  149. [self->_allDataArr addObject:doneArr];
  150. [self->_allDataArr addObject:failArr];
  151. weakSelf.uploadFileRecordBodyV.allDataArr = self->_allDataArr;
  152. }];
  153. }
  154. - (void)uploadFileRefreshFun:(NSNotification*)not
  155. {
  156. uploadFileDataModel *uploadFileDataMod = [not object];
  157. HLog(@"%@",uploadFileDataMod);
  158. if(_allDataArr.count == 3 && [uploadFileDataMod isKindOfClass:[uploadFileDataModel class]] ){
  159. NSMutableArray *curArr = _allDataArr[0];
  160. NSInteger index = 0;
  161. for (uploadFileDataModel*mod in curArr) {
  162. HLog(@"bg_id:%@ ?=? %@",mod.bg_id,uploadFileDataMod.bg_id);
  163. if(mod.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){
  164. if(uploadFileDataMod.curUploadStateType == uploadStateDone){
  165. [curArr removeObject:mod];
  166. NSMutableArray *doneArr = _allDataArr[1];
  167. [doneArr insertObject:uploadFileDataMod atIndex:0];
  168. //全部上传了
  169. if(curArr.count == 0){
  170. }
  171. }
  172. else if(uploadFileDataMod.curUploadStateType == uploadStateFail){
  173. [curArr removeObject:mod];
  174. NSMutableArray *failArr = _allDataArr[2];
  175. [failArr insertObject:uploadFileDataMod atIndex:0];
  176. }
  177. else{
  178. [curArr replaceObjectAtIndex:index withObject:uploadFileDataMod];
  179. }
  180. break;
  181. }
  182. index++;
  183. }
  184. //精准刷新
  185. if(uploadFileDataMod.curUploadStateType == uploadStateDone){
  186. [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:_allDataArr[1] withfailArr:nil];
  187. }
  188. else if(uploadFileDataMod.curUploadStateType == uploadStateFail){
  189. [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:_allDataArr[2]];
  190. }
  191. else{
  192. [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:nil];
  193. }
  194. }
  195. //self.uploadFileRecordBodyV.allDataArr = _allDataArr;
  196. }
  197. - (void)uploadFileDeteleFun:(NSNotification*)not
  198. {
  199. uploadFileDataModel *uploadFileDataMod = [not object];
  200. HLog(@"%@",uploadFileDataMod);
  201. if(_allDataArr.count == 3 && [uploadFileDataMod isKindOfClass:[uploadFileDataModel class]] ){
  202. NSMutableArray *curArr = _allDataArr[0];
  203. NSInteger index = 0;
  204. for (uploadFileDataModel*mod in curArr) {
  205. HLog(@"bg_id:%@ ?=? %@",mod.bg_id,uploadFileDataMod.bg_id);
  206. if(mod.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){
  207. [curArr removeObject:mod];
  208. break;
  209. }
  210. index++;
  211. }
  212. //精准刷新
  213. [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:nil];
  214. }
  215. }
  216. #pragma mark 按钮点击
  217. - (void)didClickButFun:(UIButton*)but
  218. {
  219. NSInteger tag = but.tag;
  220. if(tag == 1){
  221. self.isEditType = NO;
  222. self.uploadFileRecordBodyV.isEditType = NO;
  223. }
  224. else{
  225. self.uploadFileRecordBodyV.isSelectAllType = YES;
  226. }
  227. }
  228. -(void)setIsEditType:(BOOL)isEditType
  229. {
  230. _isEditType = isEditType;
  231. if(_isEditType){
  232. _leftButton.hidden = NO;
  233. _rightButton.hidden = NO;
  234. self.backBtn.hidden = YES;
  235. _uploadFileRecordEditBottomV.hidden = NO;
  236. _uploadFileRecordheadV.userInteractionEnabled = NO;
  237. [_uploadFileRecordBodyV mas_remakeConstraints:^(MASConstraintMaker *make) {
  238. make.left.mas_equalTo(0);
  239. make.right.mas_equalTo(0);
  240. make.bottom.mas_equalTo(_uploadFileRecordEditBottomV.mas_top).offset(0.0);
  241. make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
  242. }];
  243. //dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  244. // UITableView *curTabview = [_uploadFileRecordBodyV.bgScrollV viewWithTag:(10+_uploadFileRecordBodyV.selectIndex -1)];
  245. //
  246. // CGRect frame = curTabview.frame;
  247. // frame.size.height = SCREEN_H - CGRectGetMaxY(_uploadFileRecordheadV.frame) - (60 + safeArea);
  248. //
  249. // CGSize curSize = _uploadFileRecordBodyV.bgScrollV.contentSize;
  250. // curSize.height = frame.size.height;
  251. // _uploadFileRecordBodyV.bgScrollV.contentSize = curSize;
  252. //curTabview.frame = frame;
  253. //});
  254. }
  255. else{
  256. _leftButton.hidden = YES;
  257. _rightButton.hidden = YES;
  258. self.backBtn.hidden = NO;
  259. _uploadFileRecordEditBottomV.hidden = YES;
  260. _uploadFileRecordheadV.userInteractionEnabled = YES;
  261. [_uploadFileRecordBodyV mas_remakeConstraints:^(MASConstraintMaker *make) {
  262. make.left.mas_equalTo(0);
  263. make.right.mas_equalTo(0);
  264. make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
  265. make.bottom.mas_equalTo(0);
  266. }];
  267. // UITableView *curTabview = [_uploadFileRecordBodyV.bgScrollV viewWithTag:(10+_uploadFileRecordBodyV.selectIndex -1)];
  268. //
  269. // CGRect frame = curTabview.frame;
  270. // frame.size.height = SCREEN_W - CGRectGetHeight(_uploadFileRecordBodyV.frame);
  271. // curTabview.frame = frame;
  272. }
  273. }
  274. @end