nasLastFileViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. //
  2. // nasLastFileViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/7/9.
  6. //
  7. #import "nasLastFileViewController.h"
  8. #import "lastFileTableViewCell.h"
  9. #import "editTypeHeadView.h"
  10. #import "editTypeBottomView.h"
  11. #import "downloadManager.h"
  12. #import "uploadFileRecordViewController.h"
  13. #import "queryShareModel.h"
  14. #import "audioPlayerViewController.h"
  15. #import "videoPlayByAVPlayerViewController.h"
  16. #import "editShareView.h"
  17. @interface nasLastFileViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  18. @property(nonatomic,strong) UITableView*tableView;
  19. @property (nonatomic,strong) NSMutableArray *lastFileDataArr;
  20. @property(nonatomic,assign) BOOL isEditType;
  21. @property(nonatomic,strong) editTypeHeadView*curEditTypeHeadView;
  22. @property(nonatomic,strong) editTypeBottomView*curEditTypeBottomView;
  23. @property (nonatomic, strong) NSMutableArray*didSelectListArr;//选中的数据
  24. @end
  25. @implementation nasLastFileViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. // Do any additional setup after loading the view.
  29. [self.toolBar setHidden:YES];
  30. [self.navigationBar setHidden:YES];
  31. [self.navBarBGView setHidden:NO];
  32. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  33. //[self.view setBackgroundColor:[UIColor hwColor:@"#F6F8FA"]];
  34. [self.view setBackgroundColor:[UIColor whiteColor]];
  35. self.titleLabel.text = NSLocalizedString(@"NAS_last_file",nil);
  36. [self drawAnyView];
  37. _didSelectListArr = [NSMutableArray new];
  38. }
  39. - (void)drawAnyView{
  40. [self.view addSubview:self.tableView];
  41. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.mas_equalTo(0);
  43. make.right.mas_equalTo(0);
  44. //make.bottom.mas_equalTo(-(safeArea));
  45. make.bottom.mas_equalTo(0);
  46. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  47. }];
  48. _curEditTypeHeadView = [[editTypeHeadView alloc] init];
  49. _curEditTypeHeadView.hidden = YES;
  50. [self.navBarBGView addSubview:_curEditTypeHeadView];
  51. [_curEditTypeHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.mas_equalTo(0);
  53. make.right.mas_equalTo(0);
  54. make.bottom.mas_equalTo(0);
  55. make.height.mas_equalTo(NAVIHEIGHT - AdaptNaviHeight);
  56. }];
  57. #pragma mark 编辑状态的 取消 和全选按钮 响应事件
  58. KWeakSelf
  59. _curEditTypeHeadView.didClickButtonFun = ^(NSInteger tag) {
  60. if(tag==1){
  61. [weakSelf userCancelEditTypeFun];
  62. }
  63. };
  64. _curEditTypeHeadView.didClickSelectAllFun = ^(UIButton * _Nonnull but) {
  65. [weakSelf didClickSelectAllButton:but];
  66. };
  67. _curEditTypeBottomView = [[editTypeBottomView alloc] init];
  68. _curEditTypeBottomView.hidden = YES;
  69. [self.view addSubview:_curEditTypeBottomView];
  70. [_curEditTypeBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.left.mas_equalTo(0);
  72. make.right.mas_equalTo(0);
  73. make.bottom.mas_equalTo(0);
  74. make.height.mas_equalTo(60 + AdaptTabHeight);
  75. }];
  76. #pragma mark 编辑状态的 下载 分享 删除 响应事件
  77. _curEditTypeBottomView.didClickButtonFun = ^(NSInteger tag) {
  78. if(tag==1){
  79. [weakSelf gotoDownLoadFileFun];
  80. }
  81. else if(tag==2){
  82. [weakSelf gotoShareViewFun];
  83. }
  84. else if(tag==3){
  85. [weakSelf showDeleteAlearViewFun];
  86. }
  87. };
  88. [self.view addSubview:self.tableView];
  89. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.mas_equalTo(0);
  91. make.right.mas_equalTo(0);
  92. //make.bottom.mas_equalTo(-(safeArea));
  93. make.bottom.mas_equalTo(0);
  94. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  95. }];
  96. }
  97. #pragma mark - 懒加载
  98. - (UITableView *)tableView{
  99. if (!_tableView) {
  100. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
  101. _tableView.delegate = self;
  102. _tableView.dataSource = self;
  103. _tableView.showsVerticalScrollIndicator = NO;
  104. _tableView.showsHorizontalScrollIndicator = NO;
  105. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  106. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  107. [_tableView setSeparatorColor:[UIColor clearColor]];
  108. [_tableView setBackgroundColor:[UIColor clearColor]];
  109. [_tableView setTableFooterView:[UIView new]];
  110. [_tableView setBounces:YES];
  111. if (@available(iOS 15.0, *)) {
  112. _tableView.sectionHeaderTopPadding = 0;
  113. }
  114. //空数据引入第三方开源处理
  115. _tableView.emptyDataSetSource = self;
  116. _tableView.emptyDataSetDelegate = self;
  117. }
  118. return _tableView;
  119. }
  120. #pragma mark - 列表委托
  121. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  122. return 1;
  123. }
  124. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  125. if(!_lastFileDataArr){
  126. return 0;
  127. }
  128. return _lastFileDataArr.count;
  129. }
  130. - (lastFileTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  131. __block NSInteger row = indexPath.row;
  132. static NSString *identifier = @"lastFileTableViewCell";
  133. lastFileTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  134. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  135. if (!cell){
  136. cell = [[lastFileTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  137. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  138. [cell setBackgroundColor:[UIColor clearColor]];
  139. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  140. [cell hideCheckButtonBy:NO];
  141. }
  142. if(row < _lastFileDataArr.count){
  143. lastFileModel* dataModel = _lastFileDataArr[row];
  144. cell.curLastFileModel = dataModel;
  145. KWeakSelf
  146. cell.didClickSwitch = ^(BOOL SwitchOn) {
  147. [weakSelf userCheckFilePreviewByRow:row];
  148. };
  149. }
  150. return cell;
  151. }
  152. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  153. return 84;
  154. }
  155. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  156. {
  157. NSInteger row = indexPath.row;
  158. // if(row < _curNASFileAudioMod.data.list.count){
  159. //
  160. // NASFilePicDataArrModel *dataModel = _curNASFileAudioMod.data.list[row];
  161. // //videoPlayViewController *vc = [videoPlayViewController new];
  162. // videoPlayByAVPlayerViewController *vc = [videoPlayByAVPlayerViewController new];
  163. // vc.VideoDataMode = dataModel;
  164. // [self.navigationController pushViewController:vc animated:YES];
  165. //
  166. // }
  167. }
  168. #pragma mark 空数据
  169. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  170. NSString *imageName = @"nas_not_data";
  171. return [UIImage imageNamed:imageName];
  172. }
  173. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  174. NSString *text = NSLocalizedString(@"NAS_last_file_not_data_tip",nil);
  175. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  176. NSForegroundColorAttributeName: HW999999Color};
  177. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  178. }
  179. //调整图片位置
  180. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  181. return -150;
  182. }
  183. #pragma mark 用户长按图片进入编辑
  184. - (void)setViewEditTypeFun
  185. {
  186. _isEditType = YES;
  187. //[self.tableView reloadData];
  188. _curEditTypeHeadView.hidden = NO;
  189. _curEditTypeBottomView.hidden = NO;
  190. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  191. make.left.mas_equalTo(0);
  192. make.right.mas_equalTo(0);
  193. make.bottom.mas_equalTo(_curEditTypeBottomView.mas_top);
  194. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  195. }];
  196. }
  197. #pragma mark 用户取消编辑编辑
  198. - (void)userCancelEditTypeFun
  199. {
  200. //数据还原
  201. for (lastFileModel*model in _didSelectListArr) {
  202. model.isSelectType = NO;
  203. }
  204. [_didSelectListArr removeAllObjects];
  205. _isEditType = NO;
  206. [self.tableView reloadData];
  207. _curEditTypeHeadView.hidden = YES;
  208. _curEditTypeBottomView.hidden = YES;
  209. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  210. make.left.mas_equalTo(0);
  211. make.right.mas_equalTo(0);
  212. make.bottom.mas_equalTo(0);
  213. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  214. }];
  215. }
  216. - (void)userCheckFilePreviewByRow:(NSInteger)row
  217. {
  218. if(row < _lastFileDataArr.count){
  219. lastFileModel* dataModel = _lastFileDataArr[row];
  220. if(dataModel.isSelectType){
  221. [_didSelectListArr removeObject:dataModel];
  222. }
  223. else{
  224. [_didSelectListArr addObject:dataModel];
  225. }
  226. dataModel.isSelectType = !dataModel.isSelectType;
  227. [self setEditTypeTitleFun];
  228. }
  229. }
  230. - (void)didClickSelectAllButton:(UIButton*)button
  231. {
  232. //button.selected = !button.selected;
  233. [_didSelectListArr removeAllObjects];
  234. for (lastFileModel* dataModel in _lastFileDataArr) {
  235. if(!button.selected){
  236. dataModel.isSelectType = button.selected;
  237. }
  238. else{
  239. [_didSelectListArr addObject:dataModel];
  240. dataModel.isSelectType = button.selected;
  241. }
  242. }
  243. [self.tableView reloadData];
  244. [self setEditTypeTitleFun];
  245. }
  246. #pragma mark 设置选中标题
  247. - (void)setEditTypeTitleFun
  248. {
  249. [_curEditTypeHeadView setTitleLabetextByNumbers:_didSelectListArr.count];
  250. if(_didSelectListArr.count > 0){
  251. [self setViewEditTypeFun];
  252. }
  253. else{
  254. [self userCancelEditTypeFun];
  255. }
  256. }
  257. #pragma mark 删除图片
  258. - (void)showDeleteAlearViewFun
  259. {
  260. NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
  261. NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
  262. KWeakSelf
  263. ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
  264. msg:tipStr
  265. imageStr:nil
  266. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  267. okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
  268. didClickOk:^{
  269. [weakSelf delFileListFun];
  270. } didClickCancel:^{
  271. }];
  272. curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  273. [self presentViewController:curAlretVC animated:YES completion:^{
  274. curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  275. }];
  276. }
  277. #pragma mark 删除文件数据
  278. - (void)delFileListFun
  279. {
  280. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  281. NSMutableArray *pathArr = [NSMutableArray new];
  282. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  283. [pathArr addObject:dataModel.path];
  284. }
  285. [paraDict setValue:pathArr forKey:@"path"];
  286. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  287. //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
  288. KWeakSelf //@"delFile"
  289. [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) {
  290. [weakSelf removeNewIndicator];
  291. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  292. if(model && model.status == 0){
  293. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  294. [weakSelf didDeleteSucFun];
  295. }
  296. else{
  297. }
  298. } failure:^(NSError * _Nonnull error) {
  299. [weakSelf removeNewIndicator];
  300. }];
  301. }
  302. #pragma mark 删除成功
  303. - (void)didDeleteSucFun
  304. {
  305. [_didSelectListArr removeAllObjects];
  306. [self setEditTypeTitleFun];
  307. [self getLastFileDataFun];
  308. }
  309. #pragma mark 文件下载
  310. - (void)gotoDownLoadFileFun
  311. {
  312. if(_didSelectListArr.count == 0){
  313. [[iToast makeText:@""] show];
  314. return;
  315. }
  316. NSMutableArray *arr = [NSMutableArray new];
  317. for (lastFileModel *dataModel in _didSelectListArr) {
  318. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  319. fileModel.fileType = dataModel.type;
  320. fileModel.path = dataModel.path;
  321. fileModel.name = dataModel.name;
  322. fileModel.length = dataModel.size;
  323. fileModel.time = dataModel.duration;
  324. [arr addObject:fileModel];
  325. }
  326. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  327. [self.navigationController pushViewController:vc animated:YES];
  328. vc.isDownloadingType = YES;
  329. [vc gotoDownloadFile:arr];
  330. }
  331. #pragma mark 用户点击分享
  332. - (void)gotoShareViewFun
  333. {
  334. if (_didSelectListArr.count > 5) {
  335. [[iToast makeText:NSLocalizedString(@"share_max_count_tip2",nil)] show];
  336. return;
  337. }
  338. editShareView *editShareV = [[editShareView alloc] init];
  339. editShareV.didSelectListArr = _didSelectListArr;
  340. editShareV.shareFileType = @"6";
  341. [self.view addSubview:editShareV];
  342. [editShareV mas_makeConstraints:^(MASConstraintMaker *make) {
  343. make.left.mas_equalTo(0);
  344. make.right.mas_equalTo(0);
  345. make.bottom.mas_equalTo(0);
  346. make.top.mas_equalTo(0);
  347. }];
  348. }
  349. #pragma mark 获取分享开关
  350. -(void)queryShareSwitchFunFun
  351. {
  352. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  353. [paraDict setValue:@7 forKey:@"type"];
  354. KWeakSelf
  355. [[netWorkManager shareInstance] CommonGetWithCallBackCode:queryShareSwitchFun Parameters:paraDict success:^(id _Nonnull responseObject){
  356. queryShareModel *queryShareMod = [[queryShareModel alloc] initWithDictionary:responseObject error:nil];
  357. if(queryShareMod){
  358. [weakSelf.curEditTypeBottomView setCanShaewFunBy:queryShareMod.data.configValue];
  359. }
  360. } failure:^(NSError * _Nonnull error) {
  361. }];
  362. }
  363. - (void)viewWillAppear:(BOOL)animated{
  364. [super viewWillAppear:animated];
  365. [self getLastFileDataFun];
  366. [self queryShareSwitchFunFun];
  367. }
  368. #pragma mark 获取最近文件数据
  369. - (void)getLastFileDataFun
  370. {
  371. _lastFileDataArr = [lastFileManager shareManager].lastFileListArr;
  372. //HLog(@"%@",_lastFileDataArr);
  373. [self.tableView reloadData];
  374. }
  375. @end