previewAudioOrDocumentViewController.m 38 KB

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