previewFileAndFolderViewController.m 30 KB

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