NasPreviewVideoViewController.m 37 KB

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