uploadFileRecordViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. [self.view setBackgroundColor:[UIColor whiteColor]];
  31. self.titleLabel.text = NSLocalizedString(@"my_set_no_File_upload_record",nil) ;
  32. [self.toolBar setHidden:YES];
  33. [self.navigationBar setHidden:YES];
  34. [self.navBarBGView setHidden:NO];
  35. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  36. [self initbaseUIFun];
  37. [self getDataInDatabaseFun];
  38. }
  39. #pragma mark UI
  40. - (void)initbaseUIFun
  41. {
  42. _uploadFileRecordheadV = [[uploadFileRecordheadView alloc] init];
  43. [self.view addSubview:_uploadFileRecordheadV];
  44. [_uploadFileRecordheadV mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.mas_equalTo(15);
  46. make.right.mas_equalTo(-15);
  47. make.top.mas_equalTo(self.navBarBGView.mas_bottom).offset(15.0);
  48. make.height.mas_equalTo(50);
  49. }];
  50. KWeakSelf
  51. #pragma mark 头部点击事件
  52. _uploadFileRecordheadV.didClickButFun = ^(NSInteger index) {
  53. [weakSelf didClickHeadFun: index];
  54. };
  55. _uploadFileRecordBodyV = [[uploadFileRecordBodyView alloc] init];
  56. _uploadFileRecordBodyV.curVC = self;
  57. [self.view addSubview:_uploadFileRecordBodyV];
  58. [_uploadFileRecordBodyV mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.mas_equalTo(0);
  60. make.right.mas_equalTo(0);
  61. make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
  62. make.bottom.mas_equalTo(0);
  63. }];
  64. _uploadFileRecordBodyV.didScrollFun = ^(NSInteger index) {
  65. [weakSelf didScorllBodyFun:index];
  66. };
  67. _uploadFileRecordBodyV.didLongPressClick = ^{
  68. weakSelf.isEditType = YES;
  69. };
  70. _leftButton = [[UIButton alloc] init];
  71. [_leftButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  72. _leftButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
  73. _leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  74. [_leftButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  75. _leftButton.tag = 1;
  76. [_leftButton setTitle:NSLocalizedString(@"other_cancel",nil) forState:UIControlStateNormal];
  77. _leftButton.hidden = YES;
  78. [self.navBarBGView addSubview:_leftButton];
  79. [_leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.width.mas_equalTo(80);
  81. make.left.mas_equalTo(15);
  82. make.height.mas_equalTo(self.backBtn.mas_height);
  83. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  84. }];
  85. _rightButton = [[UIButton alloc] init];
  86. [_rightButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  87. _rightButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
  88. _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  89. [_rightButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  90. _rightButton.tag = 2;
  91. [_rightButton setTitle:NSLocalizedString(@"File_upload_Record_select_all",nil) forState:UIControlStateNormal];
  92. _rightButton.hidden = YES;
  93. [self.navBarBGView addSubview:_rightButton];
  94. [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.width.mas_equalTo(80);
  96. make.right.mas_equalTo(-15);
  97. make.height.mas_equalTo(self.backBtn.mas_height);
  98. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  99. }];
  100. _uploadFileRecordEditBottomV = [[uploadFileRecordEditBottomView alloc] init];
  101. _uploadFileRecordEditBottomV.hidden = YES;
  102. [self.view addSubview:_uploadFileRecordEditBottomV];
  103. [_uploadFileRecordEditBottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.left.mas_equalTo(0);
  105. make.right.mas_equalTo(0);
  106. make.height.mas_equalTo(60 + safeArea);
  107. make.bottom.mas_equalTo(0);
  108. }];
  109. _uploadFileRecordEditBottomV.didClickButFun = ^{
  110. [weakSelf.uploadFileRecordBodyV deleteModelOneByOneFun];
  111. };
  112. }
  113. #pragma mark 头部点击 背景滚动
  114. - (void)didClickHeadFun:(NSInteger)index
  115. {
  116. _uploadFileRecordBodyV.selectIndex = index;
  117. }
  118. - (void)didScorllBodyFun:(NSInteger)index
  119. {
  120. _uploadFileRecordheadV.selectIndex = index;
  121. }
  122. -(void)gotoUploadFile:(NSMutableArray*)indexPathsForSelectedItems
  123. {
  124. _indexPathsForSelectedItems = [[uploadFileManager shareInstance] handlTZAssetModelToUploadFileDataFunBy:indexPathsForSelectedItems];
  125. HLog(@"11");
  126. }
  127. #pragma mark 读取数据库数据
  128. - (void)getDataInDatabaseFun
  129. {
  130. _allDataArr = [NSMutableArray new];
  131. KWeakSelf
  132. [uploadFileDataModel bg_findAllAsync:upLoadFile_image_tableName complete:^(NSArray * _Nullable array) {
  133. NSMutableArray *failArr = [NSMutableArray new];
  134. NSMutableArray *doneArr = [NSMutableArray new];
  135. NSMutableArray *otherArr = [NSMutableArray new];
  136. for (uploadFileDataModel * curModel in array) {
  137. if(curModel.curUploadStateType == uploadStateFail){
  138. [failArr addObject:curModel];
  139. }
  140. else if(curModel.curUploadStateType == uploadStateDone){
  141. [doneArr addObject:curModel];
  142. }
  143. else{
  144. [otherArr addObject:curModel];
  145. }
  146. }
  147. [self->_allDataArr addObject:otherArr];
  148. [self->_allDataArr addObject:doneArr];
  149. [self->_allDataArr addObject:failArr];
  150. weakSelf.uploadFileRecordBodyV.allDataArr = self->_allDataArr;
  151. }];
  152. }
  153. - (void)uploadFileRefreshFun:(NSNotification*)not
  154. {
  155. uploadFileDataModel *uploadFileDataMod = [not object];
  156. HLog(@"%@",uploadFileDataMod);
  157. if(_allDataArr.count == 3 && [uploadFileDataMod isKindOfClass:[uploadFileDataModel class]] ){
  158. NSMutableArray *curArr = _allDataArr[0];
  159. NSInteger index = 0;
  160. for (uploadFileDataModel*mod in curArr) {
  161. HLog(@"bg_id:%@ ?=? %@",mod.bg_id,uploadFileDataMod.bg_id);
  162. if(mod.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){
  163. if(uploadFileDataMod.curUploadStateType == uploadStateDone){
  164. [curArr removeObject:mod];
  165. NSMutableArray *doneArr = _allDataArr[1];
  166. [doneArr insertObject:uploadFileDataMod atIndex:0];
  167. //全部上传了
  168. if(curArr.count == 0){
  169. }
  170. }
  171. else if(uploadFileDataMod.curUploadStateType == uploadStateFail){
  172. [curArr removeObject:mod];
  173. NSMutableArray *failArr = _allDataArr[2];
  174. [failArr insertObject:uploadFileDataMod atIndex:0];
  175. }
  176. else{
  177. [curArr replaceObjectAtIndex:index withObject:uploadFileDataMod];
  178. }
  179. break;
  180. }
  181. index++;
  182. }
  183. //精准刷新
  184. if(uploadFileDataMod.curUploadStateType == uploadStateDone){
  185. [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:_allDataArr[1] withfailArr:nil];
  186. }
  187. else if(uploadFileDataMod.curUploadStateType == uploadStateFail){
  188. [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:_allDataArr[2]];
  189. }
  190. else{
  191. [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:nil];
  192. }
  193. }
  194. //self.uploadFileRecordBodyV.allDataArr = _allDataArr;
  195. }
  196. #pragma mark 按钮点击
  197. - (void)didClickButFun:(UIButton*)but
  198. {
  199. NSInteger tag = but.tag;
  200. if(tag == 1){
  201. self.isEditType = NO;
  202. self.uploadFileRecordBodyV.isEditType = NO;
  203. }
  204. else{
  205. self.uploadFileRecordBodyV.isSelectAllType = YES;
  206. }
  207. }
  208. -(void)setIsEditType:(BOOL)isEditType
  209. {
  210. _isEditType = isEditType;
  211. if(_isEditType){
  212. _leftButton.hidden = NO;
  213. _rightButton.hidden = NO;
  214. self.backBtn.hidden = YES;
  215. _uploadFileRecordEditBottomV.hidden = NO;
  216. [_uploadFileRecordBodyV mas_remakeConstraints:^(MASConstraintMaker *make) {
  217. make.left.mas_equalTo(0);
  218. make.right.mas_equalTo(0);
  219. make.bottom.mas_equalTo(_uploadFileRecordEditBottomV.mas_top).offset(0.0);
  220. make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
  221. }];
  222. }
  223. else{
  224. _leftButton.hidden = YES;
  225. _rightButton.hidden = YES;
  226. self.backBtn.hidden = NO;
  227. _uploadFileRecordEditBottomV.hidden = YES;
  228. [_uploadFileRecordBodyV mas_remakeConstraints:^(MASConstraintMaker *make) {
  229. make.left.mas_equalTo(0);
  230. make.right.mas_equalTo(0);
  231. make.bottom.mas_equalTo(_uploadFileRecordEditBottomV.mas_top).offset(0.0);
  232. make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
  233. }];
  234. }
  235. }
  236. @end