previewFileAndFolderViewController.m 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  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 isEqualToString:@"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. title = [[NSString alloc] initWithFormat:@"[%@]%@",name,title];
  544. }
  545. self.MytitleLabel.text = title;
  546. CGFloat curWidth = [title boundingRectWithSize:CGSizeMake(SCREEN_W, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.f]} context:nil].size.width;
  547. curWidth += 20;
  548. //HLog(@"title w:%f",curWidth);
  549. [self.MytitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  550. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX).offset(-10);
  551. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  552. make.width.mas_equalTo(curWidth);
  553. make.height.mas_equalTo(30);
  554. }];
  555. //self.MytitleLabel.backgroundColor = [UIColor greenColor];
  556. [self.selectTip mas_makeConstraints:^(MASConstraintMaker *make) {
  557. make.left.mas_equalTo(self.MytitleLabel.mas_right).offset(0);
  558. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  559. make.width.mas_equalTo(15);
  560. make.height.mas_equalTo(15);
  561. }];
  562. [tapBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  563. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  564. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  565. make.width.mas_equalTo(curWidth+15);
  566. make.height.mas_equalTo(30);
  567. }];
  568. }
  569. #pragma mark 选择硬盘
  570. - (void)selectDiskAction:(UIButton*)but
  571. {
  572. if(self.diskListBgV.hidden){
  573. [self showDiskListVieFun];
  574. }
  575. else{
  576. [self hideDiskListVieFun];
  577. }
  578. }
  579. - (void)showDiskListVieFun
  580. {
  581. self.diskListBgV.hidden = NO;
  582. self.diskListTableV.hidden = NO;
  583. [UIView animateWithDuration:0.3 animations:^{
  584. CGRect rect = self.diskListTableV.frame;
  585. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  586. self.diskListTableV.frame = rect;
  587. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  588. }];
  589. }
  590. - (void)hideDiskListVieFun
  591. {
  592. self.diskListBgV.hidden = YES;
  593. [UIView animateWithDuration:0.3 animations:^{
  594. self.diskListTableV.hidden = YES;
  595. self.selectTip.transform = CGAffineTransformIdentity;
  596. }completion:^(BOOL finished) {
  597. CGRect rect = self.diskListTableV.frame;
  598. rect.origin.y = 0;
  599. self.diskListTableV.frame = rect;
  600. }];
  601. }
  602. #pragma mark 设置标题
  603. - (void)setTitleAfterGetdiskFun
  604. {
  605. [self setTitleLabelText:NSLocalizedString(@"my_set_no_file",nil)];
  606. }
  607. - (void)viewWillAppear:(BOOL)animated
  608. {
  609. [super viewWillAppear:animated];
  610. }
  611. - (void)viewDidAppear:(BOOL)animated{
  612. [super viewDidAppear:animated];
  613. [self showDownloadTipFun];
  614. [self checkFileTransferTask];
  615. if(!_curNASFileAudioMod){
  616. [self getFileListFun];
  617. [self queryShareSwitchFunFun];
  618. }
  619. }
  620. - (void)viewWillDisappear:(BOOL)animated{
  621. [super viewWillDisappear:animated];
  622. //[self removeNewIndicator];
  623. [self removeNewIndicatorHaveStr];
  624. }
  625. - (void)gotoDownloadloadFileRecordFun
  626. {
  627. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  628. [self.navigationController pushViewController:vc animated:YES];
  629. vc.isDownloadingType = YES;
  630. //[vc gotoDownloadFile:_downloadFileBottomV.indexPathsForSelectedItems];
  631. }
  632. - (void)showDownloadTipFun
  633. {
  634. BOOL didReadUploadTipType = [HWDataManager getBoolWithKey:Const_file_downLoad_need_read];
  635. if(didReadUploadTipType){
  636. return;
  637. }
  638. //KWeakSelf
  639. /*弹窗提示恢复出厂*/
  640. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:nil
  641. msg:NSLocalizedString(@"upload_download_need_read_msg",nil)
  642. imageStr:nil
  643. cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
  644. okTitle:nil
  645. isOkBtnHighlight:NO
  646. didClickOk:^{
  647. } didClickCancel:^{
  648. [HWDataManager setBoolWithKey:Const_file_downLoad_need_read value:YES];
  649. }];
  650. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  651. [self presentViewController:nextVC animated:YES completion:^{
  652. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  653. }];
  654. }
  655. - (void)checkFileTransferTask
  656. {//有个偶现的闪退在BGFMDB
  657. [[uploadFileManager shareInstance] checkHadUploadTaskWithComplete:^(BOOL isSuccess) {
  658. self->hadUploadTaskType = isSuccess;
  659. [self setRightButtonRedTypeFun];
  660. }];
  661. KWeakSelf
  662. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  663. [[downloadManager shareInstance] checkHadDownloadTaskWithComplete:^(BOOL isSuccess) {
  664. self->hadDownloadTaskType = isSuccess;
  665. [weakSelf setRightButtonRedTypeFun];
  666. }];
  667. });
  668. }
  669. - (void)setRightButtonRedTypeFun
  670. {
  671. mainBlock(^{
  672. if(self->hadUploadTaskType || self->hadDownloadTaskType){
  673. self->rightRedView.hidden = NO;
  674. }
  675. else{
  676. self->rightRedView.hidden = YES;
  677. }
  678. });
  679. }
  680. - (void)didiClikRightButGotoTransferListFun:(UIButton*)but
  681. {
  682. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  683. [self.navigationController pushViewController:vc animated:YES];
  684. }
  685. #pragma mark 获取文件数据
  686. - (void)getFileListFun
  687. {
  688. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  689. // NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  690. // if(diskNameArr && diskNameArr.count >= 2){
  691. //
  692. // NSString *name = diskNameArr.lastObject;
  693. // if(name.length == 0)
  694. // {
  695. // name = diskNameArr[diskNameArr.count -2];
  696. // }
  697. //
  698. // [paraDict setValue:name forKey:@"path"];
  699. // }
  700. if(_defaultDiskPath){
  701. [paraDict setValue:_defaultDiskPath forKey:@"path"];
  702. }
  703. [self showNewIndicatorHaveStrWithCanBack:YES canTouch:NO showText:NSLocalizedString(@"common_loading_tip",nil)];
  704. KWeakSelf
  705. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"getFileListByFolder" Parameters:paraDict success:^(id _Nonnull responseObject) {
  706. [weakSelf removeNewIndicatorHaveStr];
  707. weakSelf.curNASFileAudioMod = [[NASFileAndFolderModel alloc] initWithDictionary:responseObject error:nil];
  708. if(weakSelf.curNASFileAudioMod && weakSelf.curNASFileAudioMod.status == 0){
  709. [weakSelf.tableView reloadData];
  710. }
  711. } failure:^(NSError * _Nonnull error) {
  712. [weakSelf removeNewIndicatorHaveStr];
  713. }];
  714. }
  715. #pragma mark 调整文件上传
  716. - (void)gotoUploadFileFunWith:(NSInteger)tag
  717. {
  718. uploadImageOrVideoViewController *vc = [uploadImageOrVideoViewController new];
  719. if(tag ==10){
  720. vc.isPhotoType = YES;
  721. }
  722. else{
  723. vc.isPhotoType = NO;
  724. }
  725. [self.navigationController pushViewController:vc animated:YES];
  726. }
  727. #pragma mark 文件下载
  728. - (void)gotoDownLoadFileFun
  729. {
  730. if(_didSelectListArr.count == 0){
  731. [[iToast makeText:@""] show];
  732. return;
  733. }
  734. NSMutableArray *arr = [NSMutableArray new];
  735. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  736. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  737. fileModel.fileType = @"audio";
  738. fileModel.path = dataModel.path;
  739. fileModel.name = dataModel.name;
  740. fileModel.length = dataModel.size;
  741. fileModel.time = dataModel.duration;
  742. [arr addObject:fileModel];
  743. }
  744. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  745. [self.navigationController pushViewController:vc animated:YES];
  746. vc.isDownloadingType = YES;
  747. [vc gotoDownloadFile:arr];
  748. }
  749. #pragma mark 删除图片
  750. - (void)showDeleteAlearViewFun
  751. {
  752. NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
  753. NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
  754. KWeakSelf
  755. ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
  756. msg:tipStr
  757. imageStr:nil
  758. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  759. okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
  760. didClickOk:^{
  761. [weakSelf delFileListFun];
  762. } didClickCancel:^{
  763. }];
  764. curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  765. [self presentViewController:curAlretVC animated:YES completion:^{
  766. curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  767. }];
  768. }
  769. #pragma mark 删除文件数据
  770. - (void)delFileListFun
  771. {
  772. //处理数据埋点
  773. NSString * firstFileType = nil;
  774. BOOL isSameFileType = YES;
  775. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  776. if(!firstFileType){
  777. firstFileType = dataModel.type;
  778. }
  779. else if(![firstFileType isEqualToString:dataModel.type]){
  780. isSameFileType = NO;
  781. break;
  782. }
  783. }
  784. if(!isSameFileType){
  785. //数据埋点
  786. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"File_delete"];
  787. }
  788. else if([firstFileType isEqualToString:@"jpg"]){
  789. //数据埋点
  790. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Image_delete"];
  791. }
  792. else if([firstFileType isEqualToString:@"video"]){
  793. //数据埋点
  794. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Video_delete"];
  795. }
  796. else if([firstFileType isEqualToString:@"audio"]){
  797. //数据埋点
  798. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Music_delete"];
  799. }
  800. else{
  801. //数据埋点
  802. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"File_delete"];
  803. }
  804. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  805. NSMutableArray *pathArr = [NSMutableArray new];
  806. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  807. [pathArr addObject:dataModel.path];
  808. }
  809. [paraDict setValue:pathArr forKey:@"path"];
  810. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  811. //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
  812. KWeakSelf //@"delFile"
  813. [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) {
  814. [weakSelf removeNewIndicator];
  815. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  816. if(model && model.status == 0){
  817. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  818. [weakSelf didDeleteSucFun];
  819. }
  820. else{
  821. }
  822. } failure:^(NSError * _Nonnull error) {
  823. [weakSelf removeNewIndicator];
  824. }];
  825. }
  826. #pragma mark 删除成功
  827. - (void)didDeleteSucFun
  828. {
  829. [_didSelectListArr removeAllObjects];
  830. [self setEditTypeTitleFun];
  831. [self getFileListFun];
  832. }
  833. #pragma mark 获取分享开关
  834. -(void)queryShareSwitchFunFun
  835. {
  836. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  837. [paraDict setValue:@6 forKey:@"type"];
  838. KWeakSelf
  839. [[netWorkManager shareInstance] CommonGetWithCallBackCode:queryShareSwitchFun Parameters:paraDict success:^(id _Nonnull responseObject){
  840. queryShareModel *queryShareMod = [[queryShareModel alloc] initWithDictionary:responseObject error:nil];
  841. if(queryShareMod){
  842. self->canShareType = queryShareMod.data.configValue;
  843. [weakSelf.curEditTypeBottomView setCanShaewFunBy:queryShareMod.data.configValue];
  844. }
  845. } failure:^(NSError * _Nonnull error) {
  846. }];
  847. }
  848. @end