previewFileAndFolderViewController.m 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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.index = 0;
  332. vc.audioOutSidedataArray = dataArr;
  333. [self.navigationController pushViewController:vc animated:YES];
  334. }
  335. else if([dataModel.type isEqualToString:@"jpg"]){
  336. NSMutableArray *jpgDataArr = [NSMutableArray new];
  337. NSInteger index = 0;
  338. [jpgDataArr addObject:dataModel];
  339. imageDetailsScrollViewController *vc = [imageDetailsScrollViewController new];
  340. vc.index = index;
  341. vc.totalDataArr = jpgDataArr;
  342. [self.navigationController pushViewController:vc animated:YES];
  343. vc.canShareType = canShareType;
  344. }
  345. }
  346. }
  347. #pragma mark 空数据
  348. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  349. NSString *imageName = @"common_no_data_pic";
  350. return [UIImage imageNamed:imageName];
  351. }
  352. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  353. NSString *text = NSLocalizedString(@"common_no_data_tip",nil);
  354. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  355. NSForegroundColorAttributeName: HW999999Color};
  356. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  357. }
  358. //调整图片位置
  359. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  360. return -150;
  361. }
  362. //ios端:
  363. //1、需求说明:解决除MP4 MOV 3GP M4V 总计4种格式外,其他格式下载失败的问题;
  364. //2、交互说明:下载列表勾选文件中含有其他格式,toast提示“IOS系统仅支持MP4、MOV、3GP、M4V 的视频格式,其他格式无法下载”。点击下载按钮,过滤其他格式文件,仅下载MP4、MOV、3GP、M4V 的视频格式文件;
  365. //ios支持图片格式: (SVG 不支持)
  366. //需求说明:解决除JPG PNG GIF TIFF BMP总计5种格式外,其他格式下载失败的问题
  367. //视觉交互:选择文件中含有其他格式,toast提示“IOS系统仅支持JPG 、PNG、GIF、TIFF、BMP的图片格式,其他格式无法下载”。点击下载按钮,过滤其他格式文件,仅下载JPG 、PNG、GIF、TIFF、BMP的图片格式文件;
  368. - (BOOL)userCheckFileModel:(couldPhoneFileModel*)fileModel withShowTip:(BOOL)canShow{
  369. // NSString*name = [fileModel.name lowercaseString];
  370. // NSArray *nameArr = [name componentsSeparatedByString:@"."];
  371. // if(nameArr.count >0 && !_isAudioType){
  372. // BOOL canDownLoadType = NO;
  373. //
  374. // NSString *lastName = nameArr.lastObject;
  375. // if([lastName isEqualToString:@"mp4"]
  376. // ||[lastName isEqualToString:@"mov"]
  377. // ||[lastName isEqualToString:@"3gp"]
  378. // ||[lastName isEqualToString:@"m4v"]){
  379. // canDownLoadType = YES;
  380. // }
  381. //
  382. // if(!canDownLoadType){
  383. // if(canShow){
  384. // [[iToast makeText:NSLocalizedString(@"download_video_disable_state",nil)] show];
  385. // }
  386. //
  387. // return NO;
  388. // }
  389. // }
  390. //
  391. // if(nameArr.count >0 && _isAudioType){
  392. // BOOL canDownLoadType = NO;
  393. // //JPG 、PNG、GIF、TIFF、BMP
  394. // NSString *lastName = nameArr.lastObject;
  395. // if([lastName isEqualToString:@"jpg"]
  396. // ||[lastName isEqualToString:@"png"]
  397. // ||[lastName isEqualToString:@"gif"]
  398. // ||[lastName isEqualToString:@"tiff"]
  399. // ||[lastName isEqualToString:@"bmp"]
  400. // ||[lastName isEqualToString:@"heic"]
  401. // ||[lastName isEqualToString:@"jpeg"]
  402. // ||[lastName isEqualToString:@"heif"]){
  403. // canDownLoadType = YES;
  404. // }
  405. //
  406. // if(!canDownLoadType){
  407. // if(canShow){
  408. // [[iToast makeText:NSLocalizedString(@"download_image_disable_state",nil)] show];
  409. // }
  410. // return NO;
  411. // }
  412. // }
  413. return YES;
  414. }
  415. #pragma mark 用户长按图片进入编辑
  416. - (void)setViewEditTypeFun
  417. {
  418. _isEditType = YES;
  419. //[self.tableView reloadData];
  420. _curEditTypeHeadView.hidden = NO;
  421. _curEditTypeBottomView.hidden = NO;
  422. _uploadFileButton.hidden = YES;
  423. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  424. make.left.mas_equalTo(0);
  425. make.right.mas_equalTo(0);
  426. make.bottom.mas_equalTo(_curEditTypeBottomView.mas_top);
  427. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  428. }];
  429. }
  430. #pragma mark 用户取消编辑编辑
  431. - (void)userCancelEditTypeFun
  432. {
  433. //数据还原
  434. for (NASFileAndFolderDataModel*model in _didSelectListArr) {
  435. model.isSelectType = NO;
  436. }
  437. [_didSelectListArr removeAllObjects];
  438. _isEditType = NO;
  439. [self.tableView reloadData];
  440. _curEditTypeHeadView.hidden = YES;
  441. _curEditTypeBottomView.hidden = YES;
  442. _uploadFileButton.hidden = NO;
  443. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  444. make.left.mas_equalTo(0);
  445. make.right.mas_equalTo(0);
  446. make.bottom.mas_equalTo(0);
  447. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  448. }];
  449. }
  450. - (void)userCheckFilePreviewByRow:(NSInteger)row
  451. {
  452. if(row < _curNASFileAudioMod.data.list.count){
  453. NASFileAudioDataModel* dataModel = _curNASFileAudioMod.data.list[row];
  454. if(dataModel.isSelectType){
  455. [_didSelectListArr removeObject:dataModel];
  456. }
  457. else{
  458. [_didSelectListArr addObject:dataModel];
  459. }
  460. dataModel.isSelectType = !dataModel.isSelectType;
  461. [self setEditTypeTitleFun];
  462. }
  463. }
  464. - (void)didClickSelectAllButton:(UIButton*)button
  465. {
  466. //button.selected = !button.selected;
  467. [_didSelectListArr removeAllObjects];
  468. for (NASFileAudioDataModel* dataModel in _curNASFileAudioMod.data.list) {
  469. if(!button.selected){
  470. dataModel.isSelectType = button.selected;
  471. }
  472. else{
  473. if(![dataModel.type isEqualToString:@"dir"]){
  474. [_didSelectListArr addObject:dataModel];
  475. dataModel.isSelectType = button.selected;
  476. }
  477. }
  478. }
  479. [self.tableView reloadData];
  480. //[self.dataCollectionView reloadData];
  481. [self setEditTypeTitleFun];
  482. }
  483. #pragma mark 设置选中标题
  484. - (void)setEditTypeTitleFun
  485. {
  486. [_curEditTypeHeadView setTitleLabetextByNumbers:_didSelectListArr.count];
  487. if(_didSelectListArr.count > 0){
  488. [self setViewEditTypeFun];
  489. }
  490. else{
  491. [self userCancelEditTypeFun];
  492. }
  493. }
  494. #pragma mark 用户点击分享
  495. - (void)gotoShareViewFun
  496. {
  497. if (_didSelectListArr.count > 5) {
  498. [[iToast makeText:NSLocalizedString(@"share_max_count_tip2",nil)] show];
  499. return;
  500. }
  501. editShareView *editShareV = [[editShareView alloc] init];
  502. editShareV.didSelectListArr = _didSelectListArr;
  503. editShareV.shareFileType = @"6";
  504. [self.view addSubview:editShareV];
  505. [editShareV mas_makeConstraints:^(MASConstraintMaker *make) {
  506. make.left.mas_equalTo(0);
  507. make.right.mas_equalTo(0);
  508. make.bottom.mas_equalTo(0);
  509. make.top.mas_equalTo(0);
  510. }];
  511. }
  512. #pragma mark 用户点击上传文件
  513. - (void)userDidClickUploadViewFun
  514. {
  515. previewToUploadFileView *previewToUploadFileV = [[previewToUploadFileView alloc] init];
  516. [self.view addSubview:previewToUploadFileV];
  517. [previewToUploadFileV mas_makeConstraints:^(MASConstraintMaker *make) {
  518. make.left.mas_equalTo(0);
  519. make.right.mas_equalTo(0);
  520. make.bottom.mas_equalTo(0);
  521. make.top.mas_equalTo(0);
  522. }];
  523. KWeakSelf
  524. previewToUploadFileV.didClickButtonFun = ^(NSInteger tag) {
  525. [weakSelf gotoUploadFileFunWith:tag];
  526. };
  527. }
  528. #pragma mark 设置标题
  529. - (void)setTitleLabelText:(NSString*)title
  530. {
  531. NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  532. if(diskNameArr && diskNameArr.count >= 2){
  533. NSString *name = diskNameArr.lastObject;
  534. if(name.length == 0)
  535. {
  536. name = diskNameArr[diskNameArr.count -2];
  537. }
  538. name = [name stringByReplacingOccurrencesOfString:@"sdcard" withString:NSLocalizedString(@"disk_phone_default_tip",nil)];
  539. title = [[NSString alloc] initWithFormat:@"[%@]%@",name,title];
  540. }
  541. self.MytitleLabel.text = title;
  542. CGFloat curWidth = [title boundingRectWithSize:CGSizeMake(SCREEN_W, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.f]} context:nil].size.width;
  543. curWidth += 20;
  544. //HLog(@"title w:%f",curWidth);
  545. [self.MytitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  546. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX).offset(-10);
  547. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  548. make.width.mas_equalTo(curWidth);
  549. make.height.mas_equalTo(30);
  550. }];
  551. //self.MytitleLabel.backgroundColor = [UIColor greenColor];
  552. [self.selectTip mas_makeConstraints:^(MASConstraintMaker *make) {
  553. make.left.mas_equalTo(self.MytitleLabel.mas_right).offset(0);
  554. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  555. make.width.mas_equalTo(15);
  556. make.height.mas_equalTo(15);
  557. }];
  558. [tapBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  559. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  560. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  561. make.width.mas_equalTo(curWidth+15);
  562. make.height.mas_equalTo(30);
  563. }];
  564. }
  565. #pragma mark 选择硬盘
  566. - (void)selectDiskAction:(UIButton*)but
  567. {
  568. if(self.diskListBgV.hidden){
  569. [self showDiskListVieFun];
  570. }
  571. else{
  572. [self hideDiskListVieFun];
  573. }
  574. }
  575. - (void)showDiskListVieFun
  576. {
  577. self.diskListBgV.hidden = NO;
  578. self.diskListTableV.hidden = NO;
  579. [UIView animateWithDuration:0.3 animations:^{
  580. CGRect rect = self.diskListTableV.frame;
  581. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  582. self.diskListTableV.frame = rect;
  583. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  584. }];
  585. }
  586. - (void)hideDiskListVieFun
  587. {
  588. self.diskListBgV.hidden = YES;
  589. [UIView animateWithDuration:0.3 animations:^{
  590. self.diskListTableV.hidden = YES;
  591. self.selectTip.transform = CGAffineTransformIdentity;
  592. }completion:^(BOOL finished) {
  593. CGRect rect = self.diskListTableV.frame;
  594. rect.origin.y = 0;
  595. self.diskListTableV.frame = rect;
  596. }];
  597. }
  598. #pragma mark 设置标题
  599. - (void)setTitleAfterGetdiskFun
  600. {
  601. [self setTitleLabelText:NSLocalizedString(@"my_set_no_file",nil)];
  602. }
  603. - (void)viewWillAppear:(BOOL)animated
  604. {
  605. [super viewWillAppear:animated];
  606. }
  607. - (void)viewDidAppear:(BOOL)animated{
  608. [super viewDidAppear:animated];
  609. [self showDownloadTipFun];
  610. [self checkFileTransferTask];
  611. if(!_curNASFileAudioMod){
  612. [self getFileListFun];
  613. [self queryShareSwitchFunFun];
  614. }
  615. }
  616. - (void)viewWillDisappear:(BOOL)animated{
  617. [super viewWillDisappear:animated];
  618. //[self removeNewIndicator];
  619. [self removeNewIndicatorHaveStr];
  620. }
  621. - (void)gotoDownloadloadFileRecordFun
  622. {
  623. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  624. [self.navigationController pushViewController:vc animated:YES];
  625. vc.isDownloadingType = YES;
  626. //[vc gotoDownloadFile:_downloadFileBottomV.indexPathsForSelectedItems];
  627. }
  628. - (void)showDownloadTipFun
  629. {
  630. BOOL didReadUploadTipType = [HWDataManager getBoolWithKey:Const_file_downLoad_need_read];
  631. if(didReadUploadTipType){
  632. return;
  633. }
  634. //KWeakSelf
  635. /*弹窗提示恢复出厂*/
  636. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:nil
  637. msg:NSLocalizedString(@"upload_download_need_read_msg",nil)
  638. imageStr:nil
  639. cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
  640. okTitle:nil
  641. isOkBtnHighlight:NO
  642. didClickOk:^{
  643. } didClickCancel:^{
  644. [HWDataManager setBoolWithKey:Const_file_downLoad_need_read value:YES];
  645. }];
  646. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  647. [self presentViewController:nextVC animated:YES completion:^{
  648. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  649. }];
  650. }
  651. - (void)checkFileTransferTask
  652. {//有个偶现的闪退在BGFMDB
  653. [[uploadFileManager shareInstance] checkHadUploadTaskWithComplete:^(BOOL isSuccess) {
  654. self->hadUploadTaskType = isSuccess;
  655. [self setRightButtonRedTypeFun];
  656. }];
  657. KWeakSelf
  658. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  659. [[downloadManager shareInstance] checkHadDownloadTaskWithComplete:^(BOOL isSuccess) {
  660. self->hadDownloadTaskType = isSuccess;
  661. [weakSelf setRightButtonRedTypeFun];
  662. }];
  663. });
  664. }
  665. - (void)setRightButtonRedTypeFun
  666. {
  667. mainBlock(^{
  668. if(self->hadUploadTaskType || self->hadDownloadTaskType){
  669. self->rightRedView.hidden = NO;
  670. }
  671. else{
  672. self->rightRedView.hidden = YES;
  673. }
  674. });
  675. }
  676. - (void)didiClikRightButGotoTransferListFun:(UIButton*)but
  677. {
  678. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  679. [self.navigationController pushViewController:vc animated:YES];
  680. }
  681. #pragma mark 获取文件数据
  682. - (void)getFileListFun
  683. {
  684. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  685. // NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  686. // if(diskNameArr && diskNameArr.count >= 2){
  687. //
  688. // NSString *name = diskNameArr.lastObject;
  689. // if(name.length == 0)
  690. // {
  691. // name = diskNameArr[diskNameArr.count -2];
  692. // }
  693. //
  694. // [paraDict setValue:name forKey:@"path"];
  695. // }
  696. if(_defaultDiskPath){
  697. [paraDict setValue:_defaultDiskPath forKey:@"path"];
  698. }
  699. [self showNewIndicatorHaveStrWithCanBack:YES canTouch:NO showText:NSLocalizedString(@"common_loading_tip",nil)];
  700. KWeakSelf
  701. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"getFileListByFolder" Parameters:paraDict success:^(id _Nonnull responseObject) {
  702. [weakSelf removeNewIndicatorHaveStr];
  703. weakSelf.curNASFileAudioMod = [[NASFileAndFolderModel alloc] initWithDictionary:responseObject error:nil];
  704. if(weakSelf.curNASFileAudioMod && weakSelf.curNASFileAudioMod.status == 0){
  705. [weakSelf.tableView reloadData];
  706. }
  707. } failure:^(NSError * _Nonnull error) {
  708. [weakSelf removeNewIndicatorHaveStr];
  709. }];
  710. }
  711. #pragma mark 调整文件上传
  712. - (void)gotoUploadFileFunWith:(NSInteger)tag
  713. {
  714. uploadImageOrVideoViewController *vc = [uploadImageOrVideoViewController new];
  715. if(tag ==10){
  716. vc.isPhotoType = YES;
  717. }
  718. else{
  719. vc.isPhotoType = NO;
  720. }
  721. [self.navigationController pushViewController:vc animated:YES];
  722. }
  723. #pragma mark 文件下载
  724. - (void)gotoDownLoadFileFun
  725. {
  726. if(_didSelectListArr.count == 0){
  727. [[iToast makeText:@""] show];
  728. return;
  729. }
  730. NSMutableArray *arr = [NSMutableArray new];
  731. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  732. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  733. fileModel.fileType = @"audio";
  734. fileModel.path = dataModel.path;
  735. fileModel.name = dataModel.name;
  736. fileModel.length = dataModel.size;
  737. fileModel.time = dataModel.duration;
  738. [arr addObject:fileModel];
  739. }
  740. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  741. [self.navigationController pushViewController:vc animated:YES];
  742. vc.isDownloadingType = YES;
  743. [vc gotoDownloadFile:arr];
  744. }
  745. #pragma mark 删除图片
  746. - (void)showDeleteAlearViewFun
  747. {
  748. NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
  749. NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
  750. KWeakSelf
  751. ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
  752. msg:tipStr
  753. imageStr:nil
  754. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  755. okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
  756. didClickOk:^{
  757. [weakSelf delFileListFun];
  758. } didClickCancel:^{
  759. }];
  760. curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  761. [self presentViewController:curAlretVC animated:YES completion:^{
  762. curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  763. }];
  764. }
  765. #pragma mark 删除文件数据
  766. - (void)delFileListFun
  767. {
  768. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  769. NSMutableArray *pathArr = [NSMutableArray new];
  770. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  771. [pathArr addObject:dataModel.path];
  772. }
  773. [paraDict setValue:pathArr forKey:@"path"];
  774. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  775. //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
  776. KWeakSelf //@"delFile"
  777. [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) {
  778. [weakSelf removeNewIndicator];
  779. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  780. if(model && model.status == 0){
  781. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  782. [weakSelf didDeleteSucFun];
  783. }
  784. else{
  785. }
  786. } failure:^(NSError * _Nonnull error) {
  787. [weakSelf removeNewIndicator];
  788. }];
  789. }
  790. #pragma mark 删除成功
  791. - (void)didDeleteSucFun
  792. {
  793. [_didSelectListArr removeAllObjects];
  794. [self setEditTypeTitleFun];
  795. [self getFileListFun];
  796. }
  797. #pragma mark 获取分享开关
  798. -(void)queryShareSwitchFunFun
  799. {
  800. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  801. [paraDict setValue:@6 forKey:@"type"];
  802. KWeakSelf
  803. [[netWorkManager shareInstance] CommonGetWithCallBackCode:queryShareSwitchFun Parameters:paraDict success:^(id _Nonnull responseObject){
  804. queryShareModel *queryShareMod = [[queryShareModel alloc] initWithDictionary:responseObject error:nil];
  805. if(queryShareMod){
  806. self->canShareType = queryShareMod.data.configValue;
  807. [weakSelf.curEditTypeBottomView setCanShaewFunBy:queryShareMod.data.configValue];
  808. }
  809. } failure:^(NSError * _Nonnull error) {
  810. }];
  811. }
  812. @end