previewFileAndFolderViewController.m 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  1. //
  2. // previewFileAndFolderViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/21.
  6. //
  7. #import "previewFileAndFolderViewController.h"
  8. #import "couldPhoneFileListModel.h"
  9. #import "downloadThumbnailManager.h"
  10. #import "downloadManager.h"
  11. #import "uploadFileRecordViewController.h"
  12. #import "UIScrollView+EmptyDataSet.h"
  13. #import "diskListBgView.h"
  14. #import "diskListTableView.h"
  15. #import "downLoadPreViewCell.h"
  16. #import "editTypeHeadView.h"
  17. #import "editTypeBottomView.h"
  18. #import "editShareView.h"
  19. #import "previewToUploadFileView.h"
  20. #import "netWorkManager.h"
  21. #import "NASFileAndFolderModel.h"
  22. #import "queryShareModel.h"
  23. #import "videoPlayByAVPlayerViewController.h"
  24. #import "audioPlayerViewController.h"
  25. #import "imageDetailsScrollViewController.h"
  26. @interface previewFileAndFolderViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  27. {
  28. UIButton *tapBtn;
  29. UIButton* rightTransferListButton;//传输列表
  30. UIView* rightRedView;
  31. BOOL hadUploadTaskType;
  32. BOOL hadDownloadTaskType;
  33. BOOL canShareType;
  34. }
  35. @property (nonatomic, strong) UITableView *tableView;
  36. @property (strong, nonatomic) UILabel *MytitleLabel;
  37. @property (strong, nonatomic) UIImageView *selectTip;
  38. @property (nonatomic, strong) diskListBgView *diskListBgV;
  39. @property (nonatomic, strong) diskListTableView *diskListTableV;
  40. @property (nonatomic, strong) NSMutableArray*diskListArr;
  41. @property (nonatomic, copy) NSString *defaultDiskPath;
  42. @property(nonatomic,assign) BOOL isEditType;
  43. @property(nonatomic,strong) editTypeHeadView*curEditTypeHeadView;
  44. @property(nonatomic,strong) editTypeBottomView*curEditTypeBottomView;
  45. @property(nonatomic,strong) UIButton*uploadFileButton;
  46. @property (nonatomic, strong) NSMutableArray*didSelectListArr;//选中的数据
  47. @property (nonatomic, strong)NASFileAndFolderModel * curNASFileAudioMod;
  48. @end
  49. @implementation previewFileAndFolderViewController
  50. - (void)viewDidLoad {
  51. [super viewDidLoad];
  52. // Do any additional setup after loading the view.
  53. [self.toolBar setHidden:YES];
  54. [self.navigationBar setHidden:YES];
  55. [self.navBarBGView setHidden:NO];
  56. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  57. [self.view setBackgroundColor:[UIColor whiteColor]];
  58. [self drawAnyView];
  59. _didSelectListArr = [NSMutableArray new];
  60. //数据埋点
  61. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"File"];
  62. }
  63. - (void)drawAnyView{
  64. [self initNavHeadUIFun];
  65. _curEditTypeHeadView = [[editTypeHeadView alloc] init];
  66. _curEditTypeHeadView.hidden = YES;
  67. [self.navBarBGView addSubview:_curEditTypeHeadView];
  68. [_curEditTypeHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.mas_equalTo(0);
  70. make.right.mas_equalTo(0);
  71. make.bottom.mas_equalTo(0);
  72. make.height.mas_equalTo(NAVIHEIGHT - AdaptNaviHeight);
  73. }];
  74. #pragma mark 编辑状态的 取消 和全选按钮 响应事件
  75. KWeakSelf
  76. _curEditTypeHeadView.didClickButtonFun = ^(NSInteger tag) {
  77. if(tag==1){
  78. [weakSelf userCancelEditTypeFun];
  79. }
  80. };
  81. _curEditTypeHeadView.didClickSelectAllFun = ^(UIButton * _Nonnull but) {
  82. [weakSelf didClickSelectAllButton:but];
  83. };
  84. _curEditTypeBottomView = [[editTypeBottomView alloc] init];
  85. _curEditTypeBottomView.hidden = YES;
  86. [self.view addSubview:_curEditTypeBottomView];
  87. [_curEditTypeBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.mas_equalTo(0);
  89. make.right.mas_equalTo(0);
  90. make.bottom.mas_equalTo(0);
  91. make.height.mas_equalTo(60 + AdaptTabHeight);
  92. }];
  93. #pragma mark 编辑状态的 下载 分享 删除 响应事件
  94. _curEditTypeBottomView.didClickButtonFun = ^(NSInteger tag) {
  95. if(tag==1){
  96. [weakSelf gotoDownLoadFileFun];
  97. }
  98. else if(tag==2){
  99. [weakSelf gotoShareViewFun];
  100. }
  101. else if(tag==3){
  102. [weakSelf showDeleteAlearViewFun];
  103. }
  104. };
  105. [self.view addSubview:self.tableView];
  106. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.left.mas_equalTo(0);
  108. make.right.mas_equalTo(0);
  109. //make.bottom.mas_equalTo(-(safeArea));
  110. make.bottom.mas_equalTo(0);
  111. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  112. }];
  113. //大+号
  114. _uploadFileButton = [[UIButton alloc] init];
  115. [_uploadFileButton setBackgroundImage:[UIImage imageNamed:@"add_file_icon"] forState:UIControlStateNormal];
  116. [_uploadFileButton addTarget:self action:@selector(userDidClickUploadViewFun) forControlEvents:UIControlEventTouchUpInside];
  117. [self.view addSubview:_uploadFileButton];
  118. [_uploadFileButton mas_makeConstraints:^(MASConstraintMaker *make) {
  119. make.right.mas_equalTo(-15);
  120. make.width.mas_equalTo(52);
  121. make.height.mas_equalTo(52);
  122. make.bottom.mas_equalTo(-30 - AdaptTabHeight);
  123. }];
  124. NSMutableArray *arr = [NSMutableArray new];
  125. NSArray *diskList = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  126. if(diskList && [diskList isKindOfClass:[NSArray class]]){
  127. for (cloudPhoneExtraFileModel *model in diskList) {
  128. model.isCheckType = NO;
  129. [arr addObject:model];
  130. }
  131. }
  132. if(arr.count >0){
  133. cloudPhoneExtraFileModel *model = arr.firstObject;
  134. model.isCheckType = YES;
  135. _defaultDiskPath = model.extraPath;
  136. }
  137. _diskListArr = arr;
  138. [self setTitleAfterGetdiskFun];
  139. }
  140. - (void)initNavHeadUIFun
  141. {
  142. //title
  143. UILabel *titleLabel = [[UILabel alloc] init];
  144. titleLabel.textAlignment = NSTextAlignmentCenter;
  145. titleLabel.font = [UIFont boldSystemFontOfSize:16.0];
  146. titleLabel.textColor = [UIColor blackColor];
  147. titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
  148. [self.navBarBGView addSubview:titleLabel];
  149. self.MytitleLabel = titleLabel;
  150. //selectTipImageView
  151. UIImageView *selectTip = [[UIImageView alloc] init];
  152. selectTip.image = [UIImage imageNamed:@"upload_image_arrow"];
  153. selectTip.translatesAutoresizingMaskIntoConstraints = NO;
  154. [self.navBarBGView addSubview:selectTip];
  155. self.selectTip = selectTip;
  156. tapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  157. tapBtn.backgroundColor = [UIColor clearColor];
  158. tapBtn.translatesAutoresizingMaskIntoConstraints = NO;
  159. [tapBtn addTarget:self action:@selector(selectDiskAction:) forControlEvents:UIControlEventTouchUpInside];
  160. [self.navBarBGView addSubview:tapBtn];
  161. [tapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  162. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  163. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  164. make.width.mas_equalTo(100);
  165. make.height.mas_equalTo(30);
  166. }];
  167. [self setTitleLabelText:@""];
  168. rightTransferListButton = [[UIButton alloc] init];
  169. [rightTransferListButton setImage:[UIImage imageNamed:@"icon_file_transfer"] forState:UIControlStateNormal];
  170. [rightTransferListButton addTarget:self action:@selector(didiClikRightButGotoTransferListFun:) forControlEvents:UIControlEventTouchUpInside];
  171. [self.navBarBGView addSubview:rightTransferListButton];
  172. [rightTransferListButton mas_makeConstraints:^(MASConstraintMaker *make) {
  173. make.width.mas_equalTo(40);
  174. make.height.mas_equalTo(40);
  175. make.right.mas_equalTo(-15);
  176. make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  177. }];
  178. rightRedView = [[UIView alloc] init];
  179. rightRedView.backgroundColor = [UIColor hwColor:@"#DD4E4E" alpha:1.0];
  180. [rightTransferListButton addSubview:rightRedView];
  181. rightRedView.layer.cornerRadius = 7;
  182. rightRedView.hidden = YES;
  183. [rightRedView mas_makeConstraints:^(MASConstraintMaker *make) {
  184. make.width.mas_equalTo(14);
  185. make.height.mas_equalTo(14);
  186. make.right.mas_equalTo(0);
  187. make.top.mas_equalTo(6);
  188. }];
  189. }
  190. #pragma mark - 懒加载
  191. - (UITableView *)tableView{
  192. if (!_tableView) {
  193. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain];
  194. _tableView.delegate = self;
  195. _tableView.dataSource = self;
  196. _tableView.showsVerticalScrollIndicator = NO;
  197. _tableView.showsHorizontalScrollIndicator = NO;
  198. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  199. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  200. [_tableView setSeparatorColor:[UIColor clearColor]];
  201. [_tableView setBackgroundColor:[UIColor clearColor]];
  202. [_tableView setTableFooterView:[UIView new]];
  203. [_tableView setBounces:YES];
  204. if (@available(iOS 15.0, *)) {
  205. _tableView.sectionHeaderTopPadding = 0;
  206. }
  207. //空数据引入第三方开源处理
  208. _tableView.emptyDataSetSource = self;
  209. _tableView.emptyDataSetDelegate = self;
  210. }
  211. return _tableView;
  212. }
  213. - (diskListBgView*)diskListBgV
  214. {
  215. if(!_diskListBgV){
  216. _diskListBgV = [[diskListBgView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
  217. _diskListBgV.hidden = YES;
  218. [self.view addSubview:_diskListBgV];
  219. KWeakSelf
  220. _diskListBgV.didTapWhitePlace = ^{
  221. [weakSelf hideDiskListVieFun];
  222. };
  223. [_diskListBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  224. make.left.mas_equalTo(0);
  225. make.bottom.mas_equalTo(0);
  226. make.right.mas_equalTo(0);
  227. make.top.mas_equalTo(self.navBarBGView.mas_bottom);
  228. }];
  229. [self.view addSubview:self.diskListTableV];
  230. self.diskListTableV.hidden = YES;
  231. [self.diskListTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  232. make.left.mas_equalTo(0);
  233. make.height.mas_equalTo(3*70);
  234. make.right.mas_equalTo(0);
  235. make.top.mas_equalTo(self.navBarBGView.mas_bottom);
  236. }];
  237. self.diskListTableV.diskListArr = _diskListArr;
  238. self.diskListTableV.didClickDiskModel = ^(NSString * _Nonnull checkPath) {
  239. [weakSelf didCheckDiskFunByPath:checkPath];
  240. };
  241. }
  242. return _diskListBgV;
  243. }
  244. - (UITableView *)diskListTableV{
  245. if (!_diskListTableV) {
  246. _diskListTableV = [[diskListTableView alloc] init];
  247. //
  248. }
  249. return _diskListTableV;
  250. }
  251. #pragma mark 选中磁盘
  252. - (void)didCheckDiskFunByPath:(NSString*)pathStr
  253. {
  254. if(self.defaultDiskPath
  255. && self.defaultDiskPath.length>0
  256. && ![self.defaultDiskPath isEqualToString:pathStr]){
  257. //切换硬盘了 取消全选
  258. [_didSelectListArr removeAllObjects];
  259. }
  260. self.defaultDiskPath = pathStr;
  261. [self getFileListFun];
  262. [self setTitleAfterGetdiskFun];
  263. [self hideDiskListVieFun];
  264. }
  265. #pragma mark - 列表委托
  266. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  267. return 1;
  268. }
  269. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  270. if(!_curNASFileAudioMod){
  271. return 0;
  272. }
  273. return _curNASFileAudioMod.data.list.count;
  274. }
  275. - (downLoadPreViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  276. __block NSInteger row = indexPath.row;
  277. static NSString *identifier = @"downLoadPreViewCell";
  278. downLoadPreViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  279. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  280. if (!cell){
  281. cell = [[downLoadPreViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  282. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  283. [cell setBackgroundColor:[UIColor clearColor]];
  284. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  285. [cell.bgViewLayer removeFromSuperlayer];
  286. [cell.titleLabel2 setHidden:NO];
  287. [cell.rightImage setHidden:YES];
  288. [cell.lineView setHidden:YES];
  289. [cell.checkButton setHidden:NO];
  290. }
  291. if(row < _curNASFileAudioMod.data.list.count){
  292. NASFileAndFolderDataModel* dataModel = _curNASFileAudioMod.data.list[row];
  293. cell.curNASFileAndFolderDataModel = dataModel;
  294. KWeakSelf
  295. cell.didClickSwitch = ^(BOOL SwitchOn) {
  296. //if([weakSelf userCheckFileModel:dataModel withShowTip:YES]){
  297. [weakSelf userCheckFilePreviewByRow:row];
  298. //}
  299. };
  300. }
  301. return cell;
  302. }
  303. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  304. return 70;
  305. }
  306. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  307. {
  308. NSInteger row = indexPath.row;
  309. if(row < _curNASFileAudioMod.data.list.count){
  310. NASFileAndFolderDataModel* dataModel = _curNASFileAudioMod.data.list[row];
  311. if([dataModel.type isEqualToString:@"dir"])
  312. {
  313. previewFileAndFolderSecondViewController *vc = [previewFileAndFolderSecondViewController new];
  314. vc.curFolderDataModel = dataModel;
  315. vc.canShareType = canShareType;
  316. [self.navigationController pushViewController:vc animated:YES];
  317. }
  318. else if([dataModel.type isEqualToString:@"video"]){
  319. videoPlayByAVPlayerViewController *vc = [videoPlayByAVPlayerViewController new];
  320. vc.VideoDataMode = dataModel;
  321. [self.navigationController pushViewController:vc animated:YES];
  322. KWeakSelf
  323. vc.didNeedToRegetDataFun = ^{
  324. [weakSelf getFileListFun];
  325. };
  326. }
  327. else if([dataModel.type isEqualToString:@"audio"]){
  328. // NSMutableArray *dataArr = [NSMutableArray new];
  329. // [dataArr addObject:dataModel];
  330. audioPlayerViewController * vc = [audioPlayerViewController new];
  331. vc.isfirstEnterType = YES;
  332. vc.outSideDataModel = (NASFileAudioDataModel *)dataModel;
  333. [self.navigationController pushViewController:vc animated:YES];
  334. KWeakSelf
  335. vc.didNeedToRegetDataFun = ^{
  336. [weakSelf getFileListFun];
  337. };
  338. }
  339. else if([dataModel.type containsString:@"jpg"]){
  340. NSMutableArray *jpgDataArr = [NSMutableArray new];
  341. NSInteger index = 0;
  342. [jpgDataArr addObject:dataModel];
  343. imageDetailsScrollViewController *vc = [imageDetailsScrollViewController new];
  344. vc.index = index;
  345. vc.totalDataArr = jpgDataArr;
  346. [self.navigationController pushViewController:vc animated:YES];
  347. vc.canShareType = canShareType;
  348. }
  349. }
  350. }
  351. #pragma mark 空数据
  352. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  353. NSString *imageName = @"common_no_data_pic";
  354. return [UIImage imageNamed:imageName];
  355. }
  356. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  357. NSString *text = NSLocalizedString(@"common_no_data_tip",nil);
  358. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  359. NSForegroundColorAttributeName: HW999999Color};
  360. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  361. }
  362. //调整图片位置
  363. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  364. return -150;
  365. }
  366. //ios端:
  367. //1、需求说明:解决除MP4 MOV 3GP M4V 总计4种格式外,其他格式下载失败的问题;
  368. //2、交互说明:下载列表勾选文件中含有其他格式,toast提示“IOS系统仅支持MP4、MOV、3GP、M4V 的视频格式,其他格式无法下载”。点击下载按钮,过滤其他格式文件,仅下载MP4、MOV、3GP、M4V 的视频格式文件;
  369. //ios支持图片格式: (SVG 不支持)
  370. //需求说明:解决除JPG PNG GIF TIFF BMP总计5种格式外,其他格式下载失败的问题
  371. //视觉交互:选择文件中含有其他格式,toast提示“IOS系统仅支持JPG 、PNG、GIF、TIFF、BMP的图片格式,其他格式无法下载”。点击下载按钮,过滤其他格式文件,仅下载JPG 、PNG、GIF、TIFF、BMP的图片格式文件;
  372. - (BOOL)userCheckFileModel:(couldPhoneFileModel*)fileModel withShowTip:(BOOL)canShow{
  373. // NSString*name = [fileModel.name lowercaseString];
  374. // NSArray *nameArr = [name componentsSeparatedByString:@"."];
  375. // if(nameArr.count >0 && !_isAudioType){
  376. // BOOL canDownLoadType = NO;
  377. //
  378. // NSString *lastName = nameArr.lastObject;
  379. // if([lastName isEqualToString:@"mp4"]
  380. // ||[lastName isEqualToString:@"mov"]
  381. // ||[lastName isEqualToString:@"3gp"]
  382. // ||[lastName isEqualToString:@"m4v"]){
  383. // canDownLoadType = YES;
  384. // }
  385. //
  386. // if(!canDownLoadType){
  387. // if(canShow){
  388. // [[iToast makeText:NSLocalizedString(@"download_video_disable_state",nil)] show];
  389. // }
  390. //
  391. // return NO;
  392. // }
  393. // }
  394. //
  395. // if(nameArr.count >0 && _isAudioType){
  396. // BOOL canDownLoadType = NO;
  397. // //JPG 、PNG、GIF、TIFF、BMP
  398. // NSString *lastName = nameArr.lastObject;
  399. // if([lastName isEqualToString:@"jpg"]
  400. // ||[lastName isEqualToString:@"png"]
  401. // ||[lastName isEqualToString:@"gif"]
  402. // ||[lastName isEqualToString:@"tiff"]
  403. // ||[lastName isEqualToString:@"bmp"]
  404. // ||[lastName isEqualToString:@"heic"]
  405. // ||[lastName isEqualToString:@"jpeg"]
  406. // ||[lastName isEqualToString:@"heif"]){
  407. // canDownLoadType = YES;
  408. // }
  409. //
  410. // if(!canDownLoadType){
  411. // if(canShow){
  412. // [[iToast makeText:NSLocalizedString(@"download_image_disable_state",nil)] show];
  413. // }
  414. // return NO;
  415. // }
  416. // }
  417. return YES;
  418. }
  419. #pragma mark 用户长按图片进入编辑
  420. - (void)setViewEditTypeFun
  421. {
  422. _isEditType = YES;
  423. //[self.tableView reloadData];
  424. _curEditTypeHeadView.hidden = NO;
  425. _curEditTypeBottomView.hidden = NO;
  426. _uploadFileButton.hidden = YES;
  427. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  428. make.left.mas_equalTo(0);
  429. make.right.mas_equalTo(0);
  430. make.bottom.mas_equalTo(_curEditTypeBottomView.mas_top);
  431. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  432. }];
  433. }
  434. #pragma mark 用户取消编辑编辑
  435. - (void)userCancelEditTypeFun
  436. {
  437. //数据还原
  438. for (NASFileAndFolderDataModel*model in _didSelectListArr) {
  439. model.isSelectType = NO;
  440. }
  441. [_didSelectListArr removeAllObjects];
  442. _isEditType = NO;
  443. [self.tableView reloadData];
  444. _curEditTypeHeadView.hidden = YES;
  445. _curEditTypeBottomView.hidden = YES;
  446. _uploadFileButton.hidden = NO;
  447. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  448. make.left.mas_equalTo(0);
  449. make.right.mas_equalTo(0);
  450. make.bottom.mas_equalTo(0);
  451. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  452. }];
  453. }
  454. - (void)userCheckFilePreviewByRow:(NSInteger)row
  455. {
  456. if(row < _curNASFileAudioMod.data.list.count){
  457. NASFileAudioDataModel* dataModel = _curNASFileAudioMod.data.list[row];
  458. if(dataModel.isSelectType){
  459. [_didSelectListArr removeObject:dataModel];
  460. }
  461. else{
  462. [_didSelectListArr addObject:dataModel];
  463. }
  464. dataModel.isSelectType = !dataModel.isSelectType;
  465. [self setEditTypeTitleFun];
  466. }
  467. }
  468. - (void)didClickSelectAllButton:(UIButton*)button
  469. {
  470. //button.selected = !button.selected;
  471. [_didSelectListArr removeAllObjects];
  472. for (NASFileAudioDataModel* dataModel in _curNASFileAudioMod.data.list) {
  473. if(!button.selected){
  474. dataModel.isSelectType = button.selected;
  475. }
  476. else{
  477. if(![dataModel.type isEqualToString:@"dir"]){
  478. [_didSelectListArr addObject:dataModel];
  479. dataModel.isSelectType = button.selected;
  480. }
  481. }
  482. }
  483. [self.tableView reloadData];
  484. //[self.dataCollectionView reloadData];
  485. [self setEditTypeTitleFun];
  486. }
  487. #pragma mark 设置选中标题
  488. - (void)setEditTypeTitleFun
  489. {
  490. [_curEditTypeHeadView setTitleLabetextByNumbers:_didSelectListArr.count];
  491. if(_didSelectListArr.count > 0){
  492. [self setViewEditTypeFun];
  493. }
  494. else{
  495. [self userCancelEditTypeFun];
  496. }
  497. }
  498. #pragma mark 用户点击分享
  499. - (void)gotoShareViewFun
  500. {
  501. if (_didSelectListArr.count > 5) {
  502. [[iToast makeText:NSLocalizedString(@"share_max_count_tip2",nil)] show];
  503. return;
  504. }
  505. editShareView *editShareV = [[editShareView alloc] init];
  506. editShareV.didSelectListArr = _didSelectListArr;
  507. editShareV.shareFileType = @"6";
  508. [self.view addSubview:editShareV];
  509. [editShareV mas_makeConstraints:^(MASConstraintMaker *make) {
  510. make.left.mas_equalTo(0);
  511. make.right.mas_equalTo(0);
  512. make.bottom.mas_equalTo(0);
  513. make.top.mas_equalTo(0);
  514. }];
  515. }
  516. #pragma mark 用户点击上传文件
  517. - (void)userDidClickUploadViewFun
  518. {
  519. previewToUploadFileView *previewToUploadFileV = [[previewToUploadFileView alloc] init];
  520. [self.view addSubview:previewToUploadFileV];
  521. [previewToUploadFileV mas_makeConstraints:^(MASConstraintMaker *make) {
  522. make.left.mas_equalTo(0);
  523. make.right.mas_equalTo(0);
  524. make.bottom.mas_equalTo(0);
  525. make.top.mas_equalTo(0);
  526. }];
  527. KWeakSelf
  528. previewToUploadFileV.didClickButtonFun = ^(NSInteger tag) {
  529. [weakSelf gotoUploadFileFunWith:tag];
  530. };
  531. }
  532. #pragma mark 设置标题
  533. - (void)setTitleLabelText:(NSString*)title
  534. {
  535. NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  536. if(diskNameArr && diskNameArr.count >= 2){
  537. NSString *name = diskNameArr.lastObject;
  538. if(name.length == 0)
  539. {
  540. name = diskNameArr[diskNameArr.count -2];
  541. }
  542. //name = [name stringByReplacingOccurrencesOfString:@"sdcard" withString:NSLocalizedString(@"disk_phone_default_tip",nil)];
  543. name = [iTools changePathToShowPathBy:name];
  544. title = [[NSString alloc] initWithFormat:@"[%@]%@",name,title];
  545. }
  546. self.MytitleLabel.text = title;
  547. CGFloat curWidth = [title boundingRectWithSize:CGSizeMake(SCREEN_W, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.f]} context:nil].size.width;
  548. curWidth += 20;
  549. //HLog(@"title w:%f",curWidth);
  550. [self.MytitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  551. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX).offset(-10);
  552. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  553. make.width.mas_equalTo(curWidth);
  554. make.height.mas_equalTo(30);
  555. }];
  556. //self.MytitleLabel.backgroundColor = [UIColor greenColor];
  557. [self.selectTip mas_makeConstraints:^(MASConstraintMaker *make) {
  558. make.left.mas_equalTo(self.MytitleLabel.mas_right).offset(0);
  559. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  560. make.width.mas_equalTo(15);
  561. make.height.mas_equalTo(15);
  562. }];
  563. [tapBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  564. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  565. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  566. make.width.mas_equalTo(curWidth+15);
  567. make.height.mas_equalTo(30);
  568. }];
  569. }
  570. #pragma mark 选择硬盘
  571. - (void)selectDiskAction:(UIButton*)but
  572. {
  573. if(self.diskListBgV.hidden){
  574. [self showDiskListVieFun];
  575. }
  576. else{
  577. [self hideDiskListVieFun];
  578. }
  579. }
  580. - (void)showDiskListVieFun
  581. {
  582. self.diskListBgV.hidden = NO;
  583. self.diskListTableV.hidden = NO;
  584. [UIView animateWithDuration:0.3 animations:^{
  585. CGRect rect = self.diskListTableV.frame;
  586. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  587. self.diskListTableV.frame = rect;
  588. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  589. }];
  590. }
  591. - (void)hideDiskListVieFun
  592. {
  593. self.diskListBgV.hidden = YES;
  594. [UIView animateWithDuration:0.3 animations:^{
  595. self.diskListTableV.hidden = YES;
  596. self.selectTip.transform = CGAffineTransformIdentity;
  597. }completion:^(BOOL finished) {
  598. CGRect rect = self.diskListTableV.frame;
  599. rect.origin.y = 0;
  600. self.diskListTableV.frame = rect;
  601. }];
  602. }
  603. #pragma mark 设置标题
  604. - (void)setTitleAfterGetdiskFun
  605. {
  606. [self setTitleLabelText:NSLocalizedString(@"my_set_no_file",nil)];
  607. }
  608. - (void)viewWillAppear:(BOOL)animated
  609. {
  610. [super viewWillAppear:animated];
  611. }
  612. - (void)viewDidAppear:(BOOL)animated{
  613. [super viewDidAppear:animated];
  614. [self showDownloadTipFun];
  615. [self checkFileTransferTask];
  616. if(!_curNASFileAudioMod){
  617. [self getFileListFun];
  618. [self queryShareSwitchFunFun];
  619. }
  620. }
  621. - (void)viewWillDisappear:(BOOL)animated{
  622. [super viewWillDisappear:animated];
  623. //[self removeNewIndicator];
  624. [self removeNewIndicatorHaveStr];
  625. }
  626. - (void)gotoDownloadloadFileRecordFun
  627. {
  628. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  629. [self.navigationController pushViewController:vc animated:YES];
  630. vc.isDownloadingType = YES;
  631. //[vc gotoDownloadFile:_downloadFileBottomV.indexPathsForSelectedItems];
  632. }
  633. - (void)showDownloadTipFun
  634. {
  635. BOOL didReadUploadTipType = [HWDataManager getBoolWithKey:Const_file_downLoad_need_read];
  636. if(didReadUploadTipType){
  637. return;
  638. }
  639. //KWeakSelf
  640. /*弹窗提示恢复出厂*/
  641. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:nil
  642. msg:NSLocalizedString(@"upload_download_need_read_msg",nil)
  643. imageStr:nil
  644. cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
  645. okTitle:nil
  646. isOkBtnHighlight:NO
  647. didClickOk:^{
  648. } didClickCancel:^{
  649. [HWDataManager setBoolWithKey:Const_file_downLoad_need_read value:YES];
  650. }];
  651. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  652. [self presentViewController:nextVC animated:YES completion:^{
  653. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  654. }];
  655. }
  656. - (void)checkFileTransferTask
  657. {//有个偶现的闪退在BGFMDB
  658. [[uploadFileManager shareInstance] checkHadUploadTaskWithComplete:^(BOOL isSuccess) {
  659. self->hadUploadTaskType = isSuccess;
  660. [self setRightButtonRedTypeFun];
  661. }];
  662. KWeakSelf
  663. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  664. [[downloadManager shareInstance] checkHadDownloadTaskWithComplete:^(BOOL isSuccess) {
  665. self->hadDownloadTaskType = isSuccess;
  666. [weakSelf setRightButtonRedTypeFun];
  667. }];
  668. });
  669. }
  670. - (void)setRightButtonRedTypeFun
  671. {
  672. mainBlock(^{
  673. if(self->hadUploadTaskType || self->hadDownloadTaskType){
  674. self->rightRedView.hidden = NO;
  675. }
  676. else{
  677. self->rightRedView.hidden = YES;
  678. }
  679. });
  680. }
  681. - (void)didiClikRightButGotoTransferListFun:(UIButton*)but
  682. {
  683. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  684. [self.navigationController pushViewController:vc animated:YES];
  685. }
  686. #pragma mark 获取文件数据
  687. - (void)getFileListFun
  688. {
  689. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  690. // NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  691. // if(diskNameArr && diskNameArr.count >= 2){
  692. //
  693. // NSString *name = diskNameArr.lastObject;
  694. // if(name.length == 0)
  695. // {
  696. // name = diskNameArr[diskNameArr.count -2];
  697. // }
  698. //
  699. // [paraDict setValue:name forKey:@"path"];
  700. // }
  701. if(_defaultDiskPath){
  702. [paraDict setValue:_defaultDiskPath forKey:@"path"];
  703. }
  704. [self showNewIndicatorHaveStrWithCanBack:YES canTouch:NO showText:NSLocalizedString(@"common_loading_tip",nil)];
  705. KWeakSelf
  706. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"getFileListByFolder" Parameters:paraDict success:^(id _Nonnull responseObject) {
  707. [weakSelf removeNewIndicatorHaveStr];
  708. weakSelf.curNASFileAudioMod = [[NASFileAndFolderModel alloc] initWithDictionary:responseObject error:nil];
  709. if(weakSelf.curNASFileAudioMod && weakSelf.curNASFileAudioMod.status == 0){
  710. [weakSelf.tableView reloadData];
  711. }
  712. } failure:^(NSError * _Nonnull error) {
  713. [weakSelf removeNewIndicatorHaveStr];
  714. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  715. {
  716. [[iToast makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)] show];
  717. }
  718. else{
  719. [[iToast makeText:NSLocalizedString(@"netWork_error_show_tip",nil)] show];
  720. }
  721. }];
  722. }
  723. #pragma mark 调整文件上传
  724. - (void)gotoUploadFileFunWith:(NSInteger)tag
  725. {
  726. uploadImageOrVideoViewController *vc = [uploadImageOrVideoViewController new];
  727. if(tag ==10){
  728. vc.isPhotoType = YES;
  729. }
  730. else{
  731. vc.isPhotoType = NO;
  732. }
  733. [self.navigationController pushViewController:vc animated:YES];
  734. }
  735. #pragma mark 文件下载
  736. - (void)gotoDownLoadFileFun
  737. {
  738. if(_didSelectListArr.count == 0){
  739. [[iToast makeText:@""] show];
  740. return;
  741. }
  742. NSMutableArray *arr = [NSMutableArray new];
  743. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  744. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  745. fileModel.fileType = dataModel.type;
  746. fileModel.path = dataModel.path;
  747. fileModel.name = dataModel.name;
  748. fileModel.length = dataModel.size;
  749. fileModel.time = dataModel.duration;
  750. [arr addObject:fileModel];
  751. }
  752. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  753. [self.navigationController pushViewController:vc animated:YES];
  754. vc.isDownloadingType = YES;
  755. [vc gotoDownloadFile:arr];
  756. }
  757. #pragma mark 删除图片
  758. - (void)showDeleteAlearViewFun
  759. {
  760. NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
  761. NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
  762. KWeakSelf
  763. ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
  764. msg:tipStr
  765. imageStr:nil
  766. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  767. okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
  768. didClickOk:^{
  769. [weakSelf delFileListFun];
  770. } didClickCancel:^{
  771. }];
  772. curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  773. [self presentViewController:curAlretVC animated:YES completion:^{
  774. curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  775. }];
  776. }
  777. #pragma mark 删除文件数据
  778. - (void)delFileListFun
  779. {
  780. //处理数据埋点
  781. NSString * firstFileType = nil;
  782. BOOL isSameFileType = YES;
  783. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  784. if(!firstFileType){
  785. firstFileType = dataModel.type;
  786. }
  787. else if(![firstFileType isEqualToString:dataModel.type]){
  788. isSameFileType = NO;
  789. break;
  790. }
  791. }
  792. if(!isSameFileType){
  793. //数据埋点
  794. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"File_delete"];
  795. }
  796. else if([firstFileType containsString:@"jpg"]){
  797. //数据埋点
  798. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Image_delete"];
  799. }
  800. else if([firstFileType isEqualToString:@"video"]){
  801. //数据埋点
  802. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Video_delete"];
  803. }
  804. else if([firstFileType isEqualToString:@"audio"]){
  805. //数据埋点
  806. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Music_delete"];
  807. }
  808. else{
  809. //数据埋点
  810. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"File_delete"];
  811. }
  812. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  813. NSMutableArray *pathArr = [NSMutableArray new];
  814. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  815. [pathArr addObject:dataModel.path];
  816. }
  817. [paraDict setValue:pathArr forKey:@"path"];
  818. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  819. //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
  820. KWeakSelf //@"delFile"
  821. [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) {
  822. [weakSelf removeNewIndicator];
  823. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  824. if(model && model.status == 0){
  825. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  826. [weakSelf didDeleteSucFun];
  827. }
  828. else{
  829. }
  830. } failure:^(NSError * _Nonnull error) {
  831. [weakSelf removeNewIndicator];
  832. }];
  833. }
  834. #pragma mark 删除成功
  835. - (void)didDeleteSucFun
  836. {
  837. //删除最近文件
  838. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  839. [[lastFileManager shareManager] deleteFileInfoWithUrl:dataModel.path];
  840. }
  841. [_didSelectListArr removeAllObjects];
  842. [self setEditTypeTitleFun];
  843. [self getFileListFun];
  844. }
  845. #pragma mark 获取分享开关
  846. -(void)queryShareSwitchFunFun
  847. {
  848. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  849. [paraDict setValue:@6 forKey:@"type"];
  850. KWeakSelf
  851. [[netWorkManager shareInstance] CommonGetWithCallBackCode:queryShareSwitchFun Parameters:paraDict success:^(id _Nonnull responseObject){
  852. queryShareModel *queryShareMod = [[queryShareModel alloc] initWithDictionary:responseObject error:nil];
  853. if(queryShareMod){
  854. self->canShareType = queryShareMod.data.configValue;
  855. [weakSelf.curEditTypeBottomView setCanShaewFunBy:queryShareMod.data.configValue];
  856. }
  857. } failure:^(NSError * _Nonnull error) {
  858. }];
  859. }
  860. @end