NasPreviewVideoViewController.m 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  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. [self.navigationController pushViewController:vc animated:YES];
  915. }
  916. @end